Skip to content

Commit

Permalink
[barrage] correctly advertise String[] types (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind authored Nov 2, 2021
1 parent 2f13538 commit 5d5a8bd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.deephaven.db.v2.sources.chunk.ChunkType;
import io.deephaven.grpc_api.util.SchemaHelper;
import io.deephaven.proto.backplane.grpc.ExportedTableCreationResponse;
import io.deephaven.util.type.TypeUtils;
import org.apache.arrow.flatbuf.KeyValue;
import org.apache.arrow.flatbuf.Message;
import org.apache.arrow.flatbuf.MetadataVersion;
Expand Down Expand Up @@ -398,6 +399,16 @@ private static ConvertedArrowSchema convertArrowSchema(
return result;
}

private static boolean isTypeNativelySupported(final Class<?> typ) {
if (typ.isPrimitive() || TypeUtils.isBoxedType(typ) || supportedTypes.contains(typ)) {
return true;
}
if (typ.isArray()) {
return isTypeNativelySupported(typ.getComponentType());
}
return false;
}

private static Field arrowFieldFor(final String name, final ColumnDefinition<?> column, final String description,
final MutableInputTable inputTable, final Map<String, String> extraMetadata) {
List<Field> children = Collections.emptyList();
Expand All @@ -407,7 +418,7 @@ private static Field arrowFieldFor(final String name, final ColumnDefinition<?>
final Class<?> componentType = column.getComponentType();
final Map<String, String> metadata = new HashMap<>(extraMetadata);

if (type.isPrimitive() || supportedTypes.contains(type)) {
if (isTypeNativelySupported(type)) {
putMetadata(metadata, "type", type.getCanonicalName());
} else {
// otherwise will be converted to a string
Expand All @@ -429,11 +440,18 @@ private static Field arrowFieldFor(final String name, final ColumnDefinition<?>
putMetadata(metadata, "inputtable.isKey", Arrays.asList(inputTable.getKeyNames()).contains(name) + "");
}

return arrowFieldFor(name, type, componentType, metadata);
}

private static Field arrowFieldFor(
final String name, final Class<?> type, final Class<?> componentType, final Map<String, String> metadata) {
List<Field> children = Collections.emptyList();

final FieldType fieldType = arrowFieldTypeFor(type, componentType, metadata);
if (fieldType.getType().isComplex()) {
if (type.isArray()) {
children = Collections.singletonList(
new Field("", arrowFieldTypeFor(componentType, null, metadata), Collections.emptyList()));
children = Collections.singletonList(arrowFieldFor(
"", componentType, componentType.getComponentType(), Collections.emptyMap()));
} else {
throw new UnsupportedOperationException("Arrow Complex Type Not Supported: " + fieldType.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,49 @@ public void testTimestampColumn() throws InterruptedException, ExecutionExceptio
assertRoundTripDataEqual(TableTools.emptyTable(10).update("tm = DBDateTime.now()"));
}

@Test
public void testStringCol() throws InterruptedException, ExecutionException {
assertRoundTripDataEqual(TableTools.emptyTable(10).update("S = \"test\""));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("S = new String[] {\"test\", \"42\"}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("S = new String[][] {new String[] {\"t1\"}}"));

assertRoundTripDataEqual(TableTools.emptyTable(10).update("S = new String[][][] {" +
"null, new String[][] {" +
" null, " +
" new String[] {" +
" null, \"elem_1_1_1\"" +
"}}, new String[][] {" +
" null, " +
" new String[] {" +
" null, \"elem_2_1_1\"" +
" }, new String[] {" +
" null, \"elem_2_2_1\", \"elem_2_2_2\"" +
"}}, new String[][] {" +
" null, " +
" new String[] {" +
" null, \"elem_3_1_1\"" +
" }, new String[] {" +
" null, \"elem_3_2_1\", \"elem_3_2_2\"" +
" }, new String[] {" +
" null, \"elem_3_3_1\", \"elem_3_3_2\", \"elem_3_3_3\"" +
"}}}"));
}

@Test
public void testLongCol() throws InterruptedException, ExecutionException {
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = ii"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new long[] {ii}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new long[][] {new long[] {ii}}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = (Long)ii"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new Long[] {ii}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new Long[] {ii, null}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new Long[][] {new Long[] {ii}}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = new Long[][] {null, new Long[] {null, ii}}"));
assertRoundTripDataEqual(TableTools.emptyTable(10).update("L = io.deephaven.util.QueryConstants.NULL_LONG"));
assertRoundTripDataEqual(
TableTools.emptyTable(10).update("L = new long[] {0, -1, io.deephaven.util.QueryConstants.NULL_LONG}"));
}

@Test
public void testFlightInfo() {
final String staticTableName = "flightInfoTest";
Expand Down

0 comments on commit 5d5a8bd

Please sign in to comment.