Skip to content

Commit

Permalink
Improve error message for null column names and data arrays (#4097)
Browse files Browse the repository at this point in the history
  • Loading branch information
arman-ddl committed Jun 29, 2023
1 parent d7f7098 commit 84072c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private ColumnDefinition(
@NotNull final Class<TYPE> dataType,
@Nullable final Class<?> componentType,
@NotNull final ColumnType columnType) {
this.name = Objects.requireNonNull(name);
this.name = Objects.requireNonNull(name, "Column names cannot be null");
this.dataType = Objects.requireNonNull(dataType);
this.componentType = componentType;
this.columnType = Objects.requireNonNull(columnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package io.deephaven.engine.table.impl;

import io.deephaven.datastructures.util.CollectionUtil;
import io.deephaven.engine.exceptions.ArgumentException;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.engine.table.impl.sources.ArrayBackedColumnSource;
import io.deephaven.engine.table.ColumnSource;
Expand All @@ -13,7 +13,6 @@
import io.deephaven.qst.table.NewTable;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -64,7 +63,13 @@ private InMemoryTable(TableDefinition definition, TrackingRowSet rowSet,
private static Map<String, ColumnSource<?>> createColumnsMap(String[] columnNames, Object[] arrayValues) {
Map<String, ColumnSource<?>> map = new LinkedHashMap<>();
for (int i = 0; i < columnNames.length; i++) {
map.put(columnNames[i], ArrayBackedColumnSource.getMemoryColumnSourceUntyped((arrayValues[i])));
final String columnName = columnNames[i];
final Object array = arrayValues[i];
if (array == null) {
throw new ArgumentException("Value array for column " + columnName + " is null");
}

map.put(columnName, ArrayBackedColumnSource.getMemoryColumnSourceUntyped(array));
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.deephaven.base.verify.Require;
import io.deephaven.datastructures.util.CollectionUtil;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.exceptions.ArgumentException;
import io.deephaven.engine.rowset.WritableRowSet;
import io.deephaven.engine.rowset.RowSequence;
import io.deephaven.engine.rowset.RowSetFactory;
Expand Down Expand Up @@ -694,8 +695,7 @@ private static <MT extends Map<KT, VT>, KT, VT> MT newMapFromLists(Class<MT> map
*/
public static Table newTable(long size, List<String> names, List<ColumnSource<?>> columnSources) {
// noinspection unchecked
return new QueryTable(RowSetFactory.flat(size).toTracking(),
newMapFromLists(LinkedHashMap.class, names, columnSources));
return newTable(size, newMapFromLists(LinkedHashMap.class, names, columnSources));
}

/**
Expand All @@ -706,6 +706,13 @@ public static Table newTable(long size, List<String> names, List<ColumnSource<?>
* @return a Deephaven Table
*/
public static Table newTable(long size, Map<String, ColumnSource<?>> columns) {
for (final Map.Entry<String, ColumnSource<?>> entry : columns.entrySet()) {
final String columnName = entry.getKey();
if (entry.getValue() == null) {
throw new ArgumentException("Column source for " + columnName + " is null");
}
}

return new QueryTable(RowSetFactory.flat(size).toTracking(), columns);
}

Expand Down

0 comments on commit 84072c6

Please sign in to comment.