forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Source MSSQL: fix data type (smalldatetime, smallmoney) conversion …
…from mssql source (airbytehq#5609) (airbytehq#7386) * Fix data type (smalldatetime, smallmoney) conversion from mssql source (airbytehq#5609) * Fixed code format * Bumb new version * Update documentation (mssql.md) * formating * fixed converter properties * aligned converter utils with airbytehq#7339 Co-authored-by: Andrii Leonets <[email protected]>
- Loading branch information
1 parent
af1c62f
commit 56db806
Showing
6 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ses/debezium/src/main/java/io/airbyte/integrations/debezium/internals/MSSQLConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.debezium.internals; | ||
|
||
import io.debezium.spi.converter.CustomConverter; | ||
import io.debezium.spi.converter.RelationalColumn; | ||
import java.math.BigDecimal; | ||
import java.util.Objects; | ||
import java.util.Properties; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MSSQLConverter implements CustomConverter<SchemaBuilder, RelationalColumn> { | ||
|
||
private final Logger LOGGER = LoggerFactory.getLogger(MSSQLConverter.class);; | ||
|
||
private final String SMALLDATETIME_TYPE = "SMALLDATETIME"; | ||
private final String SMALLMONEY_TYPE = "SMALLMONEY"; | ||
|
||
@Override | ||
public void configure(Properties props) {} | ||
|
||
@Override | ||
public void converterFor(final RelationalColumn field, | ||
final ConverterRegistration<SchemaBuilder> registration) { | ||
if (SMALLDATETIME_TYPE.equalsIgnoreCase(field.typeName())) { | ||
registerDate(field, registration); | ||
} else if (SMALLMONEY_TYPE.equalsIgnoreCase(field.typeName())) { | ||
registerMoney(field, registration); | ||
} | ||
|
||
} | ||
|
||
private void registerDate(final RelationalColumn field, | ||
final ConverterRegistration<SchemaBuilder> registration) { | ||
registration.register(SchemaBuilder.string(), input -> { | ||
if (Objects.isNull(input)) { | ||
return DebeziumConverterUtils.convertDefaultValue(field); | ||
} | ||
|
||
return DebeziumConverterUtils.convertDate(input); | ||
}); | ||
} | ||
|
||
private void registerMoney(final RelationalColumn field, | ||
final ConverterRegistration<SchemaBuilder> registration) { | ||
registration.register(SchemaBuilder.float64(), input -> { | ||
if (Objects.isNull(input)) { | ||
return DebeziumConverterUtils.convertDefaultValue(field); | ||
} | ||
|
||
if (input instanceof BigDecimal) { | ||
return ((BigDecimal) input).doubleValue(); | ||
} | ||
|
||
LOGGER.warn("Uncovered money class type '{}'. Use default converter", | ||
input.getClass().getName()); | ||
return input.toString(); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters