Skip to content

Commit

Permalink
feat: Throw exception when writing array/vector of big decimals to pa…
Browse files Browse the repository at this point in the history
…rquet (deephaven#5930)
  • Loading branch information
malhotrashivam authored Aug 13, 2024
1 parent a45c3a9 commit a922e44
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ static TypeInfo getTypeInfo(
final RowSet rowSet,
final Map<String, ? extends ColumnSource<?>> columnSourceMap,
@NotNull final ParquetInstructions instructions) {
final Class<?> dataType = column.getDataType();
if (BigDecimal.class.equals(dataType)) {
if (BigDecimal.class.equals(column.getDataType())) {
return bigDecimalTypeInfo(computedCache, column, rowSet, columnSourceMap);
}
if (BigDecimal.class.equals(column.getComponentType())) {
throw new UnsupportedOperationException("Writing arrays/vector columns for big decimals is currently not " +
"supported");
// TODO(deephaven-core#4612): Add support for this
}
return lookupTypeInfo(column, instructions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,29 @@ private static Table arrayToVectorTable(final Table table) {
return arrayToVectorFormulas.isEmpty() ? table : table.updateView(arrayToVectorFormulas);
}

@Test
public void testBigDecimalArrayColumn() {
final Table bdArrayTable = TableTools.emptyTable(10000).select(Selectable.from(List.of(
"someBigDecimalArrayColumn = new java.math.BigDecimal[] {i % 10 == 0 ? null : " +
"java.math.BigDecimal.valueOf(ii).stripTrailingZeros()}")));
final File dest = new File(rootFile + File.separator + "testBigDecimalArrayColumn.parquet");
try {
ParquetTools.writeTable(bdArrayTable, dest.getPath());
fail("Expected exception because writing arrays of big decimal column types is not supported");
} catch (final RuntimeException e) {
assertTrue(e.getCause() instanceof UnsupportedOperationException);
}

// Convert array to vector table
final Table bdVectorTable = arrayToVectorTable(bdArrayTable);
try {
ParquetTools.writeTable(bdVectorTable, dest.getPath());
fail("Expected exception because writing vectors of big decimal column types is not supported");
} catch (final RuntimeException e) {
assertTrue(e.getCause() instanceof UnsupportedOperationException);
}
}

@Test
public void testArrayColumns() {
ArrayList<String> columns =
Expand Down

0 comments on commit a922e44

Please sign in to comment.