Skip to content

Commit

Permalink
#3931 #3932 added zero-date converting to null param "zeroDateTimeBeh…
Browse files Browse the repository at this point in the history
…avior=convertToNull"
  • Loading branch information
alexandr-shegeda committed Oct 6, 2021
1 parent f1d3b7c commit 0f0883b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public JsonNode toJdbcConfig(JsonNode config) {
config.get("port").asText(),
config.get("database").asText()));

jdbcUrl.append("?zeroDateTimeBehavior=convertToNull");
if (!additionalParameters.isEmpty()) {
jdbcUrl.append("?");
jdbcUrl.append("&");
additionalParameters.forEach(x -> jdbcUrl.append(x).append("&"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public JsonNode toDatabaseConfig(JsonNode config) {

// see MySqlJdbcStreamingQueryConfiguration for more context on why useCursorFetch=true is needed.
jdbcUrl.append("?useCursorFetch=true");
jdbcUrl.append("&zeroDateTimeBehavior=convertToNull");
if (config.get("jdbc_url_params") != null && !config.get("jdbc_url_params").asText().isEmpty()) {
jdbcUrl.append("&").append(config.get("jdbc_url_params").asText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected Database setupDatabase() throws Exception {
config.get("port").asText(),
config.get("database").asText()),
"com.mysql.cj.jdbc.Driver",
SQLDialect.MYSQL);
SQLDialect.MYSQL,
"zeroDateTimeBehavior=convertToNull");

// It disable strict mode in the DB and allows to insert specific values.
// For example, it's possible to insert date with zero values "2021-00-00"
Expand Down Expand Up @@ -210,6 +211,14 @@ protected void initTests() {
.addExpectedValues(null, "2005-10-10T23:22:21Z")
.build());

addDataTypeTestData(
TestDataHolder.builder()
.sourceType("timestamp")
.airbyteType(JsonSchemaPrimitive.STRING)
.addInsertValues("null", "'2021-01-00'", "'2021-00-00'", "'0000-00-00'")
.addExpectedValues(null, null, null, null)
.build());

addDataTypeTestData(
TestDataHolder.builder()
.sourceType("timestamp")
Expand Down
6 changes: 3 additions & 3 deletions docs/integrations/sources/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ If you can't find the data type you are looking for or have any problems feel fr
| `bigint` | number | |
| `binary` | string | |
| `blob` | string | |
| `date` | string | MySql JDBC driver has limitation. ZERO-DATE value is forbidden. |
| `datetime` | string | MySql JDBC driver has limitation. ZERO-DATE value is forbidden. |
| `date` | string | MySql JDBC driver has limitation. ZERO-DATE value will be converted to NULL. |
| `datetime` | string | MySql JDBC driver has limitation. ZERO-DATE value will be converted to NULL. |
| `decimal` | number | |
| `decimal(19, 2)` | number | |
| `double` | number | |
Expand All @@ -42,7 +42,7 @@ If you can't find the data type you are looking for or have any problems feel fr
| `tinyint` | number | |
| `text` | string | |
| `time` | string | MySql JDBC driver has limitation. Value should be in range between 00:00:00 and 23:59:59. |
| `timestamp` | string | MySql JDBC driver has limitation. ZERO-DATE value is forbidden. |
| `timestamp` | string | MySql JDBC driver has limitation. ZERO-DATE value will be converted to NULL. |
| `tinytext` | string | |
| `varbinary(256)` | string | |
| `varchar` | string | |
Expand Down

0 comments on commit 0f0883b

Please sign in to comment.