Skip to content
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

JDBC sources: Fix unexcepcted long Integer value failure #3846

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Changes from 3 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
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