Skip to content

Commit d0386f6

Browse files
committed
Add support for zero dates in mysql mapping
Signed-off-by: Divyansh Bokadia <dbokadia@amazon.com>
1 parent 8f4589f commit d0386f6

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

data-prepper-plugins/rds-source/src/main/java/org/opensearch/dataprepper/plugins/source/rds/datatype/mysql/handler/TemporalTypeHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private Long handleTime(final String timeStr) {
8888
private Long handleDate(final String dateStr) {
8989
try {
9090
// Handle MySQL zero date special case
91-
if ("0000-00-00".equals(dateStr)) {
91+
if (dateStr.matches("^0000-.*|.*-00-.*|.*-00$")) {
9292
return null;
9393
}
9494

@@ -107,6 +107,9 @@ private Long handleDate(final String dateStr) {
107107

108108
private Long handleDateTime(final String dateTimeStr) {
109109
try {
110+
if (dateTimeStr.startsWith("0000-00-00")) {
111+
return null;
112+
}
110113
final Long dateTimeEpoch = parseDateTimeStrAsEpochMillis(dateTimeStr);
111114
if (dateTimeEpoch != null) return dateTimeEpoch;
112115

data-prepper-plugins/rds-source/src/test/java/org/opensearch/dataprepper/plugins/source/rds/datatype/mysql/handler/TemporalTypeHandlerTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ private static Stream<Arguments> provideDateTestCases() {
6060
Arguments.of("1970-01-01", getEpochMillisFromDate(1970, 1, 1)),
6161
Arguments.of("2024-02-29", getEpochMillisFromDate(2024, 2, 29)), // Leap year
6262
Arguments.of("0000-00-00", null),
63-
Arguments.of("1684108800000", getEpochMillisFromDate(2023, 5, 15))
63+
Arguments.of("1684108800000", getEpochMillisFromDate(2023, 5, 15),
64+
Arguments.of("1997-00-01", null),
65+
Arguments.of("0000-01-12", null),
66+
Arguments.of("1997-01-00", null))
6467
);
6568
}
6669

@@ -94,7 +97,7 @@ private static Stream<Arguments> provideTimeTestCases() {
9497

9598
@ParameterizedTest
9699
@MethodSource("provideDateTimeTestCases")
97-
void handle_withDateTimeType_returnsCorrectEpochMillis(String input, long expected) {
100+
void handle_withDateTimeType_returnsCorrectEpochMillis(String input, Long expected) {
98101
Long result = temporalTypeHandler.handle(MySQLDataType.DATETIME, "datetime_column", input, null);
99102
assertEquals(expected, result);
100103
}
@@ -104,7 +107,8 @@ private static Stream<Arguments> provideDateTimeTestCases() {
104107
Arguments.of("2023-12-25 14:30:00.123456", getEpochMillis(2023, 12, 25, 14, 30, 0, 123456000)),
105108
Arguments.of("1970-01-01 00:00:00", getEpochMillis(1970, 1, 1, 0, 0, 0, 0)),
106109
Arguments.of("1703509900000", 1703509900000L),
107-
Arguments.of("1784161123456789", 1784161123456L)
110+
Arguments.of("1784161123456789", 1784161123456L),
111+
Arguments.of("0000-00-00 14:30:00.123456", null)
108112
);
109113
}
110114

0 commit comments

Comments
 (0)