Data Types & Precision
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Most migrations do not fail because an event is lost. They fail because an event arrives with a value that is almost
right: a price of 24.990000000000002, a delivery date one hour early, a timestamp truncated to milliseconds, a book
description replaced by __debezium_unavailable_value, or a flag column that is 'Y' in Oracle and 1 in the
mirror table. None of these raises an error. They are found during reconciliation, or by a customer.
Debezium has to map every source column type to a Kafka Connect schema type, and every consumer (the JDBC sink, the anti-corruption layer in the new application) has to map it again to the target database. Each step has defaults and each default has a reason, but the defaults are not always right for a migration. This page explains how Debezium represents numbers, temporal values, binary data and large objects; which connector properties change that; what is special about Oracle, PostgreSQL and MySQL; and how the JDBC sink uses the information. It ends with the mapping of every Bookshop legacy Oracle column to the new PostgreSQL model, the Java conversions used by the anti-corruption layer, and SQL queries that check the result.
Checked on 2026-11-09 against Debezium 3.7.1.Final, Oracle AI Database 26ai Free (image gvenzl/oracle-free:23.26.3,
PDB FREEPDB1) and PostgreSQL 18. The type mappings and property values come from the "Data type mappings" and
"Connector properties" sections of the official connector pages. The event types that the Bookshop mapping table lists
for the canonical configuration (decimal.handling.mode=string) match the events captured in the
Worked Example: Oracle to PostgreSQL run on
2026-11-09. The Java conversion class on this page was compiled and run with Java 21. The other connector fragments and
the SQL queries were derived from the official documentation and were not run against Oracle or PostgreSQL.
Literal types and semantic types
For each column, a Debezium connector chooses two things:
-
a literal type, the Kafka Connect schema type that holds the value:
INT8,INT16,INT32,INT64,FLOAT32,FLOAT64,BOOLEAN,STRING,BYTES,ARRAY,MAPorSTRUCT, and -
in many cases a semantic type, the name of the field’s schema, which says how to interpret the literal value. For example, an
INT64namedio.debezium.time.Timestampis milliseconds since the epoch, while anINT64namedio.debezium.time.MicroTimestampis microseconds.
The semantic type lives in the schema, not in the payload. A consumer that reads JSON without schemas sees only the
literal value (1557792000000) and has to know from elsewhere what it means. This is why
Serialization & Schema Registries recommends
keeping schemas (JSON with schemas or Avro) for any pipeline that writes to another database.
Debezium uses three families of semantic types:
| Family | Examples |
|---|---|
Kafka Connect logical types |
|
Debezium temporal types |
|
Debezium data types |
|
Three connector properties change these mappings for whole families of types: decimal.handling.mode,
time.precision.mode and binary.handling.mode. Custom converters change them for selected columns (see
Custom Converters & Post Processors).
Numbers and decimal.handling.mode
Money is the column type that matters most in a migration and the one that is easiest to damage. Debezium has three
ways to represent exact numeric types (Oracle NUMBER, DECIMAL, NUMERIC; PostgreSQL NUMERIC, DECIMAL, MONEY;
MySQL DECIMAL, NUMERIC), selected with decimal.handling.mode:
| Value | Representation | Advantages | Risks |
|---|---|---|---|
|
|
Exact. The JDBC sink creates |
Unreadable without the schema. A consumer that hard-codes the scale breaks when the column changes. |
|
|
Easy for any consumer. |
Loses precision. |
|
|
Exact and readable without the schema. |
The numeric type information is gone, so a JDBC sink that creates its own tables creates text columns. Pre-create the
target columns as |
For the Bookshop pipeline the choice is string. The bookshop-oracle-source connector sets
decimal.handling.mode=string, so every price arrives as an exact, readable value such as "24.99" and the Spring Boot
consumers parse it with new BigDecimal(...), with no scale to look up. The JDBC sink does not create the mirror
tables: they are created beforehand with numeric(10,2) and bigint columns, and the sink’s JDBC URL ends in
?stringtype=unspecified, so PostgreSQL casts the string parameters to the column types (without it, the insert fails
with "column … is of type bigint but expression is of type character varying"). precise is the sound alternative when
the sink must create its own tables from the event schema, or when consumers are generic tools that read the
Decimal logical type.
Oracle NUMBER, with and without precision
The Oracle NUMBER type is the source of most numeric surprises, because legacy schemas use it for everything:
identifiers, counters, flags and money, often without any precision. With decimal.handling.mode=precise (the default)
the Oracle connector maps it as follows:
| Oracle declaration | Literal type | Semantic type and notes |
|---|---|---|
|
|
Chosen by |
|
|
|
|
|
|
|
|
|
|
|
Binary floating point in Oracle already, so nothing is lost. |
Reference: Debezium — Oracle connector, numeric types
With decimal.handling.mode=string, the canonical Bookshop setting, the table above does not apply to the Bookshop
columns: every Oracle NUMBER, including the integer columns and the primary keys, arrives as a STRING. The events
of the worked example show "BOOK_ID":"1" in the key, "AUTHOR_ID":"1" and "PRICE":"10.06" in the value, all with
the schema type string. Consumers therefore parse identifiers with Long.parseLong and amounts with new BigDecimal,
and a consumer written against precise events (expecting a JSON number for BOOK_ID) breaks when the mode changes.
Two consequences of the precise mapping matter for a migration:
-
A legacy column declared as plain
NUMBERbecomes aVariableScaleDecimalstructure. The Debezium JDBC sink mapsio.debezium.data.VariableScaleDecimalto aDOUBLEcolumn, so an unconstrainedNUMBERthat holds money silently becomes a floating-point column in the mirror table. Either pre-create the mirror column asnumericand let the consumer convert, or setdecimal.handling.mode=stringand cast in PostgreSQL, or ask the DBA what the real precision is and handle the column with a custom converter. -
Avro does not allow a negative scale in its
decimaltype. ANUMBER(P, S)with a negative scale and a large enough precision becomes aDecimalwith negative scale, which can fail to serialize with some registries. Debezium’sNumberToZeroScaleConverterrewrites such values to a zero-scale decimal.
{
"converters": "zero_scale",
"zero_scale.type": "io.debezium.connector.oracle.converters.NumberToZeroScaleConverter",
"zero_scale.decimal.mode": "precise"
}
PostgreSQL and MySQL decimals
The PostgreSQL connector maps NUMERIC(M,D), DECIMAL(M,D) and MONEY to Decimal in precise mode. The scale of
MONEY comes from the money.fraction.digits property. A NUMERIC or DECIMAL without a scale becomes a
VariableScaleDecimal, exactly like Oracle’s plain NUMBER, with the same JDBC sink consequence. In double and
string modes, PostgreSQL’s special value NaN is emitted as Double.NaN or the string NAN.
The MySQL connector maps DECIMAL and NUMERIC to Decimal in precise mode and has one more numeric property,
bigint.unsigned.handling.mode. Its default, long, represents BIGINT UNSIGNED as a signed 64-bit integer, so values
above 263 - 1 arrive as negative numbers. Set it to precise (a Decimal) when unsigned identifiers can be that large.
Temporal values and time.precision.mode
Temporal columns combine two problems: precision (milliseconds, microseconds, nanoseconds) and time zones. Debezium
controls the first with time.precision.mode. The values available differ per connector:
| Value | Oracle | PostgreSQL | MySQL | SQL Server |
|---|---|---|---|---|
|
Default |
Default |
Deprecated |
Default |
|
— |
Yes |
Default |
— |
|
Yes |
Yes |
Yes |
Yes |
|
Yes |
Yes |
Yes |
Yes |
|
Yes |
Yes |
— |
— |
|
Yes |
Yes |
— |
— |
|
Yes |
Yes |
Yes |
Yes |
Reference: Debezium — PostgreSQL connector properties, time.precision.mode, Debezium — MySQL connector properties, time.precision.mode, Debezium — SQL Server connector properties, time.precision.mode
For the Oracle connector, the modes are described in the "Temporal types" section of the connector page rather than in its property table.
Choose the mode by asking what the target needs:
-
adaptivekeeps every value exact, at the cost of three different semantic types for timestamps. Consumers must look at the schema name to know the unit. This is the right default for a migration. -
connecttruncates to milliseconds. It is only safe when no source column has more than millisecond precision, which rules out OracleTIMESTAMP(6 fractional digits by default). It is also unsafe for OracleDATEcolumns that hold points in time: inconnectmode the Oracle connector mapsDATEtoorg.apache.kafka.connect.data.Date, a number of days, and drops the time part (see the next section). -
isostringis easy to read and can represent values outside the range of epoch-based integers. -
structuredkeeps every component separately, and the Debezium JDBC sink understands it. It is the only mode that can represent PostgreSQL’sinfinitydates directly.
Oracle DATE and TIMESTAMP
The Oracle DATE type always has a time part (to the second) and no time zone. Legacy applications use it both for
calendar dates (PUBLISHED, where the time is midnight) and for points in time (LAST_UPD, set with SYSDATE). With
the default adaptive mode, the Oracle connector maps:
| Oracle type | Literal type | Semantic type |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reference: Debezium — Oracle connector, temporal types
Note the change in the connect mode: Oracle DATE then becomes org.apache.kafka.connect.data.Date, a number of
days, so the time part of LAST_UPD is lost.
io.debezium.time.NanoTimestamp is a signed 64-bit count of nanoseconds and can only represent dates between about
1677-09-21 and 2262-04-11. Legacy databases often use 9999-12-31 as an "end of time" value. In a TIMESTAMP(7) to
TIMESTAMP(9) column that value cannot be represented. The connector then follows
event.converting.failure.handling.mode: with warn (the default) or skip, the value is emitted as null and a
warning is logged, and with fail, the connector stops. A null where the legacy row has 9999-12-31 is a silent data
change. Use time.precision.mode=microseconds or isostring for such columns, or search for these values before the
snapshot (see Verifying the mapping).
Time zones
Oracle DATE and TIMESTAMP and PostgreSQL timestamp store wall-clock time without a time zone. Debezium converts
such values to epoch-based numbers as if they were UTC, and the time zone of the Kafka Connect JVM does not change
that. A LAST_UPD of 2026-11-09 10:42:07, written by a legacy application running in Madrid, arrives as
1794220927000, which is 10:42:07 UTC, although the real moment was 09:42:07 UTC.
The new model stores updated_at as timestamptz, an absolute point in time. So somebody has to decide in which zone
the legacy values were written, and convert. Three places can do it:
-
The anti-corruption layer (recommended): interpret the epoch value as a local date-time and attach the legacy zone,
Europe/Madridin the Bookshop example. The conversion is explicit and testable, and handles daylight saving time correctly. TheLegacyColumnRules.instantmethod in Conversions in the anti-corruption layer does this. -
PostgreSQL: write the mirror column as
timestampand convert in SQL withupdated_at AT TIME ZONE 'Europe/Madrid'when moving data fromlegacy_bookintobook. -
A single message transformation: Debezium’s
TimezoneConverterSMT converts temporal fields from UTC to a target zone.
The TimezoneConverter assumes that the field values are in UTC and converts them to the zone given in
converted.timezone, which can be a geographic zone (America/New_York) or a fixed offset (+02:00). Use a
geographic zone when daylight saving time matters. include.list or exclude.list (not both) select the fields, with
rules such as source:<tablename>:<fieldname> or topic:<topicname>:<fieldname>. It is the right tool when the event
values are UTC and a consumer wants them in local time, for example for TIMESTAMP WITH TIME ZONE values that
consumers display in a single zone. It is not a tool for reinterpreting legacy wall-clock values, because it shifts in
the opposite direction.
{
"transforms": "convertTimezone",
"transforms.convertTimezone.type": "io.debezium.transforms.TimezoneConverter",
"transforms.convertTimezone.converted.timezone": "Europe/Madrid",
"transforms.convertTimezone.include.list": "source:SUPPLIER_CATALOGUE:after.FEED_TS"
}
In this example, only FEED_TS of SUPPLIER_CATALOGUE is converted, and only in the after image. The
supplier feed writes FEED_TS in UTC, so the SMT shows it in Madrid time. The canonical bookshop-oracle-source
configuration does not include this SMT: it is shown for consumers that need local time. Keep the decision about each legacy
temporal column (calendar date, local wall-clock time or UTC) in the mapping table below, because nothing in the data
reveals it.
Binary data and binary.handling.mode
binary.handling.mode controls how binary columns (Oracle BLOB and RAW, PostgreSQL bytea, MySQL BINARY,
VARBINARY and BLOB) are represented:
| Value | Representation |
|---|---|
|
|
|
A base64-encoded |
|
A base64-url-safe-encoded |
|
A hex-encoded (base16) |
Keep bytes when the target column is binary (bytea in PostgreSQL), because the JDBC sink then writes raw bytes. Use
hex or base64 only when the target is a text column or a consumer that cannot handle bytes. For RAW columns that
hold text-like identifiers (GUIDs generated by SYS_GUID()), the Oracle connector also has a RawToStringConverter.
Large objects and unavailable values
Some values are not in the change stream even though the column exists. Debezium cannot read them later from the
database without race conditions, so it emits a placeholder. The placeholder is the value of
unavailable.value.placeholder, by default __debezium_unavailable_value. For binary columns the placeholder is
emitted as the bytes of that string.
Oracle CLOB, NCLOB and BLOB
The Oracle connector maps CLOB and NCLOB to STRING and BLOB to BYTES (or a string, depending on
binary.handling.mode). BFILE, LONG and LONG RAW are not supported. How LOB values reach the event depends on
lob.enabled:
-
With
lob.enabled=false(the default), snapshot events contain the current LOB values, but streamed events contain the placeholder for every LOB column. LogMiner does not mine the LOB-specific redo entries, which saves a lot of work. -
With
lob.enabled=true, the connector mines the extra redo operations that Oracle writes for LOB changes. Even then, Oracle writes a LOB value to the redo log only when a statement sets or changes it. An update that does not touch the LOB column produces an event with the placeholder in that column. An update that changes the LOB has the new value inafterand the placeholder inbefore.
lob.enabled=true also captures XMLTYPE, JSON (Oracle 21c and later) and extended strings (VARCHAR2,
NVARCHAR2 and RAW longer than the legacy limits when MAX_STRING_SIZE=EXTENDED).
For a migration, this has a direct consequence. A consumer or sink that copies every column from after to the target
will overwrite a real description with __debezium_unavailable_value the first time the legacy application updates
the price of a book. The fixes are:
-
Skip the placeholder in the consumer: never write a column whose value is the placeholder, and keep the target value instead. The anti-corruption layer can do this. The JDBC sink writes whatever it receives.
-
Re-select the value with the reselect columns post processor, which queries the source table for columns that carry the placeholder (or
null) and puts the current value into the event. The Oracle documentation names this as the alternative to mining LOBs. -
Enable LOB mining with
lob.enabled=trueand accept the extra redo processing, and still handle the placeholder for updates that do not touch the LOB.
{
"lob.enabled": "false",
"unavailable.value.placeholder": "__debezium_unavailable_value",
"post.processors": "reselector",
"post.processors.reselector.type": "io.debezium.processors.reselect.ReselectColumnsPostProcessor",
"post.processors.reselector.reselect.columns.include.list": "BOOKSHOP.BOOK_DESCRIPTION:DESCRIPTION",
"post.processors.reselector.reselect.unavailable.values": "true",
"post.processors.reselector.reselect.null.values": "false"
}
The canonical Bookshop schema has no LOB columns, so the example uses a hypothetical BOOKSHOP.BOOK_DESCRIPTION table
with a DESCRIPTION CLOB column. The re-selected value is the value at the time of the query, not at the time of the
change, which is acceptable for a mirror that converges to the current state but not for an audit trail. If the legacy
application uses ROLLBACK TO SAVEPOINT in transactions that change LOB columns, also set
log.mining.include.internal.events=true, whatever the lob.enabled setting. The Oracle LOB settings are discussed in
more detail on Oracle Connector, and post processors on
Custom Converters & Post Processors.
{
"lob.enabled": "true",
"unavailable.value.placeholder": "__debezium_unavailable_value"
}
PostgreSQL TOAST and REPLICA IDENTITY
PostgreSQL stores values larger than about 8 KB out of line, with its TOAST mechanism. When a row is updated and a
TOASTed column does not change, logical decoding does not include that column, unless it is part of the table’s
replica identity. The PostgreSQL connector then emits unavailable.value.placeholder in its place. The replica
identity also decides what before contains:
REPLICA IDENTITY |
before image of UPDATE and DELETE events |
|---|---|
|
Only the primary key columns. Tables without a primary key produce only create events. Unchanged TOAST columns are missing and replaced by the placeholder. |
|
No previous values. |
|
All columns, including TOAST columns. |
|
The columns of the given index. |
Reference: Debezium — PostgreSQL connector, replica identity, Debezium — PostgreSQL connector, TOASTed values
In the Bookshop migration PostgreSQL is the source during reverse replication, when the bookshop-pg-source
connector feeds changes from the new database back to Oracle (see
Cut-over & Reverse Replication). The reverse sink needs
complete rows to update Oracle, so the captured tables get REPLICA IDENTITY FULL.
ALTER TABLE public.book REPLICA IDENTITY FULL;
ALTER TABLE public.author REPLICA IDENTITY FULL;
ALTER TABLE public.book_author REPLICA IDENTITY FULL;
ALTER TABLE public.customer REPLICA IDENTITY FULL;
-- Check: 'f' means FULL, 'd' DEFAULT, 'n' NOTHING, 'i' INDEX
SELECT relname, relreplident
FROM pg_class
WHERE relname IN ('book', 'author', 'book_author', 'customer');
FULL makes PostgreSQL write the whole old row to the WAL for every update and delete, which increases WAL volume.
For tables with large TOASTed columns that change rarely, the reselect post processor is an alternative.
MySQL: TINYINT(1), ENUM and SET
MySQL is not part of the Bookshop example, but its type quirks often appear when a second legacy system is migrated.
BOOLEAN and TINYINT(1). MySQL stores BOOLEAN as TINYINT(1). During streaming, Debezium sees the original DDL
and can map BOOLEAN columns properly. During a snapshot it reads the table definition with SHOW CREATE TABLE, which
reports TINYINT(1) for both, so the same column can change its schema between the snapshot and streaming. The
TinyIntOneToBooleanConverter makes the mapping consistent.
{
"converters": "boolean",
"boolean.type": "io.debezium.connector.binlog.converters.TinyIntOneToBooleanConverter",
"boolean.selector": "shop.product.is_active,shop.customer.newsletter"
}
Reference: Debezium — MySQL connector, boolean values
Without a selector, the converter maps all TINYINT(1) columns, which is wrong if some of them hold small numbers.
If the database does not report the length of TINYINT UNSIGNED columns during the snapshot, set
boolean.length.checker=false and list the columns in the selector.
ENUM and SET. MySQL ENUM becomes a STRING with the semantic type io.debezium.data.Enum, and SET becomes
io.debezium.data.EnumSet. The schema parameter allowed lists the permitted values. A consumer can use it to validate
values, and the JDBC sink uses it when the target is MySQL. Adding a value to an ENUM in the source changes the
schema, which a schema registry sees as a new version.
Reference: Debezium — MySQL connector, basic types
Oracle flags and BOOLEAN
Oracle had no BOOLEAN column type before Oracle Database 23ai, so legacy schemas simulate it with CHAR(1) ('Y',
'N') or NUMBER(1) (1, 0). Oracle 23ai and later (including 26ai) add a native BOOLEAN type, but the
Debezium Oracle connector does not support it, so do not convert legacy flag columns to BOOLEAN in Oracle during the
migration.
For NUMBER(1) flags, Debezium provides NumberOneToBooleanConverter, which maps selected (or all) NUMBER(1) columns
to BOOLEAN.
{
"converters": "boolean",
"boolean.type": "io.debezium.connector.oracle.converters.NumberOneToBooleanConverter",
"boolean.selector": ".*\\.ORDERS\\.IS_GIFT"
}
The example column ORDERS.IS_GIFT is hypothetical. The Bookshop flags are CHAR(1) columns (BOOK.ACTIVE_FLG,
CUSTOMER.STATUS_CD), which this converter does not handle. They arrive as strings and are translated in the
anti-corruption layer, where an unexpected value ('y', ' ', 'X') can be reported instead of silently becoming
false.
Keeping the source type for the JDBC sink
The JDBC sink creates and alters target columns from the event schema. From the literal and semantic types alone it
cannot know that a STRING came from VARCHAR2(13) or that an INT64 came from NUMBER(10), so it chooses generic
types. Two source connector properties add the original type to the field schema:
-
column.propagate.source.type: a comma-separated list of regular expressions that match fully-qualified column names (<schemaName>.<tableName>.<columnName>or<tableName>.<columnName>). -
datatype.propagate.source.type: a comma-separated list of regular expressions that match data type names.
For each matching column, the field schema gets the parameters __debezium.source.column.type,
__debezium.source.column.length and __debezium.source.column.scale.
{
"column.propagate.source.type": "BOOKSHOP\\.BOOK\\..*,BOOKSHOP\\.AUTHOR\\..*,BOOKSHOP\\.SUPPLIER_CATALOGUE\\..*"
}
With propagation, the field schema of ISBN looks like this:
{
"type": "string",
"optional": true,
"field": "ISBN",
"parameters": {
"__debezium.source.column.type": "VARCHAR2",
"__debezium.source.column.length": "13"
}
}
The JDBC sink uses these parameters to refine the column type, for example to size character columns. The documentation notes that propagation has the most effect when the source and the sink are the same kind of database. Between Oracle and PostgreSQL the type names differ, so the most reliable approach is still to create the mirror tables yourself with explicit types and let the sink only write rows (see JDBC Sink Connector). The parameters also help hand-written consumers, which can read the original length and scale from the schema instead of hard-coding them.
The Bookshop mapping: Oracle to PostgreSQL
The table lists every column of the legacy BOOKSHOP schema, how the Oracle connector represents it with the
canonical configuration used on these pages (decimal.handling.mode=string, default adaptive temporal mode,
binary.handling.mode=bytes), and where it ends up in PostgreSQL: the mirror table written 1:1 by the JDBC sink (only
for BOOK, AUTHOR and SUPPLIER_CATALOGUE) and the column of the new model written by the anti-corruption layer.
| Oracle column | Debezium event type | Mirror column | New model column and conversion |
|---|---|---|---|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|||
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|||
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|||
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|||
|
|
|
— |
|
|
|
— |
|
|
|
— |
|
|
|
— (UTC, written by the supplier feed) |
Reference: Debezium — Oracle connector, data type mappings, Debezium — JDBC sink, data type mappings
With decimal.handling.mode=string every NUMBER column is a STRING, whatever its precision and scale. With
precise the integer columns would follow the rule from Oracle NUMBER, with and without precision (NUMBER(10) and
NUMBER(12) become INT64, NUMBER(5) becomes INT32, NUMBER(4) becomes INT16) and the amounts would be Decimal
values with scale 2. The temporal types do not depend on decimal.handling.mode: Oracle DATE is a
io.debezium.time.Timestamp, and Oracle TIMESTAMP without a precision has 6 fractional digits, so FEED_TS is a
MicroTimestamp.
The mirror tables are created before the JDBC sink starts, with these explicit types, and the sink only writes rows
(schema.evolution=none). The string values of the NUMBER columns reach bigint and numeric(10,2) columns because
the sink’s JDBC URL ends in ?stringtype=unspecified. With quote.identifiers=false PostgreSQL folds the names to lower
case, which matches the legacy_${source.table} collection name format once lower-cased. The DDL is the same as on
JDBC Sink Connector and in the
worked example.
CREATE ROLE bookshop_mirror LOGIN PASSWORD 'change-me';
CREATE TABLE legacy_book (
book_id bigint PRIMARY KEY, -- NUMBER(10)
isbn varchar(13), -- VARCHAR2(13)
title varchar(200),
author_id bigint, -- NUMBER(10)
price numeric(10,2), -- NUMBER(10,2)
currency char(3),
published timestamp, -- DATE -> io.debezium.time.Timestamp
active_flg char(1), -- 'Y' / 'N', kept as in the legacy table
supplier_id bigint,
last_upd timestamp
);
CREATE TABLE legacy_author (
author_id bigint PRIMARY KEY,
full_name varchar(200)
);
CREATE TABLE legacy_supplier_catalogue (
supplier_id bigint,
isbn varchar(13),
supplier_price numeric(10,2),
feed_ts timestamp, -- TIMESTAMP(6) -> io.debezium.time.MicroTimestamp
PRIMARY KEY (supplier_id, isbn)
);
GRANT SELECT, INSERT, UPDATE, DELETE ON legacy_book, legacy_author, legacy_supplier_catalogue TO bookshop_mirror;
The mirror keeps the legacy types exactly: timestamp without time zone for Oracle DATE, numeric(10,2) for
NUMBER(10,2), char(1) for the flags. All semantic conversions happen in one place, the anti-corruption layer,
where they can be tested.
Conversions in the anti-corruption layer
The translators of the Spring Boot bookshop application (LegacyBookTranslator, LegacyCustomerTranslator,
LegacyOrderProjector) share the value conversions from the mapping table. In the application they live in the
LegacyValues and LegacyCodes classes shown on
Listening to Events in Applications, which read
the values from the Jackson tree of the event. The class below states the same rules on plain values, so that each
decision of the mapping table can be read and unit tested on its own: which zone the legacy dates are in, which flag
values are valid, how the strings of decimal.handling.mode=string are parsed, and what to do with the placeholder.
package com.example.bookshop.migration;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Base64;
import java.util.Map;
/**
* Converts values of the legacy Oracle BOOKSHOP schema, as Debezium emits them with the canonical
* decimal.handling.mode=string and the default time.precision.mode=adaptive, into the types of the new
* PostgreSQL model. The translators of the anti-corruption layer apply the same rules.
*/
public final class LegacyColumnRules {
/** Time zone in which the legacy application wrote its DATE values (wall-clock time). */
public static final ZoneId LEGACY_ZONE = ZoneId.of("Europe/Madrid");
/** Placeholder that the connector emits for LOB or TOAST values it could not read. */
public static final String UNAVAILABLE = "__debezium_unavailable_value";
private static final Map<String, String> ORDER_STATUS =
Map.of("NW", "NEW", "PD", "PAID", "SH", "SHIPPED", "CN", "CANCELLED");
private LegacyColumnRules() {
}
/** Integer NUMBER(p) such as BOOK_ID: a string such as "1001" with decimal.handling.mode=string. */
public static Long identifier(String text) {
return text == null ? null : Long.valueOf(text.trim());
}
/** NUMBER(p,s) with s greater than 0: a string such as "24.99" with decimal.handling.mode=string. */
public static BigDecimal decimal(String text) {
return text == null ? null : new BigDecimal(text.trim());
}
/**
* The same column with decimal.handling.mode=precise (not the Bookshop setting): base64 of the unscaled
* two's-complement value, with the scale taken from the field schema.
*/
public static BigDecimal decimalFromPrecise(String base64, int scale) {
return base64 == null ? null
: new BigDecimal(new BigInteger(Base64.getDecoder().decode(base64)), scale);
}
/** Widens NUMBER(10,2) to numeric(12,2); fails instead of rounding if the scale would be lost. */
public static BigDecimal money(BigDecimal value) {
return value == null ? null : value.setScale(2, RoundingMode.UNNECESSARY);
}
/** Oracle DATE used as a calendar date (io.debezium.time.Timestamp, epoch milliseconds). */
public static LocalDate dateOnly(Long epochMillis) {
if (epochMillis == null) {
return null;
}
LocalDateTime wallClock = LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC);
if (!wallClock.toLocalTime().equals(LocalTime.MIDNIGHT)) {
throw new IllegalArgumentException("DATE value has a time part: " + wallClock);
}
return wallClock.toLocalDate();
}
/** Oracle DATE used as a point in time, written in LEGACY_ZONE: becomes a timestamptz value. */
public static OffsetDateTime instant(Long epochMillis) {
if (epochMillis == null) {
return null;
}
LocalDateTime wallClock = LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC);
return wallClock.atZone(LEGACY_ZONE).toOffsetDateTime();
}
/** CHAR(1) 'Y'/'N' flag: becomes boolean; any other value is a data quality error. */
public static Boolean flag(String yn) {
if (yn == null) {
return null;
}
return switch (yn.trim()) {
case "Y" -> Boolean.TRUE;
case "N" -> Boolean.FALSE;
default -> throw new IllegalArgumentException("Unexpected flag value: '" + yn + "'");
};
}
/** ORDERS.STATUS_CD: becomes the status text of purchase_order. */
public static String orderStatus(String code) {
String status = code == null ? null : ORDER_STATUS.get(code.trim());
if (status == null) {
throw new IllegalArgumentException("Unknown order status code: " + code);
}
return status;
}
/** CUSTOMER.STATUS_CD 'A'/'I': becomes ACTIVE or INACTIVE. */
public static String customerStatus(String code) {
return switch (code == null ? "" : code.trim()) {
case "A" -> "ACTIVE";
case "I" -> "INACTIVE";
default -> throw new IllegalArgumentException("Unknown customer status code: " + code);
};
}
/** True if a LOB or TOAST column was not captured and must not overwrite the target value. */
public static boolean unavailable(Object value) {
return UNAVAILABLE.equals(value);
}
}
With the values of the update event from Anatomy of a Change Event,
identifier("1001") returns 1001, decimal("24.99") returns 24.99 (and decimalFromPrecise("CcM=", 2), the same
price in precise mode, also returns 24.99), dateOnly(1557792000000L) returns 2019-05-14, and instant(1794220927000L)
returns 2026-11-09T10:42:07+01:00 (Madrid is at UTC+1 in November). dateOnly(1794220927000L) throws, because the
value has a time part. The conversions fail loudly on unexpected data on purpose: an exception sends the event to the
consumer’s error handling (a dead-letter topic in the bookshop application) where it can be inspected, while a
silent default would hide the problem. How the translators use these methods, and how failed events are handled, is on
Listening to Events in Applications.
If a pipeline uses precise mode with Avro instead, the decimal values arrive as ByteBuffer (or BigDecimal with
Avro’s decimal conversion) instead of base64 strings, and only the decimal conversion changes.
Verifying the mapping
Run type checks before the initial snapshot, and again during reconciliation. The queries below find the values that the mapping table calls errors.
-- Calendar dates that have a time part
SELECT COUNT(*) AS published_with_time
FROM BOOKSHOP.BOOK
WHERE PUBLISHED <> TRUNC(PUBLISHED);
-- Flag and status values outside the documented sets
SELECT ACTIVE_FLG, COUNT(*) FROM BOOKSHOP.BOOK GROUP BY ACTIVE_FLG;
SELECT STATUS_CD, COUNT(*) FROM BOOKSHOP.CUSTOMER GROUP BY STATUS_CD;
SELECT STATUS_CD, COUNT(*) FROM BOOKSHOP.ORDERS GROUP BY STATUS_CD;
-- "End of time" sentinels and other extreme dates
SELECT MIN(ORDER_DT), MAX(ORDER_DT) FROM BOOKSHOP.ORDERS;
SELECT MIN(FEED_TS), MAX(FEED_TS) FROM BOOKSHOP.SUPPLIER_CATALOGUE;
-- Columns declared as NUMBER without precision (they become VariableScaleDecimal)
SELECT TABLE_NAME, COLUMN_NAME
FROM ALL_TAB_COLUMNS
WHERE OWNER = 'BOOKSHOP' AND DATA_TYPE = 'NUMBER' AND DATA_PRECISION IS NULL;
-- Totals to compare with the mirror table
SELECT COUNT(*), SUM(PRICE) FROM BOOKSHOP.BOOK;
-- Same totals as in Oracle: any difference points at a numeric mapping problem
SELECT COUNT(*), SUM(price) FROM public.legacy_book;
-- Placeholders that reached a table
SELECT COUNT(*) FROM public.legacy_book WHERE title = '__debezium_unavailable_value';
-- Columns that the JDBC sink created as floating point
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name LIKE 'legacy\_%'
AND data_type IN ('double precision', 'real');
-- Time zone conversion: the new model should be one or two hours behind the mirror
SELECT l.book_id, l.last_upd, b.updated_at AT TIME ZONE 'UTC' AS updated_at_utc
FROM public.legacy_book l
JOIN public.book b ON b.id = l.book_id
LIMIT 10;
Reference: Debezium — JDBC sink, data type mappings
Row-level comparison and checksums for the whole migration are described in Verification & Reconciliation.
Summary of the properties
| Property | Default | Use in the Bookshop migration |
|---|---|---|
|
|
|
|
|
Keep the default. Use |
|
|
Keep |
|
|
|
|
|
Keep the default and filter it in every consumer. |
|
|
|
|
none |
Not set in the canonical configuration. Optional for the mirrored tables, so consumers and the sink see lengths and scales. |
|
|
|