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

Can't load table from Postgres to Clickhouse containing nullable numeric column #529

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all 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
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
Loading