Skip to content

Commit

Permalink
Merge pull request #529 from ZlobnyiSerg/develop
Browse files Browse the repository at this point in the history
Can't load table from Postgres to Clickhouse containing nullable numeric column
  • Loading branch information
subkanthi authored Apr 25, 2024
2 parents 872650c + 3e32857 commit 74503dd
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,22 @@ else if (value instanceof Long) {
if (value instanceof Struct) {
Struct decimalValue = (Struct) value;
Object scale = decimalValue.get("scale");
Object unscaledValueInBytes = decimalValue.get("value");
BigDecimal bd = new BigDecimal(new BigInteger((byte[]) unscaledValueInBytes), (Integer) scale);
ps.setBigDecimal(index, bd);

Object unscaledValueObject = decimalValue.get("value");

byte[] unscaledValueBytes;
if (unscaledValueObject instanceof ByteBuffer) {
ByteBuffer unscaledByteBuffer = (ByteBuffer) unscaledValueObject;
unscaledValueBytes = new byte[unscaledByteBuffer.remaining()];
unscaledByteBuffer.get(unscaledValueBytes);
} else if (unscaledValueObject instanceof byte[]) {
unscaledValueBytes = (byte[]) unscaledValueObject;
} else {
// Handle unexpected type
throw new IllegalArgumentException("Unexpected type for unscaled value");
}

BigDecimal bigDecimal = new BigDecimal(new BigInteger(unscaledValueBytes), (Integer) scale);
ps.setBigDecimal(index, bigDecimal);
} else {
ps.setBigDecimal(index, new BigDecimal(0));
}
Expand Down

0 comments on commit 74503dd

Please sign in to comment.