Implementation:Risingwavelabs Risingwave DatetimeTypeConverter
| Property | Value |
|---|---|
| Component | CDC Source - Debezium Converters |
| Language | Java |
| Lines | 71 |
| License | Apache 2.0 |
| Repository | risingwavelabs/risingwave |
Overview
DatetimeTypeConverter is a custom Debezium type converter that transforms DATE column values from their internal epoch-day representation into ISO-formatted date strings (yyyy-MM-dd). RisingWave expects DATE type values in JSON CDC payloads to be human-readable strings rather than raw numeric epoch days. This converter is registered with the Debezium engine so that any DATE column encountered during CDC capture is automatically converted to the expected string format before being passed to RisingWave's Debezium JSON parser.
The class implements the Debezium CustomConverter<SchemaBuilder, RelationalColumn> interface, which provides a pluggable mechanism for overriding default type conversions in the CDC pipeline.
Code Reference
Source Location
java/connector-node/risingwave-source-cdc/src/main/java/com/risingwave/connector/cdc/debezium/converters/DatetimeTypeConverter.java
Signature
public class DatetimeTypeConverter implements CustomConverter<SchemaBuilder, RelationalColumn>
Key Methods
// Configures the date formatter to use "yyyy-MM-dd" pattern
@Override
public void configure(Properties props)
// Registers the converter for DATE columns with an optional string schema
@Override
public void converterFor(RelationalColumn column, ConverterRegistration<SchemaBuilder> registration)
// Converts an epoch-day input to a formatted date string
private String convertDate(Object input)
Imports
import io.debezium.spi.converter.CustomConverter;
import io.debezium.spi.converter.RelationalColumn;
import io.debezium.time.Date;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Properties;
import org.apache.kafka.connect.data.SchemaBuilder;
I/O Contract
Input
- Column metadata: A
RelationalColumndescribing the database column type. The converter activates only whencolumn.typeName()equals"DATE"(case-insensitive). - Raw value: An
Objectrepresenting the date value in epoch-day format (integer number of days since epoch), as provided by the DebeziumDateutility class.
Output
- Converted value: A
Stringin"yyyy-MM-dd"format (e.g.,"1988-05-04"), ornullif the input is null. - Schema: An optional string schema named
"rw.cdc.date.string", registered with the Debezium converter framework.
Side Effects
None. This converter is stateless and performs pure value transformation.
Usage Examples
Registering the Converter with Debezium
The converter is typically registered in the Debezium connector configuration properties:
// In Debezium engine configuration
props.put("converters", "datetime");
props.put("datetime.type", "com.risingwave.connector.cdc.debezium.converters.DatetimeTypeConverter");
Manual Conversion (from built-in main method)
var converter = new DatetimeTypeConverter();
// null input returns null
converter.convertDate(null); // -> null
// LocalDate input
converter.convertDate(LocalDate.of(1988, 5, 4)); // -> "1988-05-04"
// Integer epoch day
converter.convertDate(8989); // -> "1994-08-10"
Related Pages
- DbzCdcEngineRunner Start - CDC engine runner that configures the Debezium engine including custom converters
- ConfigurableOffsetBackingStore - Companion internal component for CDC offset management
- JniDbzSourceHandler RunJniDbzSourceThread - JNI bridge for running Debezium source threads