Skip to content

mysql-source:fix tinyint unsigned handling #18619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.debezium.internals;

import io.debezium.connector.mysql.converters.TinyIntOneToBooleanConverter;
import io.debezium.spi.converter.RelationalColumn;
import org.apache.kafka.connect.data.SchemaBuilder;

public class CustomMySQLTinyIntOneToBooleanConverter extends TinyIntOneToBooleanConverter {

@Override
public void converterFor(final RelationalColumn field, final ConverterRegistration<SchemaBuilder> registration) {
if (!"TINYINT".equalsIgnoreCase(field.typeName())) {
return;
}
super.converterFor(field, registration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static Properties commonProperties(final JdbcDatabase database) {
* {@link MySQLConverter}
*/
props.setProperty("converters", "boolean, datetime");
props.setProperty("boolean.type", "io.debezium.connector.mysql.converters.TinyIntOneToBooleanConverter");
props.setProperty("boolean.type", "io.airbyte.integrations.debezium.internals.CustomMySQLTinyIntOneToBooleanConverter");
props.setProperty("datetime.type", "io.airbyte.integrations.debezium.internals.MySQLDateTimeConverter");

// For CDC mode, the user cannot provide timezone arguments as JDBC parameters - they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ protected void initTests() {
.addExpectedValues(null, "true", "false")
.build());

addDataTypeTestData(
TestDataHolder.builder()
.sourceType("tinyint")
.fullSourceDataType("tinyint(1) unsigned")
.airbyteType(JsonSchemaType.INTEGER)
.addInsertValues("null", "0", "1", "2", "3")
.addExpectedValues(null, "0", "1", "2", "3")
.build());

addDataTypeTestData(
TestDataHolder.builder()
.sourceType("tinyint")
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ MySQL data types are mapped to the following data types when synchronizing data.
| `boolean` | boolean | |
| `tinyint(1)` | boolean | |
| `tinyint(>1)` | number | |
| `tinyint(>=1) unsigned` | number | |
| `smallint` | number | |
| `mediumint` | number | |
| `int` | number | |
Expand Down