Skip to content

Commit

Permalink
JDBC sources: Fix unexcepcted long Integer value failure (airbytehq#3846
Browse files Browse the repository at this point in the history
)

JDBC sources: Implement an additional handler for the Integer source values in order to cover the case with too large a value (possible for some sources)
  • Loading branch information
DoNotPanicUA authored Jun 4, 2021
1 parent cdd1d0a commit 96bd949
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "435bb9a5-7887-4809-aa58-28c27df0d7ad",
"name": "MySQL",
"dockerRepository": "airbyte/source-mysql",
"dockerImageTag": "0.3.3",
"dockerImageTag": "0.3.4",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/mysql",
"icon": "mysql.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
- sourceDefinitionId: 435bb9a5-7887-4809-aa58-28c27df0d7ad
name: MySQL
dockerRepository: airbyte/source-mysql
dockerImageTag: 0.3.3
dockerImageTag: 0.3.4
documentationUrl: https://docs.airbyte.io/integrations/sources/mysql
icon: mysql.svg
- sourceDefinitionId: 2470e835-feaf-4db6-96f3-70fd645acc77
Expand Down
15 changes: 14 additions & 1 deletion airbyte-db/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static void setJsonField(ResultSet r, int i, ObjectNode o) throws SQLExc
switch (columnType) {
case BIT, BOOLEAN -> o.put(columnName, r.getBoolean(i));
case TINYINT, SMALLINT -> o.put(columnName, r.getShort(i));
case INTEGER -> o.put(columnName, r.getInt(i));
case INTEGER -> putInteger(o, columnName, r, i);
case BIGINT -> o.put(columnName, nullIfInvalid(() -> r.getLong(i)));
case FLOAT, DOUBLE -> o.put(columnName, nullIfInvalid(() -> r.getDouble(i), Double::isFinite));
case REAL -> o.put(columnName, nullIfInvalid(() -> r.getFloat(i), Float::isFinite));
Expand All @@ -151,6 +151,19 @@ private static void setJsonField(ResultSet r, int i, ObjectNode o) throws SQLExc
}
}

/**
* In some sources Integer might have value larger than {@link Integer#MAX_VALUE}. E.q. MySQL has
* unsigned Integer type, which can contain value 3428724653. If we fail to cast Integer value, we
* will try to cast Long.
*/
private static void putInteger(ObjectNode node, String columnName, ResultSet resultSet, int index) {
try {
node.put(columnName, resultSet.getInt(index));
} catch (SQLException e) {
node.put(columnName, nullIfInvalid(() -> resultSet.getLong(index)));
}
}

// todo (cgardens) - move generic date helpers to commons.

public static String toISO8601String(long epochMillis) {
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar

RUN tar xf ${APPLICATION}.tar --strip-components=1

LABEL io.airbyte.version=0.3.3
LABEL io.airbyte.version=0.3.4

LABEL io.airbyte.name=airbyte/source-mysql

0 comments on commit 96bd949

Please sign in to comment.