-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Source IBM Db2: Connector provides wrong values for a datatype (#7670)
* added DB2 type transformation * added DB2 type transformation * fixed code style * fixed remarks * fixed remarks * fixed remarks * added java doc for certificate generation * bump new version
- Loading branch information
1 parent
c511abd
commit 6d30ba4
Showing
8 changed files
with
95 additions
and
21 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
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
73 changes: 73 additions & 0 deletions
73
...tors/source-db2/src/main/java/io.airbyte.integrations.source.db2/Db2SourceOperations.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,73 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.db2; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.db.jdbc.JdbcSourceOperations; | ||
import java.sql.JDBCType; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Db2SourceOperations extends JdbcSourceOperations { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(Db2SourceOperations.class); | ||
private static final List<String> DB2_UNIQUE_NUMBER_TYPES = List.of("DECFLOAT"); | ||
|
||
@Override | ||
public JsonNode rowToJson(final ResultSet queryContext) throws SQLException { | ||
final int columnCount = queryContext.getMetaData().getColumnCount(); | ||
final ObjectNode jsonNode = (ObjectNode) Jsons.jsonNode(Collections.emptyMap()); | ||
|
||
for (int i = 1; i <= columnCount; i++) { | ||
setFields(queryContext, i, jsonNode); | ||
} | ||
|
||
return jsonNode; | ||
} | ||
|
||
/* Helpers */ | ||
|
||
private void setFields(ResultSet queryContext, int index, ObjectNode jsonNode) throws SQLException { | ||
try { | ||
queryContext.getObject(index); | ||
if (!queryContext.wasNull()) { | ||
setJsonField(queryContext, index, jsonNode); | ||
} | ||
} catch (SQLException e) { | ||
if (DB2_UNIQUE_NUMBER_TYPES.contains(queryContext.getMetaData().getColumnTypeName(index))) { | ||
db2UniqueTypes(queryContext, index, jsonNode); | ||
} else { | ||
throw new SQLException(e.getCause()); | ||
} | ||
} | ||
} | ||
|
||
private void db2UniqueTypes(ResultSet resultSet, int index, ObjectNode jsonNode) throws SQLException { | ||
String columnType = resultSet.getMetaData().getColumnTypeName(index); | ||
String columnName = resultSet.getMetaData().getColumnName(index); | ||
if (DB2_UNIQUE_NUMBER_TYPES.contains(columnType)) { | ||
putDecfloat(jsonNode, columnName, resultSet, index); | ||
} | ||
} | ||
|
||
private void putDecfloat(final ObjectNode node, | ||
final String columnName, | ||
final ResultSet resultSet, | ||
final int index) { | ||
try { | ||
final double value = resultSet.getDouble(index); | ||
node.put(columnName, value); | ||
} catch (final SQLException e) { | ||
node.put(columnName, (Double) null); | ||
} | ||
} | ||
|
||
} |
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