From 36fcef1e9f6af1a46b1c3551b42dfd7a402ba4f9 Mon Sep 17 00:00:00 2001 From: Ryan Caudy Date: Thu, 18 Apr 2024 23:16:09 -0400 Subject: [PATCH 1/4] Retire DataColumn and replace usages --- .../io/deephaven/plot/util/PlotUtils.java | 8 +- .../util/tables/ColumnHandlerFactory.java | 116 +-- .../engine/table/impl/DataAccessHelpers.java | 54 -- .../engine/table/impl/KeyedTableListener.java | 95 +-- .../impl/QueryLibraryImportsDefaults.java | 4 +- .../table/impl/MultiColumnSortTest.java | 5 +- .../table/impl/QueryTableAggregationTest.java | 678 ++++++++++-------- .../engine/table/impl/QueryTableAjTest.java | 13 +- .../engine/table/impl/QueryTableJoinTest.java | 262 +++---- .../table/impl/QueryTableNaturalJoinTest.java | 165 +++-- .../impl/QueryTableSelectUpdateTest.java | 62 +- .../table/impl/QueryTableSliceTest.java | 3 +- .../engine/table/impl/QueryTableSortTest.java | 134 ++-- .../engine/table/impl/QueryTableTest.java | 305 ++++---- .../table/impl/QueryTableWhereTest.java | 42 +- .../table/impl/QueryTableWouldMatchTest.java | 94 +-- .../engine/table/impl/TestAggBy.java | 87 ++- .../table/impl/TestAggregatedSelect.java | 21 +- .../impl/TestConcurrentInstantiation.java | 6 +- .../impl/TestPartitionAwareSourceTable.java | 10 +- .../engine/table/impl/TestPartitionBy.java | 4 +- .../engine/table/impl/TestSharedContext.java | 16 +- .../deephaven/engine/table/impl/TestSort.java | 58 +- .../engine/table/impl/TestTotalsTable.java | 70 +- .../by/TestSortedFirstOrLastByFactory.java | 26 +- .../table/impl/select/TestClockFilters.java | 38 +- .../impl/select/WhereFilterFactoryTest.java | 25 +- .../table/impl/updateby/TestCumMinMax.java | 28 +- .../table/impl/updateby/TestCumProd.java | 26 +- .../table/impl/updateby/TestCumSum.java | 26 +- .../engine/table/impl/updateby/TestDelta.java | 50 +- .../table/impl/updateby/TestEmMinMax.java | 110 +-- .../engine/table/impl/updateby/TestEmStd.java | 64 +- .../engine/table/impl/updateby/TestEma.java | 4 +- .../engine/table/impl/updateby/TestEms.java | 58 +- .../table/impl/updateby/TestForwardFill.java | 31 +- .../table/impl/updateby/TestRollingAvg.java | 50 +- .../table/impl/updateby/TestRollingCount.java | 50 +- .../table/impl/updateby/TestRollingGroup.java | 50 +- .../impl/updateby/TestRollingMinMax.java | 98 +-- .../impl/updateby/TestRollingProduct.java | 50 +- .../table/impl/updateby/TestRollingStd.java | 50 +- .../table/impl/updateby/TestRollingSum.java | 92 ++- .../table/impl/updateby/TestRollingWAvg.java | 26 +- .../table/impl/util/TestSyncTableFilter.java | 4 +- .../util/TestCalendarMethodsFromTable.java | 5 +- .../deephaven/engine/util/TestColorUtil.java | 10 +- .../engine/util/TestOuterJoinTools.java | 227 +++--- .../deephaven/engine/util/TestTableTools.java | 157 ++-- .../deephaven/engine/testutil/TstUtils.java | 24 + .../main/java/io/deephaven/csv/CsvTools.java | 35 +- .../java/io/deephaven/csv/TestCsvTools.java | 55 +- .../parquet/table/TestParquetTools.java | 28 +- .../client/examples/SnapshotExampleBase.java | 7 +- .../client/examples/SubscribeExampleBase.java | 3 +- py/server/deephaven/numpy.py | 5 +- py/server/deephaven/pandas.py | 5 +- .../test/FlightMessageRoundTripTest.java | 18 +- 58 files changed, 1943 insertions(+), 1904 deletions(-) delete mode 100644 engine/table/src/main/java/io/deephaven/engine/table/impl/DataAccessHelpers.java diff --git a/Plot/src/main/java/io/deephaven/plot/util/PlotUtils.java b/Plot/src/main/java/io/deephaven/plot/util/PlotUtils.java index 2fb87360e71..0e7ad86ae14 100644 --- a/Plot/src/main/java/io/deephaven/plot/util/PlotUtils.java +++ b/Plot/src/main/java/io/deephaven/plot/util/PlotUtils.java @@ -7,8 +7,8 @@ import io.deephaven.api.agg.Aggregation; import io.deephaven.base.verify.Require; import io.deephaven.datastructures.util.CollectionUtil; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.plot.ChartImpl; import io.deephaven.plot.datasets.category.CategoryDataSeries; import io.deephaven.plot.datasets.data.*; @@ -16,7 +16,6 @@ import io.deephaven.plot.errors.PlotInfo; import io.deephaven.plot.util.tables.TableBackedPartitionedTableHandle; import io.deephaven.plot.util.tables.TableHandle; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.engine.context.QueryScope; @@ -30,6 +29,7 @@ import io.deephaven.gui.color.ColorPalette; import io.deephaven.gui.color.Paint; import io.deephaven.gui.table.filters.Condition; +import io.deephaven.vector.Vector; import org.jetbrains.annotations.NotNull; import java.math.BigDecimal; @@ -805,8 +805,8 @@ public HashMapWithDefault copy() { } public static IndexableData createIndexableData(final Table t, final String column, final PlotInfo plotInfo) { - final DataColumn dataColumn = DataAccessHelpers.getColumn(t, column); - final Object o = dataColumn.getDirect(); + final Vector vector = ColumnVectors.of(t, column); + final Object o = vector.copyToArray(); return new IndexableDataArray((T[]) o, plotInfo); } diff --git a/Plot/src/main/java/io/deephaven/plot/util/tables/ColumnHandlerFactory.java b/Plot/src/main/java/io/deephaven/plot/util/tables/ColumnHandlerFactory.java index 7cefd4d156a..0572d6468ff 100644 --- a/Plot/src/main/java/io/deephaven/plot/util/tables/ColumnHandlerFactory.java +++ b/Plot/src/main/java/io/deephaven/plot/util/tables/ColumnHandlerFactory.java @@ -3,11 +3,11 @@ // package io.deephaven.plot.util.tables; -import io.deephaven.engine.table.impl.DataAccessHelpers; +import io.deephaven.engine.rowset.RowSet; +import io.deephaven.engine.table.ColumnSource; import io.deephaven.plot.errors.PlotInfo; import io.deephaven.plot.errors.PlotUnsupportedOperationException; import io.deephaven.plot.util.ArgumentValidations; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.gui.color.Paint; import io.deephaven.time.DateTimeUtils; @@ -34,7 +34,7 @@ public enum TypeClassification { this.isNumeric = isNumeric; } - private boolean isNumeric; + private final boolean isNumeric; public boolean isNumeric() { return isNumeric; @@ -106,8 +106,9 @@ private static abstract class ColumnHandlerTable implements ColumnHandler { private Table table; private final String columnName; private final Class type; - private transient DataColumn dataColumn; private final PlotInfo plotInfo; + private transient RowSet rowSet; + private transient ColumnSource columnSource; private ColumnHandlerTable(final Table table, final String columnName, Class type, final PlotInfo plotInfo) { this.type = type; @@ -117,12 +118,22 @@ private ColumnHandlerTable(final Table table, final String columnName, Class typ this.plotInfo = plotInfo; } - protected DataColumn getDataColumn() { - if (dataColumn == null) { - dataColumn = DataAccessHelpers.getColumn(table, columnName); + private void ensureInitialized() { + if (columnSource == null) { + final Table coalesced = table.coalesce(); + rowSet = coalesced.getRowSet(); + columnSource = coalesced.getColumnSource(columnName); } + } + + protected ColumnSource getColumnSource() { + ensureInitialized(); + return columnSource; + } - return dataColumn; + protected RowSet getRowSet() { + ensureInitialized(); + return rowSet; } public TableHandle getTableHandle() { @@ -134,11 +145,13 @@ public String getColumnName() { } public int size() { - return getDataColumn().intSize(); + ensureInitialized(); + return rowSet.intSize(); } public Object get(final int i) { - return getDataColumn().get(i); + ensureInitialized(); + return columnSource.get(rowSet.get(i)); } public Class type() { @@ -157,7 +170,8 @@ private static abstract class ColumnHandlerHandle implements ColumnHandler, Seri private final String columnName; private final Class type; private final PlotInfo plotInfo; - private transient DataColumn dataColumn; + private transient RowSet rowSet; + private transient ColumnSource columnSource; private ColumnHandlerHandle(final TableHandle tableHandle, final String columnName, final Class type, final PlotInfo plotInfo) { @@ -168,12 +182,22 @@ private ColumnHandlerHandle(final TableHandle tableHandle, final String columnNa this.plotInfo = plotInfo; } - protected DataColumn getDataColumn() { - if (dataColumn == null) { - dataColumn = DataAccessHelpers.getColumn(tableHandle.getTable(), columnName); + private void ensureInitialized() { + if (columnSource == null) { + final Table table = tableHandle.getTable().coalesce(); + rowSet = table.getRowSet(); + columnSource = table.getColumnSource(columnName); } + } + + protected ColumnSource getColumnSource() { + ensureInitialized(); + return columnSource; + } - return dataColumn; + protected RowSet getRowSet() { + ensureInitialized(); + return rowSet; } public TableHandle getTableHandle() { @@ -185,11 +209,13 @@ public String getColumnName() { } public int size() { - return getDataColumn().intSize(); + ensureInitialized(); + return rowSet.intSize(); } public Object get(final int i) { - return getDataColumn().get(i); + ensureInitialized(); + return columnSource.get(rowSet.get(i)); } public Class type() { @@ -228,7 +254,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final short value = getDataColumn().getShort(i); + final short value = getColumnSource().getShort(getRowSet().get(i)); return value == NULL_SHORT ? Double.NaN : value; } @@ -242,7 +268,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final int value = getDataColumn().getInt(i); + final int value = getColumnSource().getInt(getRowSet().get(i)); return value == NULL_INT ? Double.NaN : value; } @@ -256,7 +282,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final long value = getDataColumn().getLong(i); + final long value = getColumnSource().getLong(getRowSet().get(i)); return value == NULL_LONG ? Double.NaN : value; } @@ -270,7 +296,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final double value = getDataColumn().getFloat(i); + final float value = getColumnSource().getFloat(getRowSet().get(i)); return value == NULL_FLOAT ? Double.NaN : value; } @@ -284,7 +310,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final double value = getDataColumn().getDouble(i); + final double value = getColumnSource().getDouble(getRowSet().get(i)); return value == NULL_DOUBLE ? Double.NaN : value; } @@ -298,7 +324,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -312,7 +338,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -326,7 +352,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -340,7 +366,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -354,7 +380,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -368,7 +394,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -382,7 +408,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Date value = (Date) getDataColumn().get(i); + final Date value = (Date) get(i); return value == null ? Double.NaN : value.getTime() * 1000000; } @@ -396,7 +422,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Instant value = (Instant) getDataColumn().get(i); + final Instant value = (Instant) get(i); return value == null ? Double.NaN : DateTimeUtils.epochNanos(value); } @@ -410,7 +436,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final ZonedDateTime value = (ZonedDateTime) getDataColumn().get(i); + final ZonedDateTime value = (ZonedDateTime) get(i); return value == null ? Double.NaN : DateTimeUtils.epochNanos(value); } @@ -459,7 +485,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final short value = getDataColumn().getShort(i); + final short value = getColumnSource().getShort(getRowSet().get(i)); return value == NULL_SHORT ? Double.NaN : value; } @@ -473,7 +499,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final int value = getDataColumn().getInt(i); + final int value = getColumnSource().getInt(getRowSet().get(i)); return value == NULL_INT ? Double.NaN : value; } @@ -487,7 +513,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final long value = getDataColumn().getLong(i); + final long value = getColumnSource().getLong(getRowSet().get(i)); return value == NULL_LONG ? Double.NaN : value; } @@ -501,7 +527,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final double value = getDataColumn().getFloat(i); + final float value = getColumnSource().getFloat(getRowSet().get(i)); return value == NULL_FLOAT ? Double.NaN : value; } @@ -515,7 +541,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final double value = getDataColumn().getDouble(i); + final double value = getColumnSource().getDouble(getRowSet().get(i)); return value == NULL_DOUBLE ? Double.NaN : value; } @@ -529,7 +555,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -543,7 +569,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -557,7 +583,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -571,7 +597,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -585,7 +611,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -599,7 +625,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Number value = (Number) getDataColumn().get(i); + final Number value = (Number) get(i); return value == null ? Double.NaN : value.doubleValue(); } @@ -613,7 +639,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Date value = (Date) getDataColumn().get(i); + final Date value = (Date) get(i); return value == null ? Double.NaN : value.getTime() * 1000000; } @@ -627,7 +653,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final Instant value = (Instant) getDataColumn().get(i); + final Instant value = (Instant) get(i); return value == null ? Double.NaN : DateTimeUtils.epochNanos(value); } @@ -641,7 +667,7 @@ public TypeClassification typeClassification() { @Override public double getDouble(int i) { - final ZonedDateTime value = (ZonedDateTime) getDataColumn().get(i); + final ZonedDateTime value = (ZonedDateTime) get(i); return value == null ? Double.NaN : DateTimeUtils.epochNanos(value); } diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/DataAccessHelpers.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/DataAccessHelpers.java deleted file mode 100644 index be5e557d1b0..00000000000 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/DataAccessHelpers.java +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl; - -import io.deephaven.engine.liveness.LivenessScopeStack; -import io.deephaven.engine.table.DataColumn; -import io.deephaven.engine.table.Table; -import io.deephaven.util.SafeCloseable; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -@Deprecated -public class DataAccessHelpers { - - // ----------------------------------------------------------------------------------------------------------------- - // DataColumns for fetching data by row position; generally much less efficient than ColumnSource - // TODO(deephaven-core#3920): Delete DataColumn - // ----------------------------------------------------------------------------------------------------------------- - - public static DataColumn[] getColumns(Table table) { - final Table t = table.coalesce(); - return t.getDefinition() - .getColumnStream() - .map(c -> getColumn(t, c.getName())) - .toArray(DataColumn[]::new); - } - - public static DataColumn getColumn(Table table, final int columnIndex) { - return getColumn(table, table.getDefinition().getColumns().get(columnIndex).getName()); - } - - public static DataColumn getColumn(Table table, @NotNull final String columnName) { - return new IndexedDataColumn<>(columnName, table.coalesce()); - } - - - // ----------------------------------------------------------------------------------------------------------------- - // Convenience data fetching; highly inefficient - // ----------------------------------------------------------------------------------------------------------------- - - public static Object[] getRecord(Table table, long rowNo, String... columnNames) { - try (final SafeCloseable ignored = LivenessScopeStack.open()) { - final Table t = table.coalesce(); - final long key = t.getRowSet().get(rowNo); - return (columnNames.length > 0 - ? Arrays.stream(columnNames).map(t::getColumnSource) - : t.getColumnSources().stream()) - .map(columnSource -> columnSource.get(key)) - .toArray(Object[]::new); - } - } -} diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/KeyedTableListener.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/KeyedTableListener.java index e7b6c806845..211b14e40e6 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/KeyedTableListener.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/KeyedTableListener.java @@ -11,11 +11,14 @@ import gnu.trove.map.hash.TObjectLongHashMap; import io.deephaven.tuple.ArrayTuple; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; +import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; + public class KeyedTableListener { public enum KeyEvent { @@ -27,26 +30,24 @@ public interface KeyUpdateListener { } private final QueryTable table; - private final TObjectLongHashMap keyToIndexHashMap; - private final TLongObjectHashMap indexToKeyHashMap; + private final TObjectLongHashMap keyToRowKeyHashMap; + private final TLongObjectHashMap rowKeyToKeyHashMap; private final HashMap> keyListenerHashMap; private final String[] keyColumnNames; private final String[] allColumnNames; private final Map> parentColumnSourceMap; private final ShiftObliviousInstrumentedListenerAdapter tableListener; - private static final long NO_ENTRY = -1; - // TODO: create an even more generic internals to handle multiple matches // TODO: Refactor with some sort of internal assistant object (unique versus generic) - // TODO: private HashMap keyToIndexObjectHashMap; // for storing multiple + // TODO: private HashMap keyToRowKeyObjectHashMap; // for storing multiple // matches public KeyedTableListener(QueryTable table, String... keyColumnNames) { this.table = table; final int tableSize = table.intSize("KeyedTableListener.initialize"); - this.keyToIndexHashMap = new TObjectLongHashMap<>(tableSize, 0.75f, NO_ENTRY); - this.indexToKeyHashMap = new TLongObjectHashMap<>(tableSize, 0.75f, NO_ENTRY); + this.keyToRowKeyHashMap = new TObjectLongHashMap<>(tableSize, 0.75f, NULL_ROW_KEY); + this.rowKeyToKeyHashMap = new TLongObjectHashMap<>(tableSize, 0.75f, NULL_ROW_KEY); this.keyListenerHashMap = new HashMap<>(); this.keyColumnNames = keyColumnNames; this.tableListener = new ShiftObliviousInstrumentedListenerAdapter(null, table, false) { @@ -74,18 +75,18 @@ private void handleUpdateFromTable(final RowSet added, final RowSet removed, fin for (RowSet.Iterator iterator = added.iterator(); iterator.hasNext();) { long next = iterator.nextLong(); ArrayTuple key = constructArrayTuple(next); - keyToIndexHashMap.put(key, next); - indexToKeyHashMap.put(next, key); + keyToRowKeyHashMap.put(key, next); + rowKeyToKeyHashMap.put(next, key); handleListeners(key, next, KeyEvent.ADDED); } // Remove all the removed rows from the hashmap for (RowSet.Iterator iterator = removed.iterator(); iterator.hasNext();) { long next = iterator.nextLong(); - ArrayTuple oldKey = indexToKeyHashMap.remove(next); + ArrayTuple oldKey = rowKeyToKeyHashMap.remove(next); Assert.assertion(oldKey != null, "oldKey != null"); - long oldIndex = keyToIndexHashMap.remove(oldKey); - Assert.assertion(oldIndex != NO_ENTRY, "oldRow != NO_ENTRY"); + long oldRowKey = keyToRowKeyHashMap.remove(oldKey); + Assert.assertion(oldRowKey != NULL_ROW_KEY, "oldRow != NULL_ROW_KEY"); handleListeners(oldKey, next, KeyEvent.REMOVED); } @@ -93,27 +94,27 @@ private void handleUpdateFromTable(final RowSet added, final RowSet removed, fin for (RowSet.Iterator iterator = modified.iterator(); iterator.hasNext();) { long next = iterator.nextLong(); ArrayTuple currentKey = constructArrayTuple(next); - ArrayTuple prevKey = indexToKeyHashMap.get(next); + ArrayTuple prevKey = rowKeyToKeyHashMap.get(next); // Check if the key values have changed if (!currentKey.equals(prevKey)) { - // only want to remove the old key if it was pointing to this index - if (keyToIndexHashMap.get(prevKey) == next) { - keyToIndexHashMap.remove(prevKey); - indexToKeyHashMap.remove(next); + // only want to remove the old key if it was pointing to this rowKey + if (keyToRowKeyHashMap.get(prevKey) == next) { + keyToRowKeyHashMap.remove(prevKey); + rowKeyToKeyHashMap.remove(next); handleListeners(prevKey, next, KeyEvent.REMOVED); } - // Check if this current key was used elsewhere and remove the index->key mapping - long otherIndex = keyToIndexHashMap.get(currentKey); - if (otherIndex != NO_ENTRY) { - indexToKeyHashMap.remove(otherIndex); - handleListeners(currentKey, otherIndex, KeyEvent.REMOVED); + // Check if this current key was used elsewhere and remove the rowKey->key mapping + long otherRowKey = keyToRowKeyHashMap.get(currentKey); + if (otherRowKey != NULL_ROW_KEY) { + rowKeyToKeyHashMap.remove(otherRowKey); + handleListeners(currentKey, otherRowKey, KeyEvent.REMOVED); } // Update the maps and notify the newly modified key - keyToIndexHashMap.put(currentKey, next); - indexToKeyHashMap.put(next, currentKey); + keyToRowKeyHashMap.put(currentKey, next); + rowKeyToKeyHashMap.put(next, currentKey); handleListeners(currentKey, next, KeyEvent.ADDED); } else { handleListeners(currentKey, next, KeyEvent.MODIFIED); @@ -121,27 +122,27 @@ private void handleUpdateFromTable(final RowSet added, final RowSet removed, fin } } - private ArrayTuple constructArrayTuple(long index) { + private ArrayTuple constructArrayTuple(long rowKey) { Object[] ArrayTupleVals = new Object[keyColumnNames.length]; for (int i = 0; i < keyColumnNames.length; i++) { - ArrayTupleVals[i] = parentColumnSourceMap.get(keyColumnNames[i]).get(index); + ArrayTupleVals[i] = parentColumnSourceMap.get(keyColumnNames[i]).get(rowKey); } return new ArrayTuple(ArrayTupleVals); } - private void handleListeners(ArrayTuple key, long index, KeyEvent event) { + private void handleListeners(ArrayTuple key, long rowKey, KeyEvent event) { synchronized (keyListenerHashMap) { CopyOnWriteArrayList listeners = keyListenerHashMap.get(key); - if (listeners != null && listeners.size() > 0) { + if (listeners != null && !listeners.isEmpty()) { for (KeyUpdateListener listener : listeners) { - listener.update(this, key, index, event); + listener.update(this, key, rowKey, event); } } } } - public long getIndex(ArrayTuple key) { - return keyToIndexHashMap.get(key); + public long getRowKey(ArrayTuple key) { + return keyToRowKeyHashMap.get(key); } // Make sure these are in the same order as the keys defined on construction @@ -153,23 +154,29 @@ public Object[] getRow(ArrayTuple key) { return getRow(key, allColumnNames); } - public Object[] getRowAtIndex(long index) { - return getRowAtIndex(index, allColumnNames); + public Object[] getRowAtRowKey(long rowKey) { + return getRowAtRowKey(rowKey, allColumnNames); } public Object[] getRow(ArrayTuple key, String... columnNames) { - long index = getIndex(key); - return getRowAtIndex(index, columnNames); + long rowKey = getRowKey(key); + return getRowAtRowKey(rowKey, columnNames); } - public Object[] getRowAtIndex(long index, String... columnNames) { - long tableRow = table.getRowSet().find(index); - return (index != -1) ? DataAccessHelpers.getRecord(table, tableRow, columnNames) : null; + public Object[] getRowAtRowKey(long rowKey, String... columnNames) { + // @formatter:off + return rowKey == NULL_ROW_KEY + ? null + : (columnNames.length > 0 + ? Arrays.stream(columnNames).map(table::getColumnSource) + : table.getColumnSources().stream() + ).map(columnSource -> columnSource.get(rowKey)).toArray(Object[]::new); + // @formatter:on } - public long getTableRow(ArrayTuple key) { - long index = getIndex(key); - return (index == -1) ? -1 : table.getRowSet().find(index); + public long getRowPosition(ArrayTuple key) { + final long rowKey = getRowKey(key); + return rowKey == NULL_ROW_KEY ? NULL_ROW_KEY : table.getRowSet().find(rowKey); } public void subscribe(ArrayTuple key, KeyUpdateListener listener) { @@ -185,9 +192,9 @@ public void subscribe(ArrayTuple key, KeyUpdateListener listener, boolean replay callBackList.add(listener); if (replayInitialData) { - long index = keyToIndexHashMap.get(key); - if (index != keyToIndexHashMap.getNoEntryValue()) { - listener.update(this, key, index, KeyEvent.ADDED); + long rowKey = keyToRowKeyHashMap.get(key); + if (rowKey != keyToRowKeyHashMap.getNoEntryValue()) { + listener.update(this, key, rowKey, KeyEvent.ADDED); } } } diff --git a/engine/table/src/main/java/io/deephaven/engine/table/lang/impl/QueryLibraryImportsDefaults.java b/engine/table/src/main/java/io/deephaven/engine/table/lang/impl/QueryLibraryImportsDefaults.java index bb799b0dffa..5ef0ad1890e 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/lang/impl/QueryLibraryImportsDefaults.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/lang/impl/QueryLibraryImportsDefaults.java @@ -13,11 +13,11 @@ import io.deephaven.engine.rowset.chunkattributes.RowKeys; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Context; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.lang.QueryLanguageFunctionUtils; import io.deephaven.engine.table.impl.select.ConditionFilter; import io.deephaven.engine.table.impl.verify.TableAssertions; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.util.ColorUtilImpl; import io.deephaven.function.*; import io.deephaven.gui.color.Color; @@ -55,7 +55,6 @@ public Set> classes() { Array.class, TypeUtils.class, Table.class, - DataColumn.class, ArrayTypeUtils.class, VectorConversions.class, DateTimeUtils.class, @@ -69,6 +68,7 @@ public Set> classes() { Period.class, QueryScopeParam.class, ColumnSource.class, + ColumnVectors.class, RowSet.class, WritableRowSet.class, TrackingRowSet.class, diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/MultiColumnSortTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/MultiColumnSortTest.java index 99838d1a5c3..6d2b6b45e6d 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/MultiColumnSortTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/MultiColumnSortTest.java @@ -9,6 +9,7 @@ import io.deephaven.benchmarking.generator.ColumnGenerator; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.indexer.DataIndexer; +import io.deephaven.engine.testutil.TstUtils; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.test.types.SerialTest; @@ -158,10 +159,10 @@ private void checkSort(Table sorted, SortColumn... sortColumns) { final String[] columns = Arrays.stream(sortColumns).map(SortColumn::column).map(ColumnName::name) .toArray(String[]::new); - Object[] lastRow = DataAccessHelpers.getRecord(sorted, 0, columns); + Object[] lastRow = TstUtils.getRowData(sorted, 0, columns); for (int ii = 1; ii < sorted.intSize(); ++ii) { - final Object[] rowData = DataAccessHelpers.getRecord(sorted, ii, columns); + final Object[] rowData = TstUtils.getRowData(sorted, ii, columns); for (int jj = 0; jj < rowData.length; ++jj) { // make sure lastRow <= rowData diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java index e24e815cf44..c93b689e4f9 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java @@ -20,6 +20,7 @@ import io.deephaven.engine.rowset.TrackingWritableRowSet; import io.deephaven.engine.table.*; import io.deephaven.engine.table.impl.indexer.DataIndexer; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.QueryTableTestBase.TableComparator; import io.deephaven.engine.table.impl.by.*; import io.deephaven.engine.table.impl.select.IncrementalReleaseFilter; @@ -78,6 +79,9 @@ @Category(OutOfBandTest.class) public class QueryTableAggregationTest { + + private static final double DELTA = 0.000001; + @Rule public final EngineCleanup base = new EngineCleanup(); @@ -475,26 +479,27 @@ public void testStaticBy() { } catch (Exception e) { TestCase.assertEquals("Invalid column name \"i\": \"i\" is a reserved keyword", e.getMessage()); } - TestCase.assertEquals(0, table.updateView("j=i").groupBy("j").size()); - TestCase.assertEquals(2, table.updateView("j=i").groupBy("j").numColumns()); - TestCase.assertEquals(int.class, table.updateView("j=i").groupBy("j").getColumnSource("j").getType()); + Table grouped = table.updateView("j=i").groupBy("j"); + TestCase.assertEquals(0, grouped.size()); + TestCase.assertEquals(2, grouped.numColumns()); + TestCase.assertEquals(int.class, grouped.getColumnSource("j").getType()); table = newTable(intCol("V", 100)); - TestCase.assertEquals(1, table.updateView("j=i").groupBy("j").size()); - TestCase.assertEquals(2, table.updateView("j=i").groupBy("j").numColumns()); + TestCase.assertEquals(1, grouped.size()); + TestCase.assertEquals(2, grouped.numColumns()); TestCase.assertEquals(int.class, - table.updateView("j=i").groupBy("j").getDefinition().getColumn("j").getDataType()); + grouped.getDefinition().getColumn("j").getDataType()); table = testRefreshingTable(RowSetFactory.fromRange(0, 2).toTracking(), col("S", "c", "e", "g"), col("I", 2, 4, 6)); - - TestCase.assertEquals(3, table.groupBy("S").size()); - TestCase.assertEquals(2, table.groupBy("S").numColumns()); - TestCase.assertEquals(String.class, table.groupBy("S").getDefinition().getColumn("S").getDataType()); - TestCase.assertEquals(IntVector.class, table.groupBy("S").getDefinition().getColumn("I").getDataType()); - TestCase.assertEquals(Arrays.asList("c", "e", "g"), - Arrays.asList(DataAccessHelpers.getColumn(table.groupBy("S"), "S").get(0, 3))); - IntVector[] intGroups = (IntVector[]) DataAccessHelpers.getColumn(table.groupBy("S"), "I").getDirect(); + grouped = table.groupBy("S"); + TestCase.assertEquals(3, grouped.size()); + TestCase.assertEquals(2, grouped.numColumns()); + TestCase.assertEquals(String.class, grouped.getDefinition().getColumn("S").getDataType()); + TestCase.assertEquals(IntVector.class, grouped.getDefinition().getColumn("I").getDataType()); + Assert.assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors.ofObject(grouped, "S", String.class).toArray()); + IntVector[] intGroups = ColumnVectors.ofObject(grouped, "I", IntVector.class).toArray(); TestCase.assertEquals(3, intGroups.length); TestCase.assertEquals(1, intGroups[0].size()); TestCase.assertEquals(1, intGroups[1].size()); @@ -506,14 +511,14 @@ public void testStaticBy() { table = testRefreshingTable(RowSetFactory.fromRange(0, 2).toTracking(), col("S", "e", "c", "g"), col("I", 4, 2, 6)); - - TestCase.assertEquals(3, table.groupBy("S").size()); - TestCase.assertEquals(2, table.groupBy("S").numColumns()); - TestCase.assertEquals(String.class, table.groupBy("S").getDefinition().getColumn("S").getDataType()); - TestCase.assertEquals(IntVector.class, table.groupBy("S").getDefinition().getColumn("I").getDataType()); - TestCase.assertEquals(Arrays.asList("e", "c", "g"), - Arrays.asList(DataAccessHelpers.getColumn(table.groupBy("S"), "S").get(0, 3))); - intGroups = (IntVector[]) DataAccessHelpers.getColumn(table.groupBy("S"), "I").getDirect(); + grouped = table.groupBy("S"); + TestCase.assertEquals(3, grouped.size()); + TestCase.assertEquals(2, grouped.numColumns()); + TestCase.assertEquals(String.class, grouped.getDefinition().getColumn("S").getDataType()); + TestCase.assertEquals(IntVector.class, grouped.getDefinition().getColumn("I").getDataType()); + Assert.assertArrayEquals(new String[] {"e", "c", "g"}, + ColumnVectors.ofObject(grouped, "S", String.class).toArray()); + intGroups = ColumnVectors.ofObject(grouped, "I", IntVector.class).toArray(); TestCase.assertEquals(3, intGroups.length); TestCase.assertEquals(1, intGroups[0].size()); TestCase.assertEquals(1, intGroups[1].size()); @@ -526,19 +531,18 @@ public void testStaticBy() { col("S", "e", "c", "g"), col("X", 4, 2, 6), col("Y", 1, 2, 3)); - TestCase.assertEquals(3, table.updateView("Z=X+Y").groupBy("Z").size()); - TestCase.assertEquals(4, table.updateView("Z=X+Y").groupBy("Z").numColumns()); + grouped = table.updateView("Z=X+Y").groupBy("Z"); + TestCase.assertEquals(3, grouped.size()); + TestCase.assertEquals(4, grouped.numColumns()); TestCase.assertEquals(ObjectVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("S").getDataType()); + grouped.getDefinition().getColumn("S").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("X").getDataType()); + grouped.getDefinition().getColumn("X").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Y").getDataType()); + grouped.getDefinition().getColumn("Y").getDataType()); TestCase.assertEquals(int.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Z").getDataType()); - ObjectVector[] sValues = - (ObjectVector[]) DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "S") - .getDirect(); + grouped.getDefinition().getColumn("Z").getDataType()); + ObjectVector[] sValues = ColumnVectors.ofObject(grouped, "S", ObjectVector.class).toArray(); TestCase.assertEquals(3, sValues.length); TestCase.assertEquals(1, sValues[0].size()); TestCase.assertEquals(1, sValues[1].size()); @@ -546,120 +550,120 @@ public void testStaticBy() { TestCase.assertEquals("e", sValues[0].get(0)); TestCase.assertEquals("c", sValues[1].get(0)); TestCase.assertEquals("g", sValues[2].get(0)); - TestCase.assertEquals(Arrays.asList(5, 4, 9), - Arrays.asList(DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "Z").get(0, 3))); + Assert.assertArrayEquals(new int[] {5, 4, 9}, + ColumnVectors.ofInt(grouped, "Z").toArray()); table = testRefreshingTable( col("S", "e", "c", "g"), col("X", 4, 2, 6), col("Y", 4, 2, 2)); - TestCase.assertEquals(2, table.updateView("Z=X+Y").groupBy("Z").size()); - TestCase.assertEquals(4, table.updateView("Z=X+Y").groupBy("Z").numColumns()); + grouped = table.updateView("Z=X+Y").groupBy("Z"); + TestCase.assertEquals(2, grouped.size()); + TestCase.assertEquals(4, grouped.numColumns()); TestCase.assertEquals(ObjectVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("S").getDataType()); + grouped.getDefinition().getColumn("S").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("X").getDataType()); + grouped.getDefinition().getColumn("X").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Y").getDataType()); + grouped.getDefinition().getColumn("Y").getDataType()); TestCase.assertEquals(int.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Z").getDataType()); - sValues = (ObjectVector[]) DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "S") - .getDirect(); + grouped.getDefinition().getColumn("Z").getDataType()); + sValues = ColumnVectors.ofObject(grouped, "S", ObjectVector.class).toArray(); TestCase.assertEquals(2, sValues.length); TestCase.assertEquals(2, sValues[0].size()); TestCase.assertEquals(1, sValues[1].size()); TestCase.assertEquals("e", sValues[0].get(0)); TestCase.assertEquals("c", sValues[1].get(0)); TestCase.assertEquals("g", sValues[0].get(1)); - TestCase.assertEquals(Arrays.asList(8, 4), - Arrays.asList(DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "Z").get(0, 2))); + Assert.assertArrayEquals(new int[] {8, 4}, + ColumnVectors.ofInt(grouped, "Z").toArray()); table = testRefreshingTable( col("S", "e", "c", "g"), colIndexed("X", 4, 2, 6), col("Y", 4, 2, 2)); - TestCase.assertEquals(2, table.updateView("Z=X+Y").groupBy("Z").size()); - TestCase.assertEquals(4, table.updateView("Z=X+Y").groupBy("Z").numColumns()); + grouped = table.updateView("Z=X+Y").groupBy("Z"); + TestCase.assertEquals(2, grouped.size()); + TestCase.assertEquals(4, grouped.numColumns()); TestCase.assertEquals(ObjectVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("S").getDataType()); + grouped.getDefinition().getColumn("S").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("X").getDataType()); + grouped.getDefinition().getColumn("X").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Y").getDataType()); + grouped.getDefinition().getColumn("Y").getDataType()); TestCase.assertEquals(int.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Z").getDataType()); - sValues = (ObjectVector[]) DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "S") - .getDirect(); + grouped.getDefinition().getColumn("Z").getDataType()); + sValues = ColumnVectors.ofObject(grouped, "S", ObjectVector.class).toArray(); TestCase.assertEquals(2, sValues.length); TestCase.assertEquals(2, sValues[0].size()); TestCase.assertEquals(1, sValues[1].size()); TestCase.assertEquals("e", sValues[0].get(0)); TestCase.assertEquals("c", sValues[1].get(0)); TestCase.assertEquals("g", sValues[0].get(1)); - TestCase.assertEquals(Arrays.asList(8, 4), - Arrays.asList(DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "Z").get(0, 2))); + Assert.assertArrayEquals(new int[] {8, 4}, + ColumnVectors.ofInt(grouped, "Z").toArray()); table = testRefreshingTable( col("S", "e", "c", "g"), col("X", 4, 2, 6), colIndexed("Y", 4, 2, 2)); - TestCase.assertEquals(2, table.updateView("Z=X+Y").groupBy("Z").size()); - TestCase.assertEquals(4, table.updateView("Z=X+Y").groupBy("Z").numColumns()); + grouped = table.updateView("Z=X+Y").groupBy("Z"); + TestCase.assertEquals(2, grouped.size()); + TestCase.assertEquals(4, grouped.numColumns()); TestCase.assertEquals(ObjectVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("S").getDataType()); + grouped.getDefinition().getColumn("S").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("X").getDataType()); + grouped.getDefinition().getColumn("X").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Y").getDataType()); + grouped.getDefinition().getColumn("Y").getDataType()); TestCase.assertEquals(int.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Z").getDataType()); - sValues = (ObjectVector[]) DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "S") - .getDirect(); + grouped.getDefinition().getColumn("Z").getDataType()); + sValues = ColumnVectors.ofObject(grouped, "S", ObjectVector.class).toArray(); TestCase.assertEquals(2, sValues.length); TestCase.assertEquals(2, sValues[0].size()); TestCase.assertEquals(1, sValues[1].size()); TestCase.assertEquals("e", sValues[0].get(0)); TestCase.assertEquals("c", sValues[1].get(0)); TestCase.assertEquals("g", sValues[0].get(1)); - TestCase.assertEquals(Arrays.asList(8, 4), - Arrays.asList(DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "Z").get(0, 2))); + Assert.assertArrayEquals(new int[] {8, 4}, + ColumnVectors.ofInt(grouped, "Z").toArray()); table = testRefreshingTable( col("S", "e", "c", "g"), colIndexed("X", 4, 2, 6), colIndexed("Y", 4, 3, 2)); - TestCase.assertEquals(2, table.updateView("Z=X+Y").groupBy("Z").size()); - TestCase.assertEquals(4, table.updateView("Z=X+Y").groupBy("Z").numColumns()); + grouped = table.updateView("Z=X+Y").groupBy("Z"); + TestCase.assertEquals(2, grouped.size()); + TestCase.assertEquals(4, grouped.numColumns()); TestCase.assertEquals(ObjectVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("S").getDataType()); + grouped.getDefinition().getColumn("S").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("X").getDataType()); + grouped.getDefinition().getColumn("X").getDataType()); TestCase.assertEquals(IntVector.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Y").getDataType()); + grouped.getDefinition().getColumn("Y").getDataType()); TestCase.assertEquals(int.class, - table.updateView("Z=X+Y").groupBy("Z").getDefinition().getColumn("Z").getDataType()); - sValues = (ObjectVector[]) DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "S") - .getDirect(); + grouped.getDefinition().getColumn("Z").getDataType()); + sValues = ColumnVectors.ofObject(grouped, "S", ObjectVector.class).toArray(); TestCase.assertEquals(2, sValues.length); TestCase.assertEquals(2, sValues[0].size()); TestCase.assertEquals(1, sValues[1].size()); TestCase.assertEquals("e", sValues[0].get(0)); TestCase.assertEquals("c", sValues[1].get(0)); TestCase.assertEquals("g", sValues[0].get(1)); - TestCase.assertEquals(Arrays.asList(8, 5), - Arrays.asList(DataAccessHelpers.getColumn(table.updateView("Z=X+Y").groupBy("Z"), "Z").get(0, 2))); + Assert.assertArrayEquals(new int[] {8, 5}, + ColumnVectors.ofInt(grouped, "Z").toArray()); table = testRefreshingTable( col("S", "c", null, "g"), col("I", 2, 4, 6)); - - TestCase.assertEquals(3, table.groupBy("S").size()); - TestCase.assertEquals(2, table.groupBy("S").numColumns()); - TestCase.assertEquals(String.class, table.groupBy("S").getDefinition().getColumn("S").getDataType()); - TestCase.assertEquals(IntVector.class, table.groupBy("S").getDefinition().getColumn("I").getDataType()); - TestCase.assertEquals(Arrays.asList("c", null, "g"), - Arrays.asList(DataAccessHelpers.getColumn(table.groupBy("S"), "S").get(0, 3))); - intGroups = (IntVector[]) DataAccessHelpers.getColumn(table.groupBy("S"), "I").getDirect(); + grouped = table.groupBy("S"); + TestCase.assertEquals(3, grouped.size()); + TestCase.assertEquals(2, grouped.numColumns()); + TestCase.assertEquals(String.class, grouped.getDefinition().getColumn("S").getDataType()); + TestCase.assertEquals(IntVector.class, grouped.getDefinition().getColumn("I").getDataType()); + Assert.assertArrayEquals(new String[] {"c", null, "g"}, + ColumnVectors.ofObject(grouped, "S", String.class).toArray()); + intGroups = ColumnVectors.ofObject(grouped, "I", IntVector.class).toArray(); TestCase.assertEquals(3, intGroups.length); TestCase.assertEquals(1, intGroups[0].size()); TestCase.assertEquals(1, intGroups[1].size()); @@ -1196,12 +1200,12 @@ public void testApplyToAllBy() { TestCase.assertEquals(result.getDefinition().getColumns().get(1).getName(), "intCol"); TestCase.assertEquals(result.getDefinition().getColumns().get(2).getName(), "doubleCol"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); - TestCase.assertEquals(Arrays.asList(30.0, 20.0), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.3, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); + Assert.assertArrayEquals(new double[] {30.0, 20.0}, + ColumnVectors.ofDouble(result, "intCol").toArray(), DELTA); + Assert.assertArrayEquals(new double[] {0.3, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.sumBy("Sym"); TestCase.assertEquals(3, result.numColumns()); @@ -1209,12 +1213,12 @@ public void testApplyToAllBy() { TestCase.assertEquals(result.getDefinition().getColumns().get(1).getName(), "intCol"); TestCase.assertEquals(result.getDefinition().getColumns().get(2).getName(), "doubleCol"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); - TestCase.assertEquals(Arrays.asList(90L, 20L), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.9, 0.2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); + Assert.assertArrayEquals(new long[] {90L, 20L}, + ColumnVectors.ofLong(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.9, 0.2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.stdBy("Sym"); TestCase.assertEquals(3, result.numColumns()); @@ -1222,112 +1226,112 @@ public void testApplyToAllBy() { TestCase.assertEquals(result.getDefinition().getColumns().get(1).getName(), "intCol"); TestCase.assertEquals(result.getDefinition().getColumns().get(2).getName(), "doubleCol"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); - TestCase.assertEquals(Arrays.asList(20.0, Double.NaN), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.19999999999999996, Double.NaN), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); + Assert.assertArrayEquals(new double[] {20.0, Double.NaN}, + ColumnVectors.ofDouble(result, "intCol").toArray(), DELTA); + Assert.assertArrayEquals(new double[] {0.19999999999999996, Double.NaN}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.minBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(10, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.1, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new int[] {10, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.maxBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(50, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.5, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new int[] {50, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.5, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.varBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(400.0, Double.NaN), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.03999999999999998, Double.NaN), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new double[] {400.0, Double.NaN}, + ColumnVectors.ofDouble(result, "intCol").toArray(), DELTA); + Assert.assertArrayEquals(new double[] {0.03999999999999998, Double.NaN}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.lastBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(50, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(.5, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); + Assert.assertArrayEquals(new int[] {50, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {.5, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); result = table.updateView("Sym1=Sym").lastBy("Sym", "Sym1"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(50, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(.5, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); + Assert.assertArrayEquals(new int[] {50, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {.5, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); result = table.updateView("Sym1=Sym").lastBy("intCol", "Sym1"); TestCase.assertEquals(result.size(), 4); - TestCase.assertEquals(Arrays.asList(10, 20, 30, 50), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 4))); - TestCase.assertEquals(Arrays.asList(0.1, 0.2, 0.3, 0.5), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 4))); - TestCase.assertEquals(Arrays.asList("aa", "bc", "aa", "aa"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 4))); - TestCase.assertEquals(Arrays.asList("aa", "bc", "aa", "aa"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym1").get(0, 4))); + Assert.assertArrayEquals(new int[] {10, 20, 30, 50}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, 0.2, 0.3, 0.5}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc", "aa", "aa"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); + Assert.assertArrayEquals(new String[] {"aa", "bc", "aa", "aa"}, + ColumnVectors.ofObject(result, "Sym1", String.class).toArray()); result = table.firstBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(10, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.1, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new int[] {10, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); result = table.updateView("Sym1=Sym").firstBy("Sym", "Sym1"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(10, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.1, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); + Assert.assertArrayEquals(new int[] {10, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); result = table.updateView("Sym1=Sym").firstBy("intCol", "Sym1"); TestCase.assertEquals(result.size(), 4); - TestCase.assertEquals(Arrays.asList(10, 20, 30, 50), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 4))); - TestCase.assertEquals(Arrays.asList(0.1, 0.2, 0.3, 0.5), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 4))); - TestCase.assertEquals(Arrays.asList("aa", "bc", "aa", "aa"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 4))); - TestCase.assertEquals(Arrays.asList("aa", "bc", "aa", "aa"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym1").get(0, 4))); + Assert.assertArrayEquals(new int[] {10, 20, 30, 50}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, 0.2, 0.3, 0.5}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc", "aa", "aa"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); + Assert.assertArrayEquals(new String[] {"aa", "bc", "aa", "aa"}, + ColumnVectors.ofObject(result, "Sym1", String.class).toArray()); result = table.view("intCol").avgBy(); TestCase.assertEquals(result.size(), 1); TestCase.assertEquals(1, result.numColumns()); TestCase.assertEquals(result.getDefinition().getColumns().get(0).getName(), "intCol"); - TestCase.assertEquals(Collections.singletonList(27.5), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 1))); + Assert.assertArrayEquals(new double[] {27.5}, + ColumnVectors.ofDouble(result, "intCol").toArray(), DELTA); result = table.lastBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(50, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(.5, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList("aa", "bc"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Sym").get(0, 2))); + Assert.assertArrayEquals(new int[] {50, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {.5, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); + Assert.assertArrayEquals(new String[] {"aa", "bc"}, + ColumnVectors.ofObject(result, "Sym", String.class).toArray()); result = table.firstBy("Sym"); TestCase.assertEquals(result.size(), 2); - TestCase.assertEquals(Arrays.asList(10, 20), - Arrays.asList(DataAccessHelpers.getColumn(result, "intCol").get(0, 2))); - TestCase.assertEquals(Arrays.asList(0.1, .2), - Arrays.asList(DataAccessHelpers.getColumn(result, "doubleCol").get(0, 2))); + Assert.assertArrayEquals(new int[] {10, 20}, + ColumnVectors.ofInt(result, "intCol").toArray()); + Assert.assertArrayEquals(new double[] {0.1, .2}, + ColumnVectors.ofDouble(result, "doubleCol").toArray(), DELTA); } @@ -1745,12 +1749,14 @@ public void testAbsSumBySimple() { final Table result = table.absSumBy(); TableTools.show(result); TestCase.assertEquals(1, result.size()); - BigInteger absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - double absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); + BigInteger absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + double absSumDouble = + result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); BigInteger expected = BigInteger.valueOf(6); TestCase.assertEquals(expected, absSum); TestCase.assertEquals(expected.doubleValue(), absSumDouble); - TestCase.assertEquals(NULL_LONG, DataAccessHelpers.getColumn(result, "BoolCol").getLong(0)); + TestCase.assertEquals(NULL_LONG, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -1759,9 +1765,10 @@ public void testAbsSumBySimple() { table.notifyListeners(i(8), i(), i()); }); show(result); - absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); - TestCase.assertEquals(1L, DataAccessHelpers.getColumn(result, "BoolCol").get(0)); + absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + absSumDouble = result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); + TestCase.assertEquals(1L, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); expected = BigInteger.valueOf(11); TestCase.assertEquals(expected, absSum); @@ -1772,8 +1779,8 @@ public void testAbsSumBySimple() { table.notifyListeners(i(), i(2), i()); }); show(result); - absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); + absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + absSumDouble = result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); expected = BigInteger.valueOf(10); TestCase.assertEquals(expected, absSum); @@ -1785,9 +1792,10 @@ public void testAbsSumBySimple() { table.notifyListeners(i(), i(), i(8)); }); show(result); - absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); - TestCase.assertEquals(0L, DataAccessHelpers.getColumn(result, "BoolCol").get(0)); + absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + absSumDouble = result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); + TestCase.assertEquals(0L, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); expected = BigInteger.valueOf(9); TestCase.assertEquals(expected, absSum); @@ -1799,24 +1807,26 @@ public void testAbsSumBySimple() { table.notifyListeners(i(10), i(), i()); }); show(result); - absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); + absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + absSumDouble = result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(expected, absSum); TestCase.assertEquals(Double.NaN, absSumDouble); - TestCase.assertEquals(1L, DataAccessHelpers.getColumn(result, "BoolCol").getLong(0)); + TestCase.assertEquals(1L, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); updateGraph.runWithinUnitTestCycle(() -> { removeRows(table, i(10)); table.notifyListeners(i(), i(10), i()); }); show(result); - absSum = (BigInteger) DataAccessHelpers.getColumn(result, "BigI").get(0); - absSumDouble = DataAccessHelpers.getColumn(result, "DoubleCol").getDouble(0); + absSum = result.getColumnSource("BigI", BigInteger.class).get(result.getRowSet().firstRowKey()); + absSumDouble = result.getColumnSource("DoubleCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(expected, absSum); TestCase.assertEquals(expected.doubleValue(), absSumDouble); - TestCase.assertEquals(0L, DataAccessHelpers.getColumn(result, "BoolCol").getLong(0)); + TestCase.assertEquals(0L, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); updateGraph.runWithinUnitTestCycle(() -> { addToTable(table, i(12, 14), col("BigI", BigInteger.valueOf(0), BigInteger.valueOf(0)), @@ -1824,7 +1834,8 @@ public void testAbsSumBySimple() { table.notifyListeners(i(12, 14), i(), i()); }); show(result); - TestCase.assertEquals(2L, DataAccessHelpers.getColumn(result, "BoolCol").getLong(0)); + TestCase.assertEquals(2L, + result.getColumnSource("BoolCol", long.class).getLong(result.getRowSet().firstRowKey())); } @Test @@ -1836,9 +1847,9 @@ public void testAbsSumByNull() { final Table result = table.absSumBy(); TableTools.show(result); TestCase.assertEquals(1, result.size()); - long absSum = DataAccessHelpers.getColumn(result, "IntCol").getLong(0); + long absSum = result.getColumnSource("IntCol", long.class).getLong(result.getRowSet().firstRowKey()); TestCase.assertEquals(NULL_LONG, absSum); - float absSumF = DataAccessHelpers.getColumn(result, "FloatCol").getFloat(0); + float absSumF = result.getColumnSource("FloatCol", float.class).getFloat(result.getRowSet().firstRowKey()); TestCase.assertEquals(QueryConstants.NULL_FLOAT, absSumF); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -1847,8 +1858,8 @@ public void testAbsSumByNull() { table.notifyListeners(i(8), i(), i()); }); show(result); - absSum = DataAccessHelpers.getColumn(result, "IntCol").getLong(0); - absSumF = DataAccessHelpers.getColumn(result, "FloatCol").getFloat(0); + absSum = result.getColumnSource("IntCol", long.class).getLong(result.getRowSet().firstRowKey()); + absSumF = result.getColumnSource("FloatCol", float.class).getFloat(result.getRowSet().firstRowKey()); TestCase.assertEquals(5L, absSum); TestCase.assertEquals(5.5f, absSumF); @@ -1857,8 +1868,8 @@ public void testAbsSumByNull() { table.notifyListeners(i(), i(8), i()); }); show(result); - absSum = DataAccessHelpers.getColumn(result, "IntCol").getLong(0); - absSumF = DataAccessHelpers.getColumn(result, "FloatCol").getFloat(0); + absSum = result.getColumnSource("IntCol", long.class).getLong(result.getRowSet().firstRowKey()); + absSumF = result.getColumnSource("FloatCol", float.class).getFloat(result.getRowSet().firstRowKey()); TestCase.assertEquals(NULL_LONG, absSum); TestCase.assertEquals(QueryConstants.NULL_FLOAT, absSumF); } @@ -1873,9 +1884,9 @@ public void testAvgInfinities() { TableTools.show(result); TableTools.show(result.meta()); TestCase.assertEquals(1, result.size()); - double avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); + double avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(Double.NaN, avg); - double avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + double avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(Double.NaN, avgF); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -1884,8 +1895,8 @@ public void testAvgInfinities() { table.notifyListeners(i(8), i(), i()); }); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(5.0, avg); TestCase.assertEquals(5.0, avgF); @@ -1894,8 +1905,8 @@ public void testAvgInfinities() { table.notifyListeners(i(9), i(), i()); }); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(5.5, avg); TestCase.assertEquals(Double.POSITIVE_INFINITY, avgF); @@ -1904,8 +1915,8 @@ public void testAvgInfinities() { table.notifyListeners(i(10), i(), i()); }); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(6.0, avg); TestCase.assertEquals(Double.NaN, avgF); @@ -1914,8 +1925,8 @@ public void testAvgInfinities() { table.notifyListeners(i(), i(9), i()); }); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(6.0, avg); TestCase.assertEquals(Double.NEGATIVE_INFINITY, avgF); @@ -1925,8 +1936,8 @@ public void testAvgInfinities() { table.notifyListeners(i(11), i(10), i()); }); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(5.5, avg); TestCase.assertEquals(Double.NaN, avgF); @@ -1936,8 +1947,8 @@ public void testAvgInfinities() { }); show(table); show(result); - avg = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - avgF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + avg = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + avgF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(5.0, avg); TestCase.assertEquals(5.0, avgF); } @@ -1952,9 +1963,9 @@ public void testVarInfinities() { TableTools.show(result); TableTools.show(result.meta()); TestCase.assertEquals(1, result.size()); - double var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); + double var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(Double.NaN, var); - double varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + double varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(Double.NaN, varF); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -1963,8 +1974,8 @@ public void testVarInfinities() { table.notifyListeners(i(7, 8), i(), i()); }); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(0.5, var); TestCase.assertEquals(0.5, varF); @@ -1973,8 +1984,8 @@ public void testVarInfinities() { table.notifyListeners(i(9), i(), i()); }); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(1.0, var); TestCase.assertEquals(Double.NaN, varF); @@ -1983,8 +1994,8 @@ public void testVarInfinities() { table.notifyListeners(i(10), i(), i()); }); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(1.0 + 2.0 / 3.0, var, 0.001); TestCase.assertEquals(Double.NaN, varF); @@ -1993,8 +2004,8 @@ public void testVarInfinities() { table.notifyListeners(i(), i(9), i()); }); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(2.0 + 1.0 / 3.0, var, 0.001); TestCase.assertEquals(Double.NaN, varF); @@ -2004,8 +2015,8 @@ public void testVarInfinities() { table.notifyListeners(i(11), i(10), i()); }); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(1.0, var); TestCase.assertEquals(Double.NaN, varF); @@ -2015,8 +2026,8 @@ public void testVarInfinities() { }); show(table); show(result); - var = DataAccessHelpers.getColumn(result, "IntCol").getDouble(0); - varF = DataAccessHelpers.getColumn(result, "FloatCol").getDouble(0); + var = result.getColumnSource("IntCol", double.class).getDouble(result.getRowSet().firstRowKey()); + varF = result.getColumnSource("FloatCol", double.class).getDouble(result.getRowSet().firstRowKey()); TestCase.assertEquals(0.5, var); TestCase.assertEquals(0.5, varF); } @@ -2157,7 +2168,7 @@ public void testWeightedAvgByLong() { final Table result = table.wavgBy("Long2"); TableTools.show(result); TestCase.assertEquals(1, result.size()); - double wavg = DataAccessHelpers.getColumn(result, "Long1").getDouble(0); + double wavg = result.getColumnSource("Long1", double.class).getDouble(result.getRowSet().firstRowKey()); long wsum = 2 + 8 + 18; long sumw = 6; double expected = (double) wsum / (double) sumw; @@ -2169,7 +2180,7 @@ public void testWeightedAvgByLong() { table.notifyListeners(i(8), i(), i()); }); show(result); - wavg = DataAccessHelpers.getColumn(result, "Long1").getDouble(0); + wavg = result.getColumnSource("Long1", double.class).getDouble(result.getRowSet().firstRowKey()); wsum = wsum + (7L * (long) Integer.MAX_VALUE); sumw = sumw + (7L); @@ -2700,8 +2711,10 @@ public void testTDigestAccumulation() { .update("P95=Digest.quantile(0.95)"); TableTools.show(accumulated); - final double singleValue = DataAccessHelpers.getColumn(aggregated, "P95").getDouble(0); - final double accumulatedValue = DataAccessHelpers.getColumn(accumulated, "P95").getDouble(0); + final double singleValue = + aggregated.getColumnSource("P95", double.class).getDouble(aggregated.getRowSet().firstRowKey()); + final double accumulatedValue = + accumulated.getColumnSource("P95", double.class).getDouble(accumulated.getRowSet().firstRowKey()); final double error = Math.abs(singleValue - accumulatedValue) / singleValue; if (error > 0.002) { System.err.println("Single Value: " + singleValue); @@ -2711,67 +2724,75 @@ public void testTDigestAccumulation() { } private void checkTableP99(Table queryTable, Table aggregated) { - final double[] dValues = (double[]) DataAccessHelpers - .getColumn(queryTable.where("!Double.isNaN(doubleCol) && !isNull(doubleCol)"), "doubleCol").getDirect(); + Table table = queryTable.where("!Double.isNaN(doubleCol) && !isNull(doubleCol)"); + final double[] dValues = ColumnVectors.ofDouble(table, "doubleCol").toArray(); Arrays.sort(dValues); final double dValue = dValues[(dValues.length * 99) / 100]; - final double dtValue = DataAccessHelpers.getColumn(aggregated, "doubleCol").getDouble(0); + final double dtValue = + aggregated.getColumnSource("doubleCol", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double derror = Math.abs((dValue - dtValue) / dValue); System.out.println("Double: " + dValue + ", " + dtValue + ", Error: " + derror); checkTDigestError(derror); - final float[] fValues = (float[]) DataAccessHelpers - .getColumn(queryTable.where("!Float.isNaN(floatCol) && !isNull(floatCol)"), "floatCol").getDirect(); + table = queryTable.where("!Float.isNaN(floatCol) && !isNull(floatCol)"); + final float[] fValues = ColumnVectors.ofFloat(table, "floatCol").toArray(); Arrays.sort(fValues); final float fValue = fValues[(fValues.length * 99) / 100]; - final double ftValue = DataAccessHelpers.getColumn(aggregated, "floatCol").getDouble(0); + final double ftValue = + aggregated.getColumnSource("floatCol", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double ferror = Math.abs((fValue - ftValue) / fValue); System.out.println("Float: " + fValue + ", " + ftValue + ", Error: " + ferror); checkTDigestError(ferror); - final int[] iValues = - (int[]) DataAccessHelpers.getColumn(queryTable.where("!isNull(intCol)"), "intCol").getDirect(); + table = queryTable.where("!isNull(intCol)"); + final int[] iValues = ColumnVectors.ofInt(table, "intCol").toArray(); Arrays.sort(iValues); final float iValue = iValues[(iValues.length * 99) / 100]; - final double itValue = DataAccessHelpers.getColumn(aggregated, "intCol").getDouble(0); + final double itValue = + aggregated.getColumnSource("intCol", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double ierror = Math.abs((iValue - itValue) / iValue); System.out.println("Int: " + iValue + ", " + itValue + ", Error: " + ierror); checkTDigestError(ferror); } private void checkTableComboPercentiles(Table queryTable, Table aggregated, RMSE rmse) { - final double[] dValues = (double[]) DataAccessHelpers - .getColumn(queryTable.where("!Double.isNaN(doubleCol) && !isNull(doubleCol)"), "doubleCol").getDirect(); + Table table = queryTable.where("!Double.isNaN(doubleCol) && !isNull(doubleCol)"); + final double[] dValues = ColumnVectors.ofDouble(table, "doubleCol").toArray(); Arrays.sort(dValues); final double dValue75 = dValues[(dValues.length * 75) / 100]; - final double dtValue75 = DataAccessHelpers.getColumn(aggregated, "DP75").getDouble(0); + final double dtValue75 = + aggregated.getColumnSource("DP75", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double derror75 = Math.abs((dValue75 - dtValue75) / dValue75); System.out.println("Double 75: " + dValue75 + ", " + dtValue75 + ", Error: " + derror75); checkTDigestError(derror75); final double dValue99 = dValues[(dValues.length * 99) / 100]; - final double dtValue99 = DataAccessHelpers.getColumn(aggregated, "DP99").getDouble(0); + final double dtValue99 = + aggregated.getColumnSource("DP99", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double derror99 = Math.abs((dValue99 - dtValue99) / dValue99); System.out.println("Double 99: " + dValue99 + ", " + dtValue99 + ", Error: " + derror99); checkTDigestError(derror99); final double dValue999 = dValues[(dValues.length * 999) / 1000]; - final double dtValue999 = DataAccessHelpers.getColumn(aggregated, "DP999").getDouble(0); + final double dtValue999 = + aggregated.getColumnSource("DP999", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double derror999 = Math.abs((dValue999 - dtValue999) / dValue999); System.out.println("Double 99.9: " + dValue999 + ", " + dtValue999 + ", Error: " + derror999); checkTDigestError(derror999); - final float[] fValues = (float[]) DataAccessHelpers - .getColumn(queryTable.where("!Float.isNaN(floatCol) && !isNull(floatCol)"), "floatCol").getDirect(); + table = queryTable.where("!Float.isNaN(floatCol) && !isNull(floatCol)"); + final float[] fValues = ColumnVectors.ofFloat(table, "floatCol").toArray(); Arrays.sort(fValues); final float fValue75 = fValues[(fValues.length * 75) / 100]; - final double ftValue75 = DataAccessHelpers.getColumn(aggregated, "FP75").getDouble(0); + final double ftValue75 = + aggregated.getColumnSource("FP75", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double ferror75 = Math.abs((fValue75 - ftValue75) / fValue75); System.out.println("Float 75: " + fValue75 + ", " + ftValue75 + ", Error: " + ferror75); checkTDigestError(ferror75); final float fValue99 = fValues[(fValues.length * 99) / 100]; - final double ftValue99 = DataAccessHelpers.getColumn(aggregated, "FP99").getDouble(0); + final double ftValue99 = + aggregated.getColumnSource("FP99", double.class).getDouble(aggregated.getRowSet().firstRowKey()); final double ferror99 = Math.abs((fValue99 - ftValue99) / fValue99); System.out.println("Float 99: " + fValue99 + ", " + ftValue99 + ", Error: " + ferror99); checkTDigestError(ferror99); @@ -2956,9 +2977,9 @@ public void testMedianTypes() { for (final Map.Entry check : expectedResults.entrySet()) { final String key = check.getKey(); final Object[] expectValues = check.getValue(); - final Object medianValue = DataAccessHelpers.getColumn(median, key).get(0); - final Object p10Value = DataAccessHelpers.getColumn(percentile10, key).get(0); - final Object p90Value = DataAccessHelpers.getColumn(percentile90, key).get(0); + final Object medianValue = median.getColumnSource(key).get(median.getRowSet().firstRowKey()); + final Object p10Value = percentile10.getColumnSource(key).get(percentile10.getRowSet().firstRowKey()); + final Object p90Value = percentile90.getColumnSource(key).get(percentile90.getRowSet().firstRowKey()); TestCase.assertEquals(key + " P10", expectValues[0], p10Value); TestCase.assertEquals(key + " median", expectValues[1], medianValue); TestCase.assertEquals(key + " P90", expectValues[2], p90Value); @@ -2980,8 +3001,9 @@ public void testMedianTypes() { for (final Map.Entry check : expectedResults.entrySet()) { final String key = check.getKey(); final Object[] expectValues = check.getValue(); - final Object medianValue = DataAccessHelpers.getColumn(refreshing, key).get(0); - final Object medianKeyValue = DataAccessHelpers.getColumn(refreshingKeys, key).get(0); + final Object medianValue = refreshing.getColumnSource(key).get(refreshing.getRowSet().firstRowKey()); + final Object medianKeyValue = + refreshingKeys.getColumnSource(key).get(refreshingKeys.getRowSet().firstRowKey()); TestCase.assertEquals(key + " median", expectValues[1], medianValue); TestCase.assertEquals(key + " median", expectValues[1], medianKeyValue); } @@ -3004,56 +3026,64 @@ public void testCountBy() { } Table table = newTable(); - TestCase.assertEquals(0, table.countBy("count").size()); - TestCase.assertEquals(1, table.countBy("count").numColumns()); + Table count = table.countBy("count"); + TestCase.assertEquals(0, count.size()); + TestCase.assertEquals(1, count.numColumns()); + table = emptyTable(10); - TestCase.assertEquals(1, table.countBy("count").size()); - TestCase.assertEquals(10, DataAccessHelpers.getColumn(table.countBy("count"), "count").getLong(0)); - TestCase.assertEquals(1, table.countBy("count").numColumns()); + count = table.countBy("count"); + TestCase.assertEquals(1, count.size()); + TestCase.assertEquals(10, count.getColumnSource("count", long.class).getLong(count.getRowSet().firstRowKey())); + TestCase.assertEquals(1, count.numColumns()); table = newTable(col("x", 1, 2, 3)); - TestCase.assertEquals(1, table.countBy("count").size()); - TestCase.assertEquals(3, DataAccessHelpers.getColumn(table.countBy("count"), "count").getLong(0)); - TestCase.assertEquals(1, table.countBy("count").numColumns()); + count = table.countBy("count"); + TestCase.assertEquals(1, count.size()); + TestCase.assertEquals(3, count.getColumnSource("count", long.class).getLong(count.getRowSet().firstRowKey())); + TestCase.assertEquals(1, count.numColumns()); table = newTable(col("x", 1, 2, 3)); - TestCase.assertEquals(3, table.countBy("count", "x").size()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x"), "x").get(0, 3))); - TestCase.assertEquals(Arrays.asList(1L, 1L, 1L), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x"), "count").get(0, 3))); - TestCase.assertEquals(2, table.countBy("count", "x").numColumns()); + count = table.countBy("count", "x"); + TestCase.assertEquals(3, count.size()); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(count, "x").toArray()); + Assert.assertArrayEquals(new long[] {1L, 1L, 1L}, + ColumnVectors.ofLong(count, "count").toArray()); + TestCase.assertEquals(2, count.numColumns()); try { - show(table.countBy("count", "x")); + show(count); } catch (Exception e) { e.printStackTrace(); } + table = newTable(col("x", 1, 2, 2, 2, 3, 3), col("y", 1, 2, 2, 2, 3, 3)); + count = table.countBy("count", "x", "y"); try { - show(table.countBy("count", "x", "y")); + show(count); } catch (Exception e) { e.printStackTrace(); } - TestCase.assertEquals(3, table.countBy("count", "x", "y").size()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "x").get(0, 3))); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "y").get(0, 3))); - TestCase.assertEquals(Arrays.asList(1L, 3L, 2L), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "count").get(0, 3))); - TestCase.assertEquals(3, table.countBy("count", "x", "y").numColumns()); + TestCase.assertEquals(3, count.size()); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(count, "x").toArray()); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(count, "y").toArray()); + Assert.assertArrayEquals(new long[] {1L, 3L, 2L}, + ColumnVectors.ofLong(count, "count").toArray()); + TestCase.assertEquals(3, count.numColumns()); table = newTable(col("x", 1, 2, 3), col("y", 1, 2, 3)); - TestCase.assertEquals(3, table.countBy("count", "x", "y").size()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "x").get(0, 3))); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "y").get(0, 3))); - TestCase.assertEquals(Arrays.asList(1L, 1L, 1L), - Arrays.asList(DataAccessHelpers.getColumn(table.countBy("count", "x", "y"), "count").get(0, 3))); - TestCase.assertEquals(3, table.countBy("count", "x", "y").numColumns()); + count = table.countBy("count", "x", "y"); + TestCase.assertEquals(3, count.size()); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(count, "x").toArray()); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(count, "y").toArray()); + Assert.assertArrayEquals(new long[] {1L, 1L, 1L}, + ColumnVectors.ofLong(count, "count").toArray()); + TestCase.assertEquals(3, count.numColumns()); try { - show(table.countBy("count", "x", "y")); + show(count); } catch (Exception e) { e.printStackTrace(); } @@ -3071,38 +3101,38 @@ public void testSelectDistinct() { Table result = table.selectDistinct("x"); TestCase.assertEquals(3, result.size()); - TestCase.assertEquals(3, DataAccessHelpers.getColumn(result, "x").size()); + TestCase.assertEquals(3, ColumnVectors.of(result, "x").size()); TestCase.assertEquals(1, result.numColumns()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(result, "x").get(0, 3))); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(result, "x").toArray()); table = newTable(col("x", 1, 2, 2, 2, 3, 3), col("y", 1, 2, 2, 3, 3, 3)); System.out.println("Table:"); show(table); result = table.selectDistinct("x"); TestCase.assertEquals(3, result.size()); - TestCase.assertEquals(3, DataAccessHelpers.getColumn(result, "x").size()); + TestCase.assertEquals(3, ColumnVectors.of(result, "x").size()); TestCase.assertEquals(1, result.numColumns()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(result, "x").get(0, 3))); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(result, "x").toArray()); result = table.selectDistinct("y"); TestCase.assertEquals(3, result.size()); - TestCase.assertEquals(3, DataAccessHelpers.getColumn(result, "y").size()); + TestCase.assertEquals(3, ColumnVectors.of(result, "y").size()); TestCase.assertEquals(1, result.numColumns()); - TestCase.assertEquals(Arrays.asList(1, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(result, "y").get(0, 3))); + Assert.assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(result, "y").toArray()); result = table.selectDistinct("x", "y"); show(result); TestCase.assertEquals(4, result.size()); - TestCase.assertEquals(4, DataAccessHelpers.getColumn(result, "x").size()); - TestCase.assertEquals(4, DataAccessHelpers.getColumn(result, "y").size()); + TestCase.assertEquals(4, ColumnVectors.of(result, "x").size()); + TestCase.assertEquals(4, ColumnVectors.of(result, "y").size()); TestCase.assertEquals(2, result.numColumns()); - TestCase.assertEquals(Arrays.asList(1, 2, 2, 3), - Arrays.asList(DataAccessHelpers.getColumn(result, "x").get(0, 4))); - TestCase.assertEquals(Arrays.asList(1, 2, 3, 3), - Arrays.asList(DataAccessHelpers.getColumn(result, "y").get(0, 4))); + Assert.assertArrayEquals(new int[] {1, 2, 2, 3}, + ColumnVectors.ofInt(result, "x").toArray()); + Assert.assertArrayEquals(new int[] {1, 2, 3, 3}, + ColumnVectors.ofInt(result, "y").toArray()); } private static class SelectDistinctEvalNugget implements EvalNuggetInterface { @@ -3388,11 +3418,15 @@ public void testFirstByShift() { TestCase.assertEquals(2, firstResult.size()); TestCase.assertEquals(2, lastResult.size()); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(1)); + TestCase.assertEquals(1, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(1))); - TestCase.assertEquals(4097, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(1)); + TestCase.assertEquals(4097, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(1))); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -3404,13 +3438,19 @@ public void testFirstByShift() { TableTools.showWithRowSet(firstResult); TableTools.showWithRowSet(lastResult); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(1)); - TestCase.assertEquals(0, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(2)); + TestCase.assertEquals(1, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(1))); + TestCase.assertEquals(0, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(2))); - TestCase.assertEquals(4097, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(1)); - TestCase.assertEquals(0, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(2)); + TestCase.assertEquals(4097, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(1))); + TestCase.assertEquals(0, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(2))); updateGraph.runWithinUnitTestCycle(() -> { for (int idx = 3; idx < 4097; ++idx) { @@ -3423,13 +3463,19 @@ public void testFirstByShift() { TableTools.showWithRowSet(firstResult); TableTools.showWithRowSet(lastResult); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(1)); - TestCase.assertEquals(0, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(2)); + TestCase.assertEquals(1, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(1))); + TestCase.assertEquals(0, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(2))); - TestCase.assertEquals(4097, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(1)); - TestCase.assertEquals(4096, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(2)); + TestCase.assertEquals(4097, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(1))); + TestCase.assertEquals(4096, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(2))); updateGraph.runWithinUnitTestCycle(() -> { ((TestColumnSource) table.getColumnSource("Sentinel")).shift(0, 4097, 4096); @@ -3454,13 +3500,19 @@ public void testFirstByShift() { System.out.println("Last"); TableTools.showWithRowSet(lastResult); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(1)); - TestCase.assertEquals(0, DataAccessHelpers.getColumn(firstResult, "Sentinel").getInt(2)); + TestCase.assertEquals(1, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(1))); + TestCase.assertEquals(0, + firstResult.getColumnSource("Sentinel", int.class).getInt(firstResult.getRowSet().get(2))); - TestCase.assertEquals(4097, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(1)); - TestCase.assertEquals(4096, DataAccessHelpers.getColumn(lastResult, "Sentinel").getInt(2)); + TestCase.assertEquals(4097, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().firstRowKey())); + TestCase.assertEquals(2, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(1))); + TestCase.assertEquals(4096, + lastResult.getColumnSource("Sentinel", int.class).getInt(lastResult.getRowSet().get(2))); } @Test @@ -3700,7 +3752,8 @@ public void testIds6332() { new BigInteger("100"), new BigInteger("100"), BigInteger.valueOf(200))); final Table percentile = source.aggAllBy(percentile(0.25)); TableTools.show(percentile); - TestCase.assertEquals(BigInteger.valueOf(100), DataAccessHelpers.getColumn(percentile, "Value").get(0)); + TestCase.assertEquals(BigInteger.valueOf(100), + percentile.getColumnSource("Value").get(percentile.getRowSet().firstRowKey())); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -3710,7 +3763,8 @@ public void testIds6332() { }); TableTools.show(percentile); - TestCase.assertEquals(BigInteger.valueOf(100), DataAccessHelpers.getColumn(percentile, "Value").get(0)); + TestCase.assertEquals(BigInteger.valueOf(100), + percentile.getColumnSource("Value").get(percentile.getRowSet().firstRowKey())); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAjTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAjTest.java index a113c85e234..0da82cfe4f3 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAjTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAjTest.java @@ -11,6 +11,7 @@ import io.deephaven.engine.primitive.iterator.CloseableIterator; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.impl.indexer.DataIndexer; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; @@ -1430,11 +1431,13 @@ private void checkAjResult(Table leftTable, Table rightTable, Table result, bool final TIntArrayList expectedStamp = new TIntArrayList(); final TIntArrayList expectedSentinel = new TIntArrayList(); - final int[] leftStampArray = (int[]) DataAccessHelpers.getColumn(leftTable, "LeftStamp").getDirect(); - final int[] rightStampArray = rightTable == null ? CollectionUtil.ZERO_LENGTH_INT_ARRAY - : (int[]) DataAccessHelpers.getColumn(rightTable, "RightStamp").getDirect(); - final int[] rightSentinelArray = rightTable == null ? CollectionUtil.ZERO_LENGTH_INT_ARRAY - : (int[]) DataAccessHelpers.getColumn(rightTable, "RightSentinel").getDirect(); + final int[] leftStampArray = ColumnVectors.ofInt(leftTable, "LeftStamp").toArray(); + final int[] rightStampArray = rightTable == null + ? CollectionUtil.ZERO_LENGTH_INT_ARRAY + : ColumnVectors.ofInt(rightTable, "RightStamp").toArray(); + final int[] rightSentinelArray = rightTable == null + ? CollectionUtil.ZERO_LENGTH_INT_ARRAY + : ColumnVectors.ofInt(rightTable, "RightSentinel").toArray(); for (final int leftStamp : leftStampArray) { final int rightPosition = Arrays.binarySearch(rightStampArray, leftStamp); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java index d975556ea9c..4ae42ce7518 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java @@ -6,6 +6,7 @@ import io.deephaven.datastructures.util.CollectionUtil; import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.IntGenerator; import io.deephaven.engine.testutil.generator.SetGenerator; @@ -17,16 +18,13 @@ import io.deephaven.vector.ObjectVector; import io.deephaven.vector.DoubleVector; import io.deephaven.engine.context.QueryScope; -import io.deephaven.util.type.ArrayTypeUtils; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.util.QueryConstants; import io.deephaven.engine.util.TableTools; -import java.text.ParseException; import java.time.Instant; import java.time.ZoneId; -import java.util.Arrays; import java.util.Random; import org.jetbrains.annotations.NotNull; @@ -38,16 +36,20 @@ import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.printTableUpdates; import static io.deephaven.engine.util.TableTools.*; import static io.deephaven.engine.testutil.TstUtils.*; +import static io.deephaven.util.QueryConstants.NULL_INT; import static java.util.Arrays.asList; import static org.junit.Assert.*; @Category(OutOfBandTest.class) public class QueryTableJoinTest { + + private static final double DELTA = 0.000001; + @Rule public final EngineCleanup base = new EngineCleanup(); @Test - public void testAjIncremental() throws ParseException { + public void testAjIncremental() { final int maxSteps = 10; final int[] leftSizes = new int[] {10, 20}; final int[] rightSizes = new int[] {10, 20}; @@ -357,7 +359,7 @@ public void testAj() { col("OptionBid", .1, .2, .3, .4, .5)); Table result = table.aj(lookUpValue1, "Ticker,Timestamp", "OptionBid"); - assertEquals(Arrays.asList("Ticker", "Timestamp", "OptionBid"), result.getDefinition().getColumnNames()); + assertEquals(asList("Ticker", "Timestamp", "OptionBid"), result.getDefinition().getColumnNames()); table = testRefreshingTable( col("Timestamp", 1L, 10L, 50L)); @@ -379,10 +381,10 @@ public void testAj() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); - assertEquals(asList(null, null, "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("a", "b", "c"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(null, null, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {null, null, "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, NULL_INT, 2}, ColumnVectors.ofInt(result, "Int").toArray()); result = lookUpValue1.aj(table, "indx>=String", "Int,String"); @@ -398,10 +400,10 @@ public void testAj() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("c", "c", "e"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("c", "d", "e"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(2, 2, 4), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"c", "c", "e"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"c", "d", "e"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {2, 2, 4}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "h", "e", "a")); result = lookUpValue1.aj(table, "indx>=String", "String,Int"); @@ -410,10 +412,10 @@ public void testAj() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("g", "e", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("h", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(6, 4, null), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"g", "e", null}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {6, 4, NULL_INT}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "h", "e", "a")); @@ -422,9 +424,9 @@ public void testAj() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals(2, result.numColumns()); - assertEquals(asList("g", "e", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("h", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); + assertArrayEquals(new String[] {"g", "e", null}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); lookUpValue1 = testRefreshingTable(col("String", "h", "e", "a")); result = lookUpValue1.aj(table, "String", "xString=String,Int"); @@ -433,11 +435,11 @@ public void testAj() { assertEquals("xString", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("g", "e", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "xString").getDirect())); - assertEquals(asList("h", "e", "a"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList(6, 4, null), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"g", "e", null}, + ColumnVectors.ofObject(result, "xString", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new int[] {6, 4, NULL_INT}, ColumnVectors.ofInt(result, "Int").toArray()); } @@ -452,12 +454,12 @@ public void testAjLt() { col("OptionBid", .1, .2, .3, .4, .5)); Table result = table.aj(lookUpValue1.renameColumns("TS2=Timestamp"), "Ticker,Timestamp>TS2", "OptionBid"); - assertEquals(Arrays.asList("Ticker", "Timestamp", "TS2", "OptionBid"), result.getDefinition().getColumnNames()); - final long[] timestamps = DataAccessHelpers.getColumn(result, "TS2").getLongs(0, result.size()); + assertEquals(asList("Ticker", "Timestamp", "TS2", "OptionBid"), result.getDefinition().getColumnNames()); + final long[] timestamps = ColumnVectors.ofLong(result, "TS2").toArray(); TableTools.show(result); assertArrayEquals(new long[] {QueryConstants.NULL_LONG, 5L, 10L}, timestamps); assertArrayEquals(new double[] {QueryConstants.NULL_DOUBLE, .2, .3}, - DataAccessHelpers.getColumn(result, "OptionBid").getDoubles(0, result.size()), 0.0); + ColumnVectors.ofDouble(result, "OptionBid").toArray(), 0.0); table = testRefreshingTable( col("Timestamp", 1L, 10L, 50L)); @@ -468,9 +470,9 @@ public void testAjLt() { assertEquals(long.class, result.getDefinition().getColumn("OptionTimestamp").getDataType()); TableTools.show(result); assertArrayEquals(new long[] {QueryConstants.NULL_LONG, 5L, 25L}, - DataAccessHelpers.getColumn(result, "OptionTimestamp").getLongs(0, result.size())); + ColumnVectors.ofLong(result, "OptionTimestamp").toArray()); assertArrayEquals(new double[] {QueryConstants.NULL_DOUBLE, .2, .4}, - DataAccessHelpers.getColumn(result, "OptionBid").getDoubles(0, result.size()), 0.0); + ColumnVectors.ofDouble(result, "OptionBid").toArray(), 0.0); table = testRefreshingTable( col("String", "c", "e", "g"), @@ -484,10 +486,10 @@ public void testAjLt() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); - assertEquals(asList(null, null, "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("a", "c", "d"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(null, null, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {null, null, "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"a", "c", "d"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, NULL_INT, 2}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "c", "d", "e")); @@ -497,10 +499,10 @@ public void testAjLt() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList(null, "c", "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("c", "d", "e"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(null, 2, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {null, "c", "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"c", "d", "e"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, 2, 2}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "h", "e", "a")); result = lookUpValue1.aj(table, "indx>String", "String,Int"); @@ -510,10 +512,10 @@ public void testAjLt() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("g", "c", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("h", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(6, 2, null), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"g", "c", null}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {6, 2, NULL_INT}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "h", "e", "a")); @@ -529,9 +531,9 @@ public void testAjLt() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals(2, result.numColumns()); - assertEquals(asList("g", "c", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("h", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); + assertArrayEquals(new String[] {"g", "c", null}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); lookUpValue1 = testRefreshingTable(col("String", "h", "e", "a")); result = lookUpValue1.aj(table, "String>String", "xString=String,Int"); @@ -540,11 +542,11 @@ public void testAjLt() { assertEquals("xString", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("g", "c", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "xString").getDirect())); - assertEquals(asList("h", "e", "a"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList(6, 2, null), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"g", "c", null}, + ColumnVectors.ofObject(result, "xString", String.class).toArray()); + assertArrayEquals(new String[] {"h", "e", "a"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new int[] {6, 2, NULL_INT}, ColumnVectors.ofInt(result, "Int").toArray()); } @@ -599,15 +601,15 @@ public void testAjNull() { System.out.println("AJ:"); TableTools.show(aj); - assertEquals(asList("E2", "D4", "G6", "H8"), - asList((Object[]) DataAccessHelpers.getColumn(aj, "RSentinel").getDirect())); + assertArrayEquals(new String[] {"E2", "D4", "G6", "H8"}, + ColumnVectors.ofObject(aj, "RSentinel", String.class).toArray()); System.out.println("AJ2:"); // let's swap the left and right final Table aj2 = right.sort("RSentinel").aj(left, "RInt>=LInt", "LInt,LSentinel"); TableTools.show(aj2); - assertEquals(asList("a", null, "b", null, "b", "c", "d", "c"), - asList((Object[]) DataAccessHelpers.getColumn(aj2, "LSentinel").getDirect())); + assertArrayEquals(new String[] {"a", null, "b", null, "b", "c", "d", "c"}, + ColumnVectors.ofObject(aj2, "LSentinel", String.class).toArray()); } @@ -632,8 +634,8 @@ public void testAjEmptyRight() { System.out.println("AJ:"); TableTools.show(aj); - assertEquals(asList(null, null, null, null), - asList((Object[]) DataAccessHelpers.getColumn(aj, "RSentinel").getDirect())); + assertArrayEquals(new String[] {null, null, null, null}, + ColumnVectors.ofObject(aj, "RSentinel", String.class).toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -642,8 +644,8 @@ public void testAjEmptyRight() { }); TableTools.show(aj); - assertEquals(asList(null, null, null, null), - asList((Object[]) DataAccessHelpers.getColumn(aj, "RSentinel").getDirect())); + assertArrayEquals(new String[] {null, null, null, null}, + ColumnVectors.ofObject(aj, "RSentinel", String.class).toArray()); } @@ -659,15 +661,15 @@ public void testRaj() { Table result = table.raj(lookUpValue1, "Ticker,Timestamp", "OptionBid"); show(result, 10); - assertEquals(Arrays.asList("Ticker", "Timestamp", "OptionBid"), result.getDefinition().getColumnNames()); + assertEquals(asList("Ticker", "Timestamp", "OptionBid"), result.getDefinition().getColumnNames()); assertEquals(3, result.size()); assertEquals("Ticker", result.getDefinition().getColumns().get(0).getName()); assertEquals("Timestamp", result.getDefinition().getColumns().get(1).getName()); assertEquals("OptionBid", result.getDefinition().getColumns().get(2).getName()); - assertEquals(asList("AAPL", "IBM", "AAPL"), - asList((Object[]) DataAccessHelpers.getColumn(result, "Ticker").getDirect())); - assertEquals(asList(1L, 10L, 50L), asList(DataAccessHelpers.getColumn(result, "Timestamp").get(0, 3))); - assertEquals(asList(.1, .4, .5), asList(DataAccessHelpers.getColumn(result, "OptionBid").get(0, 3))); + assertArrayEquals(new String[] {"AAPL", "IBM", "AAPL"}, + ColumnVectors.ofObject(result, "Ticker", String.class).toArray()); + assertArrayEquals(new long[] {1L, 10L, 50L}, ColumnVectors.ofLong(result, "Timestamp").toArray()); + assertArrayEquals(new double[] {.1, .4, .5}, ColumnVectors.ofDouble(result, "OptionBid").toArray(), DELTA); table = testRefreshingTable( col("Timestamp", 1L, 10L, 50L)); @@ -689,10 +691,10 @@ public void testRaj() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); - assertEquals(asList("c", "c", "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("a", "b", "c"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(2, 2, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"c", "c", "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {2, 2, 2}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "f", "g", "h")); @@ -703,10 +705,10 @@ public void testRaj() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); - assertEquals(asList("g", "g", null), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("f", "g", "h"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(6, 6, null), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"g", "g", null}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"f", "g", "h"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {6, 6, NULL_INT}, ColumnVectors.ofInt(result, "Int").toArray()); result = lookUpValue1.raj(table, "indx<=String", "Int,String"); @@ -728,10 +730,10 @@ public void testRaj() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList("c", "e", "e"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("c", "d", "e"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(2, 4, 4), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "e"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"c", "d", "e"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {2, 4, 4}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "j", "e", "a")); result = lookUpValue1.raj(table, "indx<=String", "String,Int"); @@ -740,10 +742,10 @@ public void testRaj() { assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList(null, "e", "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("j", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); - assertEquals(asList(null, 4, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {null, "e", "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"j", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, 4, 2}, ColumnVectors.ofInt(result, "Int").toArray()); lookUpValue1 = testRefreshingTable(col("indx", "j", "e", "a")); @@ -752,9 +754,9 @@ public void testRaj() { assertEquals("indx", result.getDefinition().getColumns().get(0).getName()); assertEquals("String", result.getDefinition().getColumns().get(1).getName()); assertEquals(2, result.numColumns()); - assertEquals(asList(null, "e", "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList("j", "e", "a"), asList((Object[]) DataAccessHelpers.getColumn(result, "indx").getDirect())); + assertArrayEquals(new String[] {null, "e", "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new String[] {"j", "e", "a"}, ColumnVectors.ofObject(result, "indx", String.class).toArray()); lookUpValue1 = testRefreshingTable(col("String", "j", "e", "a")); result = lookUpValue1.raj(table, "String", "xString=String,Int"); @@ -763,11 +765,11 @@ public void testRaj() { assertEquals("xString", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int", result.getDefinition().getColumns().get(2).getName()); assertEquals(3, result.numColumns()); - assertEquals(asList(null, "e", "c"), - asList((Object[]) DataAccessHelpers.getColumn(result, "xString").getDirect())); - assertEquals(asList("j", "e", "a"), - asList((Object[]) DataAccessHelpers.getColumn(result, "String").getDirect())); - assertEquals(asList(null, 4, 2), asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); + assertArrayEquals(new String[] {null, "e", "c"}, + ColumnVectors.ofObject(result, "xString", String.class).toArray()); + assertArrayEquals(new String[] {"j", "e", "a"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, 4, 2}, ColumnVectors.ofInt(result, "Int").toArray()); } static final JoinControl SMALL_LEFT_CONTROL = new JoinControl() { @@ -805,13 +807,13 @@ public void testAjRegression0() { showWithRowSet(rightQueryTable); final Table sortedRightQueryTable = rightQueryTable.sort("I1"); showWithRowSet(sortedRightQueryTable); - final Table result = leftQueryTable.aj(sortedRightQueryTable, "C1,I1", "LI1=I1,LC1=C1,Sentinel"); + final Table result = leftQueryTable.aj(sortedRightQueryTable, "C1,I1", "RI1=I1,RC1=C1,Sentinel"); showWithRowSet(result); - assertEquals(100, DataAccessHelpers.getColumn(result, "Sentinel").get(3)); - assertEquals(207, DataAccessHelpers.getColumn(result, "LI1").get(3)); - assertEquals(140, DataAccessHelpers.getColumn(result, "Sentinel").get(4)); - assertEquals(432, DataAccessHelpers.getColumn(result, "LI1").get(4)); + assertEquals(100, result.getColumnSource("Sentinel", int.class).getInt(result.getRowSet().get(3))); + assertEquals(207, result.getColumnSource("RI1", int.class).getInt(result.getRowSet().get(3))); + assertEquals(140, result.getColumnSource("Sentinel", int.class).getInt(result.getRowSet().get(4))); + assertEquals(432, result.getColumnSource("RI1", int.class).getInt(result.getRowSet().get(4))); } @Test @@ -834,8 +836,8 @@ public void testAjRegression1() { final Table result = leftQueryTable.aj(sortedRightQueryTable, "C1,I1", "LI1=I1,LC1=C1,Sentinel"); showWithRowSet(result); - assertEquals(80, DataAccessHelpers.getColumn(result, "Sentinel").get(5)); - assertEquals(821, DataAccessHelpers.getColumn(result, "LI1").get(5)); + assertEquals(80, result.getColumnSource("Sentinel", int.class).getInt(result.getRowSet().get(5))); + assertEquals(821, result.getColumnSource("LI1", int.class).getInt(result.getRowSet().get(5))); } @@ -849,10 +851,10 @@ public void testJoin() { assertEquals(2, result.numColumns()); assertEquals("X", result.getDefinition().getColumns().get(0).getName()); assertEquals("Y", result.getDefinition().getColumns().get(1).getName()); - assertEquals(Arrays.asList("a", "a", "b", "b", "c", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 6))); - assertEquals(Arrays.asList("x", "y", "x", "y", "x", "y"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 6))); + assertArrayEquals(new String[] {"a", "a", "b", "b", "c", "c"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"x", "y", "x", "y", "x", "y"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b", "b"), col("Z", 1, 2, 3)); @@ -862,9 +864,9 @@ public void testJoin() { assertEquals("X", result.getDefinition().getColumns().get(0).getName()); assertEquals("Y", result.getDefinition().getColumns().get(1).getName()); assertEquals("Z", result.getDefinition().getColumns().get(2).getName()); - assertEquals(Arrays.asList("a", "b", "b"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); - assertEquals(Arrays.asList("a", "b", "b"), Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 3))); - assertEquals(Arrays.asList(1, 2, 3), Arrays.asList(DataAccessHelpers.getColumn(result, "Z").get(0, 3))); + assertArrayEquals(new String[] {"a", "b", "b"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "b"}, ColumnVectors.ofObject(result, "Y", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(result, "Z").toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b")); @@ -874,8 +876,8 @@ public void testJoin() { assertEquals(2, result.numColumns()); assertEquals("X", result.getDefinition().getColumns().get(0).getName()); assertEquals("Y", result.getDefinition().getColumns().get(1).getName()); - assertEquals(Arrays.asList("a", "b"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 2))); - assertEquals(Arrays.asList("a", "b"), Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 2))); + assertArrayEquals(new String[] {"a", "b"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b"}, ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("X", "a", "b", "d")); @@ -884,7 +886,7 @@ public void testJoin() { assertEquals(2, result.size()); assertEquals(1, result.numColumns()); assertEquals("X", result.getDefinition().getColumns().get(0).getName()); - assertEquals(Arrays.asList("a", "b"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 2))); + assertArrayEquals(new String[] {"a", "b"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); } @Test @@ -908,14 +910,15 @@ public void testNaturalJoinWithGroupBy() { assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(IntVector.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(DoubleVector.class, pairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - IntVector[] vValues = (IntVector[]) DataAccessHelpers.getColumn(pairMatch, "v").getDirect(); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + IntVector[] vValues = ColumnVectors.ofObject(pairMatch, "v", IntVector.class).toArray(); assertEquals(1, vValues[0].get(0)); assertEquals(2, vValues[1].get(0)); assertEquals(1, vValues[0].size()); assertEquals(1, vValues[1].size()); assertNull(vValues[2]); - DoubleVector[] uValues = (DoubleVector[]) DataAccessHelpers.getColumn(pairMatch, "u").getDirect(); + DoubleVector[] uValues = ColumnVectors.ofObject(pairMatch, "u", DoubleVector.class).toArray(); assertEquals(3.0, uValues[0].get(0), 0.000001); assertEquals(4.0, uValues[1].get(0), 0.000001); assertEquals(1, uValues[0].size()); @@ -929,8 +932,9 @@ public void testNaturalJoinWithGroupBy() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(IntVector.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - vValues = (IntVector[]) DataAccessHelpers.getColumn(pairMatch, "v").getDirect(); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + vValues = ColumnVectors.ofObject(pairMatch, "v", IntVector.class).toArray(); assertEquals(1, vValues[0].get(0)); assertEquals(2, vValues[1].get(0)); assertEquals(1, vValues[0].size()); @@ -946,14 +950,15 @@ public void testNaturalJoinWithGroupBy() { assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(DoubleVector.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(IntVector.class, pairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - vValues = (IntVector[]) DataAccessHelpers.getColumn(pairMatch, "v").getDirect(); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + vValues = ColumnVectors.ofObject(pairMatch, "v", IntVector.class).toArray(); assertEquals(1, vValues[0].get(0)); assertEquals(2, vValues[1].get(0)); assertEquals(1, vValues[0].size()); assertEquals(1, vValues[1].size()); assertNull(vValues[2]); - uValues = (DoubleVector[]) DataAccessHelpers.getColumn(pairMatch, "u").getDirect(); + uValues = ColumnVectors.ofObject(pairMatch, "u", DoubleVector.class).toArray(); assertEquals(3.0, uValues[0].get(0), 0.000001); assertEquals(4.0, uValues[1].get(0), 0.000001); assertEquals(1, uValues[0].size()); @@ -967,8 +972,9 @@ public void testNaturalJoinWithGroupBy() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(IntVector.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - vValues = (IntVector[]) DataAccessHelpers.getColumn(pairMatch, "v").getDirect(); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + vValues = ColumnVectors.ofObject(pairMatch, "v", IntVector.class).toArray(); assertEquals(1, vValues[0].get(0)); assertEquals(2, vValues[1].get(0)); assertEquals(1, vValues[0].size()); @@ -990,17 +996,20 @@ public void testNaturalJoinWithGroupBy() { assertEquals(String.class, noPairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(ObjectVector.class, noPairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(IntVector.class, noPairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(noPairMatch, 0).getDirect())); + assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors + .ofObject(noPairMatch, noPairMatch.getDefinition().getColumns().get(0).getName(), String.class) + .toArray()); // noinspection unchecked final ObjectVector[] aggregateString = - (ObjectVector[]) DataAccessHelpers.getColumn(noPairMatch, "String2").getDirect(); - assertEquals(asList("c", "e"), asList(aggregateString[0].toArray())); - assertEquals(asList("c", "e"), asList(aggregateString[1].toArray())); - assertEquals(asList("c", "e"), asList(aggregateString[2].toArray())); - vValues = (IntVector[]) DataAccessHelpers.getColumn(noPairMatch, "v").getDirect(); - assertEquals(asList(1, 2), asList(ArrayTypeUtils.getBoxedArray(vValues[0].toArray()))); - assertEquals(asList(1, 2), asList(ArrayTypeUtils.getBoxedArray(vValues[1].toArray()))); - assertEquals(asList(1, 2), asList(ArrayTypeUtils.getBoxedArray(vValues[2].toArray()))); + ColumnVectors.ofObject(noPairMatch, "String2", ObjectVector.class).toArray(); + assertArrayEquals(new String[] {"c", "e"}, aggregateString[0].toArray()); + assertArrayEquals(new String[] {"c", "e"}, aggregateString[1].toArray()); + assertArrayEquals(new String[] {"c", "e"}, aggregateString[2].toArray()); + vValues = ColumnVectors.ofObject(noPairMatch, "v", IntVector.class).toArray(); + assertArrayEquals(new int[] {1, 2}, vValues[0].toArray()); + assertArrayEquals(new int[] {1, 2}, vValues[1].toArray()); + assertArrayEquals(new int[] {1, 2}, vValues[2].toArray()); pairMatch = table1.naturalJoin(table2.groupBy("String2"), "String1=String2"); assertEquals(3, pairMatch.size()); @@ -1011,14 +1020,15 @@ public void testNaturalJoinWithGroupBy() { assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(IntVector.class, pairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); - final String[] stringColumn = (String[]) DataAccessHelpers.getColumn(pairMatch, "String2").getDirect(); + final String[] stringColumn = ColumnVectors.ofObject(pairMatch, "String2", String.class).toArray(); assertEquals("c", stringColumn[0]); assertEquals("e", stringColumn[1]); assertNull(stringColumn[2]); - vValues = (IntVector[]) DataAccessHelpers.getColumn(pairMatch, "v").getDirect(); + vValues = ColumnVectors.ofObject(pairMatch, "v", IntVector.class).toArray(); assertEquals(1, vValues[0].get(0)); assertEquals(2, vValues[1].get(0)); assertEquals(1, vValues[0].size()); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableNaturalJoinTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableNaturalJoinTest.java index 5ba3bec89c2..f9e7d3c9880 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableNaturalJoinTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableNaturalJoinTest.java @@ -14,12 +14,12 @@ import io.deephaven.engine.table.ChunkSource; import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.engine.table.ColumnSource; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.engine.table.impl.indexer.DataIndexer; import io.deephaven.engine.table.impl.select.MatchPairFactory; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; @@ -29,6 +29,8 @@ import io.deephaven.time.DateTimeUtils; import io.deephaven.util.QueryConstants; import io.deephaven.util.mutable.MutableInt; +import io.deephaven.vector.IntVector; +import io.deephaven.vector.ObjectVector; import junit.framework.TestCase; import org.jetbrains.annotations.NotNull; import org.junit.experimental.categories.Category; @@ -47,7 +49,7 @@ import static io.deephaven.engine.testutil.TstUtils.*; import static io.deephaven.engine.util.TableTools.*; import static io.deephaven.util.QueryConstants.NULL_INT; -import static java.util.Arrays.asList; +import static org.junit.Assert.assertArrayEquals; @Category(OutOfBandTest.class) public class QueryTableNaturalJoinTest extends QueryTableTestBase { @@ -249,26 +251,23 @@ public void testNaturalJoinLeftStaticRightIncremental() { private void testNaturalJoinIncremental(boolean leftStatic, boolean rightStatic, int leftSize, int rightSize, boolean leftIndexed, boolean rightIndexed, - JoinIncrement joinIncrement, long seed, long maxSteps) { + JoinIncrement joinIncrement, long seed, int maxSteps) { testNaturalJoinIncremental(leftStatic, rightStatic, leftSize, rightSize, leftIndexed, rightIndexed, - joinIncrement, seed, - new MutableInt((int) maxSteps)); + joinIncrement, seed, new MutableInt(maxSteps)); } private void testNaturalJoinIncremental(boolean leftStatic, boolean rightStatic, int leftSize, int rightSize, boolean leftIndexed, boolean rightIndexed, JoinIncrement joinIncrement, long seed, MutableInt numSteps) { testNaturalJoinIncremental(leftStatic, rightStatic, leftSize, rightSize, leftIndexed, rightIndexed, - joinIncrement, seed, numSteps, - new JoinControl()); + joinIncrement, seed, numSteps, new JoinControl()); } private static void testNaturalJoinIncremental(boolean leftStatic, boolean rightStatic, int leftSize, int rightSize, - boolean leftIndexed, boolean rightIndexed, JoinIncrement joinIncrement, long seed, long maxSteps, + boolean leftIndexed, boolean rightIndexed, JoinIncrement joinIncrement, long seed, int maxSteps, JoinControl control) { testNaturalJoinIncremental(leftStatic, rightStatic, leftSize, rightSize, leftIndexed, rightIndexed, - joinIncrement, seed, - new MutableInt((int) maxSteps), control); + joinIncrement, seed, new MutableInt(maxSteps), control); } private static void testNaturalJoinIncremental(boolean leftStatic, boolean rightStatic, int leftSize, int rightSize, @@ -444,7 +443,6 @@ public void testNaturalJoinSimpleStatic() { } public void testNaturalJoinGroupedStatic() { - // noinspection unchecked testNaturalJoinSimpleStatic(TstUtils::colIndexed); } @@ -892,10 +890,10 @@ public void testNaturalJoin() { assertEquals("String", result.getDefinition().getColumns().get(0).getName()); assertEquals("Int", result.getDefinition().getColumns().get(1).getName()); assertEquals("Int2", result.getDefinition().getColumns().get(2).getName()); - assertEquals(Arrays.asList("a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "String").get(0, 3))); - assertEquals(Arrays.asList(1, 2, 3), Arrays.asList(DataAccessHelpers.getColumn(result, "Int").get(0, 3))); - assertEquals(Arrays.asList(10, 20, 30), Arrays.asList(DataAccessHelpers.getColumn(result, "Int2").get(0, 3))); + assertArrayEquals(new String[] {"a", "b", "c"}, + ColumnVectors.ofObject(result, "String", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(result, "Int").toArray()); + assertArrayEquals(new int[] {10, 20, 30}, ColumnVectors.ofInt(result, "Int2").toArray()); Table table1 = TstUtils.testRefreshingTable( @@ -909,8 +907,9 @@ public void testNaturalJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, null), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, NULL_INT}, ColumnVectors.ofInt(pairMatch, "v").toArray()); table2 = TstUtils.testRefreshingTable( @@ -923,8 +922,9 @@ public void testNaturalJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table2.naturalJoin(table1, "String", ""); assertEquals(3, pairMatch.size()); @@ -933,8 +933,9 @@ public void testNaturalJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table1.naturalJoin(table2, "String=String", "v"); assertEquals(3, pairMatch.size()); @@ -943,8 +944,9 @@ public void testNaturalJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table2.naturalJoin(table1, "String=String", ""); @@ -954,10 +956,12 @@ public void testNaturalJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(1, DataAccessHelpers.getColumn(pairMatch, "v").getInt(0)); - assertEquals(2, DataAccessHelpers.getColumn(pairMatch, "v").getInt(1)); - assertEquals(3, DataAccessHelpers.getColumn(pairMatch, "v").getInt(2)); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + IntVector vValues = ColumnVectors.ofInt(pairMatch, "v"); + assertEquals(1, vValues.get(0)); + assertEquals(2, vValues.get(1)); + assertEquals(3, vValues.get(2)); table1 = TstUtils.testRefreshingTable( @@ -977,9 +981,12 @@ public void testNaturalJoin() { assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 1).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, 2).get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(1).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(pairMatch, pairMatch.getDefinition().getColumns().get(2).getName()).toArray()); pairMatch = table2.naturalJoin(table1, "String2=String1", "String1"); @@ -992,11 +999,11 @@ public void testNaturalJoin() { assertEquals(String.class, pairMatch.getDefinition().getColumn("String1").getDataType()); assertEquals(String.class, pairMatch.getDefinition().getColumn("String2").getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumn("v").getDataType()); - assertEquals(asList("c", "e", "g"), - asList((Object[]) DataAccessHelpers.getColumn(pairMatch, "String1").getDirect())); - assertEquals(asList("c", "e", "g"), - asList((Object[]) DataAccessHelpers.getColumn(pairMatch, "String2").getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors.ofObject(pairMatch, "String1", String.class).toArray()); + assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors.ofObject(pairMatch, "String2", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); } public void testNaturalJoinNull() { @@ -1007,10 +1014,12 @@ public void testNaturalJoinNull() { TableTools.show(cj); - assertEquals(1, DataAccessHelpers.getColumn(cj, "X").get(0)); - assertEquals(2, DataAccessHelpers.getColumn(cj, "X").get(1)); - assertEquals(3, DataAccessHelpers.getColumn(cj, "Y").get(0)); - assertEquals(4, DataAccessHelpers.getColumn(cj, "Y").get(1)); + final IntVector xValues = ColumnVectors.ofInt(cj, "X"); + assertEquals(1, xValues.get(0)); + assertEquals(2, xValues.get(1)); + final IntVector yValues = ColumnVectors.ofInt(cj, "Y"); + assertEquals(3, yValues.get(0)); + assertEquals(4, yValues.get(1)); } public void testNaturalJoinInactive() { @@ -1024,10 +1033,12 @@ public void testNaturalJoinInactive() { System.out.println("Result:"); TableTools.showWithRowSet(cj); - assertEquals(1, DataAccessHelpers.getColumn(cj, "X").get(0)); - assertEquals(2, DataAccessHelpers.getColumn(cj, "X").get(1)); - assertEquals(3, DataAccessHelpers.getColumn(cj, "Y").get(0)); - assertNull(DataAccessHelpers.getColumn(cj, "Y").get(1)); + IntVector xValues = ColumnVectors.ofInt(cj, "X"); + assertEquals(1, xValues.get(0)); + assertEquals(2, xValues.get(1)); + IntVector yValues = ColumnVectors.ofInt(cj, "Y"); + assertEquals(3, yValues.get(0)); + assertEquals(NULL_INT, yValues.get(1)); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -1037,10 +1048,12 @@ public void testNaturalJoinInactive() { System.out.println("Right:"); TableTools.showWithRowSet(c1); - assertEquals(1, DataAccessHelpers.getColumn(cj, "X").get(0)); - assertEquals(2, DataAccessHelpers.getColumn(cj, "X").get(1)); - assertEquals(3, DataAccessHelpers.getColumn(cj, "Y").get(0)); - assertNull(DataAccessHelpers.getColumn(cj, "Y").get(1)); + xValues = ColumnVectors.ofInt(cj, "X"); + assertEquals(1, xValues.get(0)); + assertEquals(2, xValues.get(1)); + yValues = ColumnVectors.ofInt(cj, "Y"); + assertEquals(3, yValues.get(0)); + assertEquals(NULL_INT, yValues.get(1)); updateGraph.runWithinUnitTestCycle(() -> { addToTable(c0, i(2), col("USym0", "B"), col("X", 6)); @@ -1053,12 +1066,14 @@ public void testNaturalJoinInactive() { System.out.println("Result:"); TableTools.showWithRowSet(cj); - assertEquals(1, DataAccessHelpers.getColumn(cj, "X").get(0)); - assertEquals(2, DataAccessHelpers.getColumn(cj, "X").get(1)); - assertEquals(6, DataAccessHelpers.getColumn(cj, "X").get(2)); - assertEquals(3, DataAccessHelpers.getColumn(cj, "Y").get(0)); - assertNull(DataAccessHelpers.getColumn(cj, "Y").get(1)); - assertEquals(4, DataAccessHelpers.getColumn(cj, "Y").get(2)); + xValues = ColumnVectors.ofInt(cj, "X"); + assertEquals(1, xValues.get(0)); + assertEquals(2, xValues.get(1)); + assertEquals(6, xValues.get(2)); + yValues = ColumnVectors.ofInt(cj, "Y"); + assertEquals(3, yValues.get(0)); + assertEquals(NULL_INT, yValues.get(1)); + assertEquals(4, yValues.get(2)); } public void testNaturalJoinLeftIncrementalRightStaticSimple() { @@ -1501,8 +1516,9 @@ public void testExactJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table2.exactJoin(table1, "String"); assertEquals(3, pairMatch.size()); @@ -1511,8 +1527,9 @@ public void testExactJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table1.exactJoin(table2, "String=String"); assertEquals(3, pairMatch.size()); @@ -1521,8 +1538,9 @@ public void testExactJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); pairMatch = table2.exactJoin(table1, "String=String"); @@ -1532,11 +1550,9 @@ public void testExactJoin() { assertEquals("v", pairMatch.getDefinition().getColumns().get(1).getName()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(1, DataAccessHelpers.getColumn(pairMatch, "v").getInt(0)); - assertEquals(2, DataAccessHelpers.getColumn(pairMatch, "v").getInt(1)); - assertEquals(3, DataAccessHelpers.getColumn(pairMatch, "v").getInt(2)); - + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); table1 = testRefreshingTable(col("String1", "c", "e", "g")); @@ -1551,9 +1567,12 @@ public void testExactJoin() { assertEquals(String.class, pairMatch.getDefinition().getColumns().get(0).getDataType()); assertEquals(String.class, pairMatch.getDefinition().getColumns().get(1).getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumns().get(2).getDataType()); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 0).getDirect())); - assertEquals(asList("c", "e", "g"), asList((Object[]) DataAccessHelpers.getColumn(pairMatch, 1).getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, 2).get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(0).getName(), String.class).toArray()); + assertArrayEquals(new String[] {"c", "e", "g"}, ColumnVectors + .ofObject(pairMatch, pairMatch.getDefinition().getColumns().get(1).getName(), String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, + ColumnVectors.ofInt(pairMatch, pairMatch.getDefinition().getColumns().get(2).getName()).toArray()); pairMatch = table2.exactJoin(table1, "String2=String1"); @@ -1566,11 +1585,11 @@ public void testExactJoin() { assertEquals(String.class, pairMatch.getDefinition().getColumn("String1").getDataType()); assertEquals(String.class, pairMatch.getDefinition().getColumn("String2").getDataType()); assertEquals(int.class, pairMatch.getDefinition().getColumn("v").getDataType()); - assertEquals(asList("c", "e", "g"), - asList((Object[]) DataAccessHelpers.getColumn(pairMatch, "String1").getDirect())); - assertEquals(asList("c", "e", "g"), - asList((Object[]) DataAccessHelpers.getColumn(pairMatch, "String2").getDirect())); - assertEquals(asList(1, 2, 3), asList(DataAccessHelpers.getColumn(pairMatch, "v").get(0, 3))); + assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors.ofObject(pairMatch, "String1", String.class).toArray()); + assertArrayEquals(new String[] {"c", "e", "g"}, + ColumnVectors.ofObject(pairMatch, "String2", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(pairMatch, "v").toArray()); } public void testSymbolTableJoin() throws IOException { @@ -1655,7 +1674,7 @@ public void testGetDirectAfterNaturalJoin() { assertEquals(rightValue, ck.get(1)); assertNull(ck.get(2)); } - final DataColumn colRight = DataAccessHelpers.getColumn(vanillaVanilla, "ColRight"); + final ObjectVector colRight = ColumnVectors.ofObject(vanillaVanilla, "ColRight", String.class); assertEquals(rightValue, colRight.get(0)); assertEquals(rightValue, colRight.get(1)); assertNull(colRight.get(2)); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSelectUpdateTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSelectUpdateTest.java index d0173467f5b..35596b75d0e 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSelectUpdateTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSelectUpdateTest.java @@ -25,6 +25,7 @@ import io.deephaven.engine.table.impl.sources.RedirectedColumnSource; import io.deephaven.engine.table.impl.sources.SparseArrayColumnSource; import io.deephaven.engine.table.impl.util.RuntimeMemory; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.QueryTableTestBase.ListenerWithGlobals; import io.deephaven.engine.testutil.QueryTableTestBase.TableComparator; @@ -47,7 +48,9 @@ import static io.deephaven.engine.testutil.TstUtils.*; import static io.deephaven.engine.util.TableTools.*; +import static io.deephaven.util.QueryConstants.NULL_INT; import static java.util.Collections.emptyList; +import static org.junit.Assert.assertArrayEquals; /** * Test QueryTable select and update operations. @@ -248,13 +251,9 @@ public void testLazyUpdate() { .lazyUpdate("B=" + QueryTableSelectUpdateTest.class.getCanonicalName() + ".callCounter(A)"); TestCase.assertEquals(3, table.size()); TestCase.assertEquals(0, callCount); - TestCase - .assertEquals(Arrays.asList(3, 6, 9), - Arrays.asList(DataAccessHelpers.getColumn(table, "B").get(0, table.size()))); + assertArrayEquals(new int[] {3, 6, 9}, ColumnVectors.ofInt(table, "B").toArray()); TestCase.assertEquals(3, callCount); - TestCase - .assertEquals(Arrays.asList(3, 6, 9), - Arrays.asList(DataAccessHelpers.getColumn(table, "B").get(0, table.size()))); + assertArrayEquals(new int[] {3, 6, 9}, ColumnVectors.ofInt(table, "B").toArray()); TestCase.assertEquals(3, callCount); callCount = 0; @@ -264,11 +263,9 @@ public void testLazyUpdate() { .lazyUpdate("B=" + QueryTableSelectUpdateTest.class.getCanonicalName() + ".callCounter(A)"); TestCase.assertEquals(6, table2.size()); TestCase.assertEquals(0, callCount); - TestCase.assertEquals(Arrays.asList(3, 6, 9, 6, 9, 3), - Arrays.asList(DataAccessHelpers.getColumn(table2, "B").get(0, table2.size()))); + assertArrayEquals(new int[] {3, 6, 9, 6, 9, 3}, ColumnVectors.ofInt(table2, "B").toArray()); TestCase.assertEquals(3, callCount); - TestCase.assertEquals(Arrays.asList(3, 6, 9, 6, 9, 3), - Arrays.asList(DataAccessHelpers.getColumn(table2, "B").get(0, table2.size()))); + assertArrayEquals(new int[] {3, 6, 9, 6, 9, 3}, ColumnVectors.ofInt(table2, "B").toArray()); TestCase.assertEquals(3, callCount); TestCase.assertEquals(3, table2.getColumnSource("B").getInt(2)); TestCase.assertEquals(3, table2.getColumnSource("B").get(2)); @@ -735,7 +732,7 @@ private void testUpdateIncrementalRandomized(int seed, boolean useRedirection, i private void testUpdateIncrementalRandomized(final int seed, MutableInt numSteps, int size) { final Random random = new Random(seed); - final ColumnInfo[] columnInfo; + final ColumnInfo[] columnInfo; final QueryTable queryTable = getTable(size, random, columnInfo = initColumnInfos(new String[] {"Sym", "intCol", "doubleCol"}, new SetGenerator<>("a", "b", "c", "d", "e"), @@ -760,7 +757,7 @@ private void testUpdateIncrementalRandomized(final int seed, MutableInt numSteps @Test public void testUpdateIncrementalWithI() { Random random = new Random(0); - ColumnInfo[] columnInfo; + ColumnInfo[] columnInfo; int size = 50; final QueryTable queryTable = getTable(size, random, columnInfo = initColumnInfos(new String[] {"Sym", "intCol", "doubleCol"}, @@ -804,11 +801,8 @@ public void testUpdateEmptyTable() { TestCase.assertEquals(2, table.size()); TestCase.assertEquals(2, table2.size()); show(table2); - TestCase.assertEquals(Arrays.asList(0, 3), - Arrays.asList(DataAccessHelpers.getColumn(table2, "x").get(0, table2.size()))); - TestCase - .assertEquals(Arrays.asList("7", "9"), - Arrays.asList(DataAccessHelpers.getColumn(table2, "y").get(0, table2.size()))); + assertArrayEquals(new int[] {0, 3}, ColumnVectors.ofInt(table2, "x").toArray()); + assertArrayEquals(new String[] {"7", "9"}, ColumnVectors.ofObject(table2, "y", String.class).toArray()); TestCase.assertEquals(base.added, i(7, 9)); TestCase.assertEquals(base.removed, i()); TestCase.assertEquals(base.modified, i()); @@ -838,10 +832,8 @@ public void testUpdateIndex() { TestCase.assertEquals(2, table.size()); TestCase.assertEquals(2, table2.size()); show(table2); - TestCase.assertEquals(Arrays.asList(0, 1), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Position").get(0, table2.size()))); - TestCase.assertEquals(Arrays.asList("7", "9"), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Key").get(0, table2.size()))); + assertArrayEquals(new int[] {0, 1}, ColumnVectors.ofInt(table2, "Position").toArray()); + assertArrayEquals(new String[] {"7", "9"}, ColumnVectors.ofObject(table2, "Key", String.class).toArray()); TestCase.assertEquals(base.added, i(7, 9)); TestCase.assertEquals(base.removed, i()); TestCase.assertEquals(base.modified, i()); @@ -851,10 +843,8 @@ public void testUpdateIndex() { TestCase.assertEquals(2, table.size()); TestCase.assertEquals(2, table2.size()); show(table2); - TestCase.assertEquals(Arrays.asList(0, 1), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Position").get(0, table2.size()))); - TestCase.assertEquals(Arrays.asList("7", "9"), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Key").get(0, table2.size()))); + assertArrayEquals(new int[] {0, 1}, ColumnVectors.ofInt(table2, "Position").toArray()); + assertArrayEquals(new String[] {"7", "9"}, ColumnVectors.ofObject(table2, "Key", String.class).toArray()); TestCase.assertEquals(base.added, i()); TestCase.assertEquals(base.removed, i()); TestCase.assertEquals(base.modified, i(9)); @@ -882,11 +872,9 @@ public void testUpdateArrayColumns() { TestCase.assertEquals(2, table.size()); TestCase.assertEquals(2, table2.size()); show(table2); - TestCase.assertEquals(Arrays.asList(0, 1), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Position").get(0, table2.size()))); - // assertEquals(Arrays.asList("7", "9"), Arrays.asList(table2.getColumn("Key").get(0, table2.size()))); - TestCase.assertEquals(Arrays.asList(null, 0), - Arrays.asList(DataAccessHelpers.getColumn(table2, "PrevI").get(0, table2.size()))); + assertArrayEquals(new int[] {0, 1}, ColumnVectors.ofInt(table2, "Position").toArray()); + // assertArrayEquals(new String[] {"7", "9"}, ColumnVectors.ofObject(table2, "Key", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, 0}, ColumnVectors.ofInt(table2, "PrevI").toArray()); TestCase.assertEquals(i(7, 9), base.added); TestCase.assertEquals(i(), base.removed); TestCase.assertEquals(i(), base.modified); @@ -896,11 +884,9 @@ public void testUpdateArrayColumns() { TestCase.assertEquals(2, table.size()); TestCase.assertEquals(2, table2.size()); show(table2); - TestCase.assertEquals(Arrays.asList(0, 1), - Arrays.asList(DataAccessHelpers.getColumn(table2, "Position").get(0, table2.size()))); - // assertEquals(Arrays.asList("7", "9"), Arrays.asList(table2.getColumn("Key").get(0, table2.size()))); - TestCase.assertEquals(Arrays.asList(null, 0), - Arrays.asList(DataAccessHelpers.getColumn(table2, "PrevI").get(0, table2.size()))); + assertArrayEquals(new int[] {0, 1}, ColumnVectors.ofInt(table2, "Position").toArray()); + // assertArrayEquals(new String[] {"7", "9"}, ColumnVectors.ofObject(table2, "Key", String.class).toArray()); + assertArrayEquals(new int[] {NULL_INT, 0}, ColumnVectors.ofInt(table2, "PrevI").toArray()); // note this modification is not reported to table2 since `update` is smart enough to notice that no columns // are actually modified in the result table @@ -1002,7 +988,7 @@ public void testIds5212() { final Table testtest = TableTools.emptyTable(554).view("Quantity=k").where("Quantity>200"); final Table test = testtest.update("Quantity=100", "Test=Quantity"); - final int[] testArray = (int[]) DataAccessHelpers.getColumn(test, "Test").getDirect(); + final int[] testArray = ColumnVectors.ofInt(test, "Test").toArray(); final int[] expected = new int[test.intSize()]; Arrays.fill(expected, 100); BaseArrayTestCase.assertEquals(expected, testArray); @@ -1050,7 +1036,7 @@ public void testExpectedParamFailure() { public void testIds5746() { final Table x = TableTools.emptyTable(2).update("result = `blah`", "L = result.length()"); - final int[] testArray = (int[]) DataAccessHelpers.getColumn(x, "L").getDirect(); + final int[] testArray = ColumnVectors.ofInt(x, "L").toArray(); final int[] expected = new int[] {4, 4}; BaseArrayTestCase.assertEquals(expected, testArray); } @@ -1104,7 +1090,7 @@ public void testRedirectUpdate() { Assert.assertTrue(cs instanceof RedirectedColumnSource); Assert.assertEquals(4L, updated.getColumnSource("D").get(updated.getRowSet().get(1))); - Assert.assertEquals(8L, updated.getColumnSource("D").getPrev(updated.getRowSet().copyPrev().get(2))); + Assert.assertEquals(8L, updated.getColumnSource("D").getPrev(updated.getRowSet().prev().get(2))); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSliceTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSliceTest.java index f88fd615413..875cfa0a4a8 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSliceTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSliceTest.java @@ -8,6 +8,7 @@ import io.deephaven.engine.table.ModifiedColumnSet; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableUpdate; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.IntGenerator; import io.deephaven.engine.testutil.generator.SetGenerator; @@ -457,7 +458,7 @@ public void testShrinkageUpdatePattern() { public void testLongTail() { final Table bigTable = emptyTable(2 * (long) (Integer.MAX_VALUE)).updateView("I=i", "II=ii"); final Table tailed = bigTable.tail(1); - assertEquals(2L * Integer.MAX_VALUE - 1, DataAccessHelpers.getColumn(tailed, "II").get(0)); + assertEquals(2L * Integer.MAX_VALUE - 1, tailed.getColumnSource("II").get(tailed.getRowSet().firstRowKey())); } public void testZeroHead() { diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSortTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSortTest.java index 782cee2d306..d00db2dce9e 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSortTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableSortTest.java @@ -15,6 +15,7 @@ import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.engine.table.impl.indexer.DataIndexer; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.time.DateTimeUtils; @@ -41,27 +42,34 @@ import static io.deephaven.engine.util.TableTools.*; import static io.deephaven.engine.testutil.TstUtils.*; +import static io.deephaven.util.QueryConstants.NULL_CHAR; +import static io.deephaven.util.QueryConstants.NULL_DOUBLE; +import static org.junit.Assert.assertArrayEquals; @Category(OutOfBandTest.class) public class QueryTableSortTest extends QueryTableTestBase { + private static final float DELTA = 0.000001f; + public void testSort() { final Table result0 = newTable(col("Unsorted", 3.0, null, 2.0), col("DataToSort", "c", "a", "b")); show(result0.sort("Unsorted")); - assertEquals(Arrays.asList(null, 2.0, 3.0), - Arrays.asList(DataAccessHelpers.getColumn(result0.sort("Unsorted"), "Unsorted").get(0, 3))); + Table table2 = result0.sort("Unsorted"); + assertArrayEquals(new double[] {NULL_DOUBLE, 2.0, 3.0}, ColumnVectors.ofDouble(table2, "Unsorted").toArray(), + DELTA); show(result0.sortDescending("Unsorted")); - assertEquals(Arrays.asList(3.0, 2.0, null), - Arrays.asList(DataAccessHelpers.getColumn(result0.sortDescending("Unsorted"), "Unsorted").get(0, 3))); + Table table1 = result0.sortDescending("Unsorted"); + assertArrayEquals(new double[] {3.0, 2.0, NULL_DOUBLE}, ColumnVectors.ofDouble(table1, "Unsorted").toArray(), + DELTA); Table result1 = newTable(col("Unsorted", 4.0, 3.0, 1.1, Double.NaN, 2.0, 1.0, 5.0), col("DataToSort", "e", "d", "b", "g", "c", "a", "f")); final Table nanSorted = result1.sort("Unsorted"); show(nanSorted); - assertEquals(Arrays.asList(1.0, 1.1, 2.0, 3.0, 4.0, 5.0, Double.NaN), - Arrays.asList(DataAccessHelpers.getColumn(nanSorted, "Unsorted").get(0, 7))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g"), - Arrays.asList(DataAccessHelpers.getColumn(nanSorted, "DataToSort").get(0, 7))); + assertArrayEquals(new double[] {1.0, 1.1, 2.0, 3.0, 4.0, 5.0, Double.NaN}, + ColumnVectors.ofDouble(nanSorted, "Unsorted").toArray(), DELTA); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g"}, + ColumnVectors.ofObject(nanSorted, "DataToSort", String.class).toArray()); result1 = newTable(col("Unsorted", 4.1f, 3.1f, 1.2f, Float.NaN, 2.1f, 1.1f, 5.1f), col("DataToSort", "e", "d", "b", "g", "c", "a", "f")); @@ -70,56 +78,52 @@ public void testSort() { show(result1); System.out.println("nanFloatedSorted"); show(nanFloatSorted); - assertEquals(Arrays.asList(1.1f, 1.2f, 2.1f, 3.1f, 4.1f, 5.1f, Float.NaN), - Arrays.asList(DataAccessHelpers.getColumn(nanFloatSorted, "Unsorted").get(0, 7))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g"), - Arrays.asList(DataAccessHelpers.getColumn(nanFloatSorted, "DataToSort").get(0, 7))); + assertArrayEquals(new float[] {1.1f, 1.2f, 2.1f, 3.1f, 4.1f, 5.1f, Float.NaN}, + ColumnVectors.ofFloat(nanFloatSorted, "Unsorted").toArray(), DELTA); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g"}, + ColumnVectors.ofObject(nanFloatSorted, "DataToSort", String.class).toArray()); Table result = newTable(col("Unsorted", 3, 1, 2), col("DataToSort", "c", "a", "b")).sort("DataToSort"); - assertEquals(Arrays.asList(1, 2, 3), Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); result = newTable(col("Unsorted", 3, 1, 2), col("DataToSort", "c", "a", "b")).sortDescending("DataToSort"); - assertEquals(Arrays.asList(3, 2, 1), Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("c", "b", "a"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new int[] {3, 2, 1}, ColumnVectors.ofInt(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"c", "b", "a"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); result = newTable(col("Unsorted", '3', '1', '2'), col("DataToSort", "c", "a", "b")).sort("Unsorted"); - assertEquals(Arrays.asList('1', '2', '3'), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new char[] {'1', '2', '3'}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); result = newTable(col("Unsorted", '3', '1', '2'), col("DataToSort", "c", "a", "b")).sortDescending("Unsorted"); - assertEquals(Arrays.asList('3', '2', '1'), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("c", "b", "a"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new char[] {'3', '2', '1'}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"c", "b", "a"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final ColumnHolder c1 = TstUtils.colIndexed("Unsorted", 3, 1, 2); final Table table = newTable(c1, col("DataToSort", "c", "a", "b")); result = table.sort("DataToSort"); - assertEquals(Arrays.asList(1, 2, 3), Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new int[] {1, 2, 3}, ColumnVectors.ofInt(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final ColumnHolder c11 = TstUtils.colIndexed("Unsorted", 3, 1, 2); result = newTable(c11, col("DataToSort", "c", "a", "b")).sortDescending("DataToSort"); - assertEquals(Arrays.asList(3, 2, 1), Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("c", "b", "a"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new int[] {3, 2, 1}, ColumnVectors.ofInt(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"c", "b", "a"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final ColumnHolder c2 = TstUtils.colIndexed("Unsorted", '3', '1', '2'); result = newTable(c2, col("DataToSort", "c", "a", "b")).sort("Unsorted"); - assertEquals(Arrays.asList('1', '2', '3'), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new char[] {'1', '2', '3'}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"a", "b", "c"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final ColumnHolder c22 = TstUtils.colIndexed("Unsorted", '3', '1', '2'); result = newTable(c22, col("DataToSort", "c", "a", "b")).sortDescending("Unsorted"); - assertEquals(Arrays.asList('3', '2', '1'), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 3))); - assertEquals(Arrays.asList("c", "b", "a"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 3))); + assertArrayEquals(new char[] {'3', '2', '1'}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"c", "b", "a"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final Table input = newTable(col("C1", 2, 4, 2, 4), col("C2", '1', '1', '2', '2'), col("Witness", "a", "b", "c", "d")); @@ -128,51 +132,45 @@ public void testSort() { result = input.sort("C1", "C2"); System.out.println("Result:"); showWithRowSet(result); - assertEquals(Arrays.asList(2, 2, 4, 4), Arrays.asList(DataAccessHelpers.getColumn(result, "C1").get(0, 4))); - assertEquals(Arrays.asList('1', '2', '1', '2'), - Arrays.asList(DataAccessHelpers.getColumn(result, "C2").get(0, 4))); - assertEquals(Arrays.asList("a", "c", "b", "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Witness").get(0, 4))); + assertArrayEquals(new int[] {2, 2, 4, 4}, ColumnVectors.ofInt(result, "C1").toArray()); + assertArrayEquals(new char[] {'1', '2', '1', '2'}, ColumnVectors.ofChar(result, "C2").toArray()); + assertArrayEquals(new String[] {"a", "c", "b", "d"}, + ColumnVectors.ofObject(result, "Witness", String.class).toArray()); result = newTable(col("C1", 2, 4, 2, 4), col("C2", '2', '2', '1', '1'), col("Witness", "a", "b", "c", "d")) .sort("C2", "C1"); - assertEquals(Arrays.asList(2, 4, 2, 4), Arrays.asList(DataAccessHelpers.getColumn(result, "C1").get(0, 4))); - assertEquals(Arrays.asList('1', '1', '2', '2'), - Arrays.asList(DataAccessHelpers.getColumn(result, "C2").get(0, 4))); - assertEquals(Arrays.asList("c", "d", "a", "b"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Witness").get(0, 4))); + assertArrayEquals(new int[] {2, 4, 2, 4}, ColumnVectors.ofInt(result, "C1").toArray()); + assertArrayEquals(new char[] {'1', '1', '2', '2'}, ColumnVectors.ofChar(result, "C2").toArray()); + assertArrayEquals(new String[] {"c", "d", "a", "b"}, + ColumnVectors.ofObject(result, "Witness", String.class).toArray()); result = newTable(col("C1", 2, 4, 2, 4), col("C2", '1', '1', '2', '2'), col("Witness", "a", "b", "c", "d")) .sortDescending("C1", "C2"); - assertEquals(Arrays.asList(4, 4, 2, 2), Arrays.asList(DataAccessHelpers.getColumn(result, "C1").get(0, 4))); - assertEquals(Arrays.asList('2', '1', '2', '1'), - Arrays.asList(DataAccessHelpers.getColumn(result, "C2").get(0, 4))); - assertEquals(Arrays.asList("d", "b", "c", "a"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Witness").get(0, 4))); + assertArrayEquals(new int[] {4, 4, 2, 2}, ColumnVectors.ofInt(result, "C1").toArray()); + assertArrayEquals(new char[] {'2', '1', '2', '1'}, ColumnVectors.ofChar(result, "C2").toArray()); + assertArrayEquals(new String[] {"d", "b", "c", "a"}, + ColumnVectors.ofObject(result, "Witness", String.class).toArray()); result = newTable(col("C1", 2, 4, 2, 4), col("C2", '2', '2', '1', '1'), col("Witness", "a", "b", "c", "d")) .sortDescending("C2", "C1"); - assertEquals(Arrays.asList(4, 2, 4, 2), Arrays.asList(DataAccessHelpers.getColumn(result, "C1").get(0, 4))); - assertEquals(Arrays.asList('2', '2', '1', '1'), - Arrays.asList(DataAccessHelpers.getColumn(result, "C2").get(0, 4))); - assertEquals(Arrays.asList("b", "a", "d", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Witness").get(0, 4))); + assertArrayEquals(new int[] {4, 2, 4, 2}, ColumnVectors.ofInt(result, "C1").toArray()); + assertArrayEquals(new char[] {'2', '2', '1', '1'}, ColumnVectors.ofChar(result, "C2").toArray()); + assertArrayEquals(new String[] {"b", "a", "d", "c"}, + ColumnVectors.ofObject(result, "Witness", String.class).toArray()); final ColumnHolder c3 = TstUtils.colIndexed("Unsorted", '3', '1', '2', null); result = newTable(c3, col("DataToSort", "c", "a", "b", "d")).sort("Unsorted"); show(result); - assertEquals(Arrays.asList(null, '1', '2', '3'), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 4))); - assertEquals(Arrays.asList("d", "a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 4))); + assertArrayEquals(new char[] {NULL_CHAR, '1', '2', '3'}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"d", "a", "b", "c"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); final ColumnHolder c4 = TstUtils.colIndexed("Unsorted", '3', '1', null, '2'); result = newTable(c4, col("DataToSort", "c", "a", "d", "b")).sortDescending("Unsorted"); - assertEquals(Arrays.asList('3', '2', '1', null), - Arrays.asList(DataAccessHelpers.getColumn(result, "Unsorted").get(0, 4))); - assertEquals(Arrays.asList("c", "b", "a", "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "DataToSort").get(0, 4))); + assertArrayEquals(new char[] {'3', '2', '1', NULL_CHAR}, ColumnVectors.ofChar(result, "Unsorted").toArray()); + assertArrayEquals(new String[] {"c", "b", "a", "d"}, + ColumnVectors.ofObject(result, "DataToSort", String.class).toArray()); } public void testSort2() { diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java index 8ebf8ed34ce..d48731af680 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java @@ -31,6 +31,7 @@ import io.deephaven.engine.table.impl.sources.NullValueColumnSource; import io.deephaven.engine.table.impl.util.BarrageMessage; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; @@ -94,10 +95,8 @@ public void testUngroupWithNullSecondColumn() { updateGraph.runWithinUnitTestCycle(() -> { final RowSet mods = i(0, 2); addToTable(qt, mods, - col("C1", null, - new int[] {4, 5, 6}), - col("C2", null, - new int[] {6, 5, 4})); + col("C1", null, new int[] {4, 5, 6}), + col("C2", null, new int[] {6, 5, 4})); qt.notifyListeners(i(), i(), mods); }); final QueryTable expected = testTable( @@ -162,11 +161,11 @@ public void testIds6532() { * compile the formula. Prior to the second update to IDS-6532, this threw an exception, although typically only by * OpenAPI code (because that code uses validateSelect() whereas other code tends not to). The issue is that this * sequence of operations works: - * + *

* initDef() get compiled formula initDef() get compiled formula - * + *

* But (prior to this change) this sequence of operations would not work: initDef() initDef() get compiled formula - * + *

* The reason the second one breaks is that (prior to this change), when using certain Time literals, the second * initDef() changes Formula state in such a way that a subsequent compilation would not succeed. The reason this * break was not observed in practice is that most usages are like the first example: there is a compilation request @@ -202,7 +201,7 @@ public void testIds6760() { final Table t = emptyTable(10).select("II = ii").where("II > 5"); final SelectColumn sc = SelectColumnFactory.getExpression("XX = II + 1000"); ((QueryTable) t).validateSelect(sc); - final Table result = t.select(List.of(sc)); + t.select(List.of(sc)); } public void testIds1822() { @@ -234,7 +233,7 @@ public void testIds1822() { public void testViewIncremental() { final Random random = new Random(0); - final ColumnInfo[] columnInfo; + final ColumnInfo[] columnInfo; final int size = 50; final QueryTable queryTable = getTable(size, random, columnInfo = initColumnInfos(new String[] {"Sym", "intCol", "doubleCol"}, @@ -302,18 +301,13 @@ public void testView() { TableTools.emptyTable(3).updateView("MinEdge = (IsIndex ? indexMinEdge : MEF * LnRatioStd) * VegaPer"); final QueryTable table0 = (QueryTable) TableTools.emptyTable(3).view("x = i*2", "y = \"\" + x"); - assertEquals(Arrays.asList(0, 2, 4), - Arrays.asList(DataAccessHelpers.getColumn(table0, "x").get(0, table0.size()))); - assertEquals(Arrays.asList("0", "2", "4"), - Arrays.asList(DataAccessHelpers.getColumn(table0, "y").get(0, table0.size()))); + assertArrayEquals(new int[] {0, 2, 4}, ColumnVectors.ofInt(table0, "x").toArray()); + assertArrayEquals(new String[] {"0", "2", "4"}, ColumnVectors.ofObject(table0, "y", String.class).toArray()); final QueryTable table = (QueryTable) table0.updateView("z = x + 1", "x = z + 1", "t = x - 3"); - assertEquals(Arrays.asList(1, 3, 5), - Arrays.asList(DataAccessHelpers.getColumn(table, "z").get(0, table.size()))); - assertEquals(Arrays.asList(2, 4, 6), - Arrays.asList(DataAccessHelpers.getColumn(table, "x").get(0, table.size()))); - assertEquals(Arrays.asList(-1, 1, 3), - Arrays.asList(DataAccessHelpers.getColumn(table, "t").get(0, table.size()))); + assertArrayEquals(new int[] {1, 3, 5}, ColumnVectors.ofInt(table, "z").toArray()); + assertArrayEquals(new int[] {2, 4, 6}, ColumnVectors.ofInt(table, "x").toArray()); + assertArrayEquals(new int[] {-1, 1, 3}, ColumnVectors.ofInt(table, "t").toArray()); final QueryTable table1 = testRefreshingTable(i(2, 4, 6).toTracking(), col("x", 1, 2, 3), col("y", 'a', 'b', 'c')); @@ -433,14 +427,12 @@ public void testView1() { final Table t2 = t.view("y=x && true"); TableTools.merge(t1, t2); TableTools.merge(t2, t1); - assertNull(DataAccessHelpers.getColumn(t.updateView("nullD = NULL_DOUBLE + 0"), "nullD").get(0)); + Table table2 = t.updateView("nullD = NULL_DOUBLE + 0"); + assertNull(table2.getColumnSource("nullD").get(table2.getRowSet().firstRowKey())); - assertEquals( - Arrays.asList(DataAccessHelpers - .getColumn(emptyTable(4).updateView("b1 = (i%2 = 0)?null:true").updateView("x = b1 == null?1:2") - .select("x"), "x") - .get(0, 4)), - Arrays.asList(1, 2, 1, 2)); + Table table1 = emptyTable(4).updateView("b1 = (i%2 = 0)?null:true").updateView("x = b1 == null?1:2") + .select("x"); + assertArrayEquals(new int[] {1, 2, 1, 2}, ColumnVectors.ofInt(table1, "x").toArray()); Table table = newTable(3, Arrays.asList("String", "Int"), Arrays.asList(TableTools.objColSource("c", "e", "g"), TableTools.colSource(2, 4, 6))); @@ -472,20 +464,21 @@ public void testView1() { table = TableTools.emptyTable(3); table = table.view("x = i*2", "y = \"\" + x"); - assertEquals(Arrays.asList(0, 2, 4), Arrays.asList(DataAccessHelpers.getColumn(table, "x").get(0, 3))); - assertEquals(Arrays.asList("0", "2", "4"), Arrays.asList(DataAccessHelpers.getColumn(table, "y").get(0, 3))); + assertArrayEquals(new int[] {0, 2, 4}, ColumnVectors.ofInt(table, "x").toArray()); + assertArrayEquals(new String[] {"0", "2", "4"}, ColumnVectors.ofObject(table, "y", String.class).toArray()); table = table.updateView("z = x + 1", "x = z + 1", "t = x - 3"); - assertEquals(Arrays.asList(1, 3, 5), Arrays.asList(DataAccessHelpers.getColumn(table, "z").get(0, 3))); - assertEquals(Arrays.asList(2, 4, 6), Arrays.asList(DataAccessHelpers.getColumn(table, "x").get(0, 3))); - assertEquals(Arrays.asList(-1, 1, 3), Arrays.asList(DataAccessHelpers.getColumn(table, "t").get(0, 3))); + assertArrayEquals(new int[] {1, 3, 5}, ColumnVectors.ofInt(table, "z").toArray()); + assertArrayEquals(new int[] {2, 4, 6}, ColumnVectors.ofInt(table, "x").toArray()); + assertArrayEquals(new int[] {-1, 1, 3}, ColumnVectors.ofInt(table, "t").toArray()); } public void testReinterpret() { final Table source = emptyTable(5).select("dt = epochNanosToInstant(ii)", "n = ii"); final Table result = source.updateView(List.of( new ReinterpretedColumn<>("dt", Instant.class, "dt", long.class))); - assertEquals((long[]) DataAccessHelpers.getColumn(result, 0).getDirect(), LongStream.range(0, 5).toArray()); + assertArrayEquals(LongStream.range(0, 5).toArray(), + ColumnVectors.ofLong(result, result.getDefinition().getColumns().get(0).getName()).toArray()); final Table reflexive = result.updateView(List.of( new ReinterpretedColumn<>("dt", long.class, "dt", Instant.class))); assertTableEquals(reflexive, source); @@ -556,7 +549,8 @@ public void testDropColumns() { } catch (RuntimeException ignored) { } try { - DataAccessHelpers.getColumn(table.dropColumns("String", "Int"), "Int"); + Table table1 = table.dropColumns("String", "Int"); + ColumnVectors.of(table1, "Int"); fail("Expected exception"); } catch (RuntimeException ignored) { } @@ -620,68 +614,79 @@ public void testRenameColumns() { assertEquals(3, table.renameColumns("NewInt=Int").numColumns()); assertEquals(table.getColumnSources().toArray()[0], table.renameColumns("NewInt=Int").getColumnSources().toArray()[0]); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, 1).getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), 1).getDirect()); + Table table5 = table.renameColumns("NewInt=Int"); + assertEquals( + ColumnVectors.of(table, table.getDefinition().getColumns().get(1).getName()), + ColumnVectors.of(table5, table5.getDefinition().getColumns().get(1).getName())); assertEquals(table.getColumnSources().toArray()[2], table.renameColumns("NewInt=Int").getColumnSources().toArray()[2]); assertEquals(table.getColumnSource("String"), table.renameColumns("NewInt=Int").getColumnSource("String")); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), "NewInt").getDirect()); + Table table11 = table.renameColumns("NewInt=Int"); + assertEquals(ColumnVectors.of(table, "Int"), ColumnVectors.of(table11, "NewInt")); assertEquals(table.getColumnSource("Double"), table.renameColumns("NewInt=Int").getColumnSource("Double")); try { - DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), "Int"); + Table table1 = table.renameColumns("NewInt=Int"); + ColumnVectors.of(table1, "Int"); fail("Expected exception"); } catch (RuntimeException ignored) { } assertEquals(3, table.renameColumns("NewInt=Int", "NewString=String").numColumns()); - assertArrayEquals((String[]) DataAccessHelpers.getColumn(table, 0).getDirect(), - (String[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int", "NewString=String"), 0) - .getDirect()); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, 1).getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), 1).getDirect()); + Table table4 = table.renameColumns("NewInt=Int", "NewString=String"); + assertEquals( + ColumnVectors.of(table, table.getDefinition().getColumns().get(0).getName()), + ColumnVectors.of(table4, table4.getDefinition().getColumns().get(0).getName())); + Table table3 = table.renameColumns("NewInt=Int"); + assertEquals( + ColumnVectors.of(table, table.getDefinition().getColumns().get(1).getName()), + ColumnVectors.of(table3, table3.getDefinition().getColumns().get(1).getName())); assertEquals(table.getColumnSources().toArray()[2], table.renameColumns("NewInt=Int", "NewString=String").getColumnSources().toArray()[2]); - assertArrayEquals((String[]) DataAccessHelpers.getColumn(table, "String").getDirect(), - (String[]) DataAccessHelpers - .getColumn(table.renameColumns("NewInt=Int", "NewString=String"), "NewString").getDirect()); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), "NewInt").getDirect()); + Table table10 = table.renameColumns("NewInt=Int", "NewString=String"); + assertEquals(ColumnVectors.of(table, "String"), ColumnVectors.of(table10, "NewString")); + Table table9 = table.renameColumns("NewInt=Int"); + assertEquals(ColumnVectors.of(table, "Int"), ColumnVectors.of(table9, "NewInt")); assertEquals(table.getColumnSource("Double"), table.renameColumns("NewInt=Int", "NewString=String").getColumnSource("Double")); try { - DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int", "NewString=String"), "Int"); + Table table1 = table.renameColumns("NewInt=Int", "NewString=String"); + ColumnVectors.of(table1, "Int"); fail("Expected exception"); } catch (RuntimeException ignored) { } try { - DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int", "NewString=String"), "String"); + Table table1 = table.renameColumns("NewInt=Int", "NewString=String"); + ColumnVectors.of(table1, "String"); fail("Expected exception"); } catch (RuntimeException ignored) { } assertEquals(3, table.renameColumns("NewInt=Int").renameColumns("NewString=String").numColumns()); - assertArrayEquals((String[]) DataAccessHelpers.getColumn(table, 0).getDirect(), - (String[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int", "NewString=String"), 0) - .getDirect()); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, 1).getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), 1).getDirect()); + Table table2 = table.renameColumns("NewInt=Int", "NewString=String"); + assertEquals( + ColumnVectors.of(table, table.getDefinition().getColumns().get(0).getName()), + ColumnVectors.of(table2, table2.getDefinition().getColumns().get(0).getName())); + Table table1 = table.renameColumns("NewInt=Int"); + assertEquals( + ColumnVectors.of(table, table.getDefinition().getColumns().get(1).getName()), + ColumnVectors.of(table1, table1.getDefinition().getColumns().get(1).getName())); assertEquals(table.getColumnSources().toArray()[2], table.renameColumns("NewInt=Int").renameColumns("NewString=String").getColumnSources().toArray()[2]); - assertArrayEquals((String[]) DataAccessHelpers.getColumn(table, "String").getDirect(), - (String[]) DataAccessHelpers - .getColumn(table.renameColumns("NewInt=Int", "NewString=String"), "NewString").getDirect()); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int"), "NewInt").getDirect()); + Table table8 = table.renameColumns("NewInt=Int", "NewString=String"); + assertEquals(ColumnVectors.of(table, "String"), ColumnVectors.of(table8, "NewString")); + Table table7 = table.renameColumns("NewInt=Int"); + assertEquals(ColumnVectors.of(table, "Int"), ColumnVectors.of(table7, "NewInt")); assertEquals(table.getColumnSource("Double"), table.renameColumns("NewInt=Int").renameColumns("NewString=String").getColumnSource("Double")); try { - DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int").renameColumns("NewString=String"), "Int"); + Table table6 = table.renameColumns("NewInt=Int").renameColumns("NewString=String"); + ColumnVectors.of(table6, "Int"); fail("Expected exception"); } catch (RuntimeException ignored) { } try { - DataAccessHelpers.getColumn(table.renameColumns("NewInt=Int").renameColumns("NewString=String"), "String"); + Table table6 = table.renameColumns("NewInt=Int").renameColumns("NewString=String"); + ColumnVectors.of(table6, "String"); fail("Expected exception"); } catch (RuntimeException ignored) { } @@ -961,7 +966,6 @@ public void testStringMatchFilterIndexed() { // MatchFilters (currently) only use indexes on initial creation but this incremental test will recreate // index-enabled match filtered tables and compare them against incremental non-indexed filtered tables. - Function filter = ConditionFilter::createConditionFilter; final Random random = new Random(0); final int size = 500; @@ -1118,38 +1122,30 @@ public void testInstantRangeFilter() { final EvalNuggetInterface[] en = new EvalNuggetInterface[] { new TableComparator( - table.where(filter.apply( - "Timestamp >= '" + lower.toString() + "' && Timestamp <= '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp >= '" + lower + "' && Timestamp <= '" + upper + "'")), "Condition", table.where(new InstantRangeFilter("Timestamp", lower, upper, true, true)), "Range"), new TableComparator( - table.where(filter.apply( - "Timestamp >= '" + lower.toString() + "' && Timestamp < '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp >= '" + lower + "' && Timestamp < '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, true, false))), new TableComparator( - table.where(filter.apply( - "Timestamp > '" + lower.toString() + "' && Timestamp <= '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp > '" + lower + "' && Timestamp <= '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, true, true))), new TableComparator( - table.where(filter.apply( - "Timestamp > '" + lower.toString() + "' && Timestamp < '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp > '" + lower + "' && Timestamp < '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, false, false))), new TableComparator( - table.where( - filter.apply("Ts2 >= '" + lower.toString() + "' && Ts2 <= '" + upper.toString() + "'")), + table.where(filter.apply("Ts2 >= '" + lower + "' && Ts2 <= '" + upper + "'")), "Condition", table.where(new InstantRangeFilter("Ts2", lower, upper, true, true)), "Range"), new TableComparator( - table.where( - filter.apply("Ts2 >= '" + lower.toString() + "' && Ts2 < '" + upper.toString() + "'")), + table.where(filter.apply("Ts2 >= '" + lower + "' && Ts2 < '" + upper + "'")), table.where(new InstantRangeFilter("Ts2", lower, upper, true, false))), new TableComparator( - table.where( - filter.apply("Ts2 > '" + lower.toString() + "' && Ts2 <= '" + upper.toString() + "'")), + table.where(filter.apply("Ts2 > '" + lower + "' && Ts2 <= '" + upper + "'")), table.where(new InstantRangeFilter("Ts2", lower, upper, true, true))), new TableComparator( - table.where( - filter.apply("Ts2 > '" + lower.toString() + "' && Ts2 < '" + upper.toString() + "'")), + table.where(filter.apply("Ts2 > '" + lower + "' && Ts2 < '" + upper + "'")), table.where(new InstantRangeFilter("Ts2", lower, upper, false, false))) }; @@ -1178,21 +1174,17 @@ public void testInstantRangeFilterNulls() { final EvalNuggetInterface[] en = new EvalNuggetInterface[] { new TableComparator( - table.where(filter.apply( - "Timestamp >= '" + lower.toString() + "' && Timestamp <= '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp >= '" + lower + "' && Timestamp <= '" + upper + "'")), "Condition", table.where(new InstantRangeFilter("Timestamp", lower, upper, true, true)), "Range"), new TableComparator( - table.where(filter.apply( - "Timestamp >= '" + lower.toString() + "' && Timestamp < '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp >= '" + lower + "' && Timestamp < '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, true, false))), new TableComparator( - table.where(filter.apply( - "Timestamp > '" + lower.toString() + "' && Timestamp <= '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp > '" + lower + "' && Timestamp <= '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, true, true))), new TableComparator( - table.where(filter.apply( - "Timestamp > '" + lower.toString() + "' && Timestamp < '" + upper.toString() + "'")), + table.where(filter.apply("Timestamp > '" + lower + "' && Timestamp < '" + upper + "'")), table.where(new InstantRangeFilter("Timestamp", lower, upper, false, false))), }; @@ -1223,13 +1215,13 @@ public void testReverse() { checkReverse(table, reversed, "Ticker"); - assertEquals("TSLA", reversed.getColumnSource("Ticker").getPrev(reversed.getRowSet().copyPrev().get(0))); + assertEquals("TSLA", reversed.getColumnSource("Ticker").getPrev(reversed.getRowSet().prev().firstRowKey())); updateGraph.runWithinUnitTestCycle(() -> { }); - assertEquals("VXX", reversed.getColumnSource("Ticker").getPrev(reversed.getRowSet().copyPrev().get(0))); + assertEquals("VXX", reversed.getColumnSource("Ticker").getPrev(reversed.getRowSet().prev().firstRowKey())); final ColumnSource longIdentityColumnSource = @@ -1253,11 +1245,10 @@ public long getLong(long rowKey) { Collections.singletonMap("LICS", longIdentityColumnSource)); bigTable.setRefreshing(true); final Table bigReversed = bigTable.reverse(); - // noinspection unchecked - final DataColumn licsr = DataAccessHelpers.getColumn(bigReversed, "LICS"); - assertEquals((long) Integer.MAX_VALUE * 2L, (long) licsr.get(0)); - assertEquals(Integer.MAX_VALUE, (long) licsr.get(1)); - assertEquals(0, (long) licsr.get(2)); + final LongVector licsr = ColumnVectors.ofLong(bigReversed, "LICS"); + assertEquals((long) Integer.MAX_VALUE * 2L, licsr.get(0)); + assertEquals(Integer.MAX_VALUE, licsr.get(1)); + assertEquals(0, licsr.get(2)); updateGraph.runWithinUnitTestCycle(() -> { bigTable.getRowSet().writableCast().insert(Long.MAX_VALUE); @@ -1266,10 +1257,10 @@ public long getLong(long rowKey) { assertEquals(4, bigReversed.size()); - assertEquals(Long.MAX_VALUE, (long) licsr.get(0)); - assertEquals((long) Integer.MAX_VALUE * 2L, (long) licsr.get(1)); - assertEquals(Integer.MAX_VALUE, (long) licsr.get(2)); - assertEquals(0, (long) licsr.get(3)); + assertEquals(Long.MAX_VALUE, licsr.get(0)); + assertEquals((long) Integer.MAX_VALUE * 2L, licsr.get(1)); + assertEquals(Integer.MAX_VALUE, licsr.get(2)); + assertEquals(0, licsr.get(3)); } @@ -1315,8 +1306,9 @@ private void checkReverse(QueryTable table, Table reversed, String timestamp) { assertEquals(table.size(), reversed.size()); for (long ii = 0; ii < table.size(); ++ii) { final long jj = table.size() - ii - 1; - assertEquals(DataAccessHelpers.getColumn(table, timestamp).get(ii), - DataAccessHelpers.getColumn(reversed, timestamp).get(jj)); + assertEquals( + ColumnVectors.ofObject(table, timestamp, Object.class).get(ii), + ColumnVectors.ofObject(reversed, timestamp, Object.class).get(jj)); } } @@ -1730,7 +1722,7 @@ public void testSnapshotDependencies() { TableTools.show(snappedOfSnap); TestCase.assertEquals(1, snappedOfSnap.size()); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(snappedOfSnap, "B").get(0)); + TestCase.assertEquals(2, snappedOfSnap.getColumnSource("B").getInt(snappedOfSnap.getRowSet().firstRowKey())); } public void testSnapshotAdditions() { @@ -1848,7 +1840,7 @@ public void testSnapshotIncrementalDependencies() { System.out.println("Checking satisfaction after #3."); flushed2 = updateGraph.flushOneNotificationForUnitTests(); - // this will do the merged notification; which means the snaphsot is satisfied + // this will do the merged notification; which means the snapshot is satisfied TestCase.assertTrue(flushed2); TestCase.assertTrue( snappedFirst.satisfied(ExecutionContext.getContext().getUpdateGraph().clock().currentStep())); @@ -1894,7 +1886,7 @@ public void testSnapshotIncrementalDependencies() { TableTools.show(snappedOfSnap); TestCase.assertEquals(snappedOfSnap.size(), 1); - TestCase.assertEquals(DataAccessHelpers.getColumn(snappedOfSnap, "B").get(0), 1); + TestCase.assertEquals(snappedOfSnap.getColumnSource("B").getInt(snappedOfSnap.getRowSet().firstRowKey()), 1); // this will do the notification for right; at which point we can should get the update going through // nothing left @@ -1943,7 +1935,7 @@ public void testSnapshotIncrementalDependencies() { TableTools.show(snappedOfSnap); TestCase.assertEquals(snappedOfSnap.size(), 1); - TestCase.assertEquals(DataAccessHelpers.getColumn(snappedOfSnap, "B").get(0), 1); + TestCase.assertEquals(snappedOfSnap.getColumnSource("B").getInt(snappedOfSnap.getRowSet().firstRowKey()), 1); // now we should flush the select // now we should flush the second snapshot recorder @@ -2050,7 +2042,7 @@ public void testSnapshotIncrementalDependencies() { TableTools.show(snappedOfSnap); TestCase.assertEquals(snappedOfSnap.size(), 2); - TestCase.assertEquals(DataAccessHelpers.getColumn(snappedOfSnap, "B").get(0), 2); + TestCase.assertEquals(snappedOfSnap.getColumnSource("B").getInt(snappedOfSnap.getRowSet().firstRowKey()), 2); } public void testWhereInScope() { @@ -2080,7 +2072,7 @@ public void testWhereInScope() { ExecutionContext.getContext().getUpdateGraph().cast().completeCycleForUnitTests(); assertEquals(1, whereIn.size()); - assertEquals(new Object[] {"B", 2}, DataAccessHelpers.getRecord(whereIn, 0)); + assertEquals(new Object[] {"B", 2}, getRowData(whereIn, 0)); assertTrue(whereIn.tryRetainReference()); whereIn.dropReference(); @@ -2094,8 +2086,8 @@ public void testWhereInScope() { ExecutionContext.getContext().getUpdateGraph().cast().completeCycleForUnitTests(); assertEquals(2, whereIn.size()); - assertEquals(new Object[] {"B", 2}, DataAccessHelpers.getRecord(whereIn, 0)); - assertEquals(new Object[] {"D", 4}, DataAccessHelpers.getRecord(whereIn, 1)); + assertEquals(new Object[] {"B", 2}, getRowData(whereIn, 0)); + assertEquals(new Object[] {"D", 4}, getRowData(whereIn, 1)); // Everything is dropped after this, the singletonManager was holding everything. ExecutionContext.getContext().getUpdateGraph().exclusiveLock().doLocked(singletonManager::release); @@ -2394,13 +2386,10 @@ public void testSnapshotIncrementalRandom() { } // and anything unmodified should be the same as last time - @SuppressWarnings("unchecked") - final DataColumn lastStamps = DataAccessHelpers.getColumn(lastSnapshot, "Stamp"); + final ColumnSource lastStamps = lastSnapshot.getColumnSource("Stamp", int.class); for (final RowSet.Iterator it = unmodified.iterator(); it.hasNext();) { final long next = it.nextLong(); - final long lastPos = lastRowSet.find(next); - assertTrue(lastPos >= 0); - final int priorStamp = lastStamps.getInt((int) lastPos); + final int priorStamp = lastStamps.getInt(next); final int stamp = stamps.getInt(next); assertEquals(priorStamp, stamp); } @@ -2644,18 +2633,18 @@ public void testUngroupingAgnostic() { Table t1 = table.ungroup("Y", "Z"); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 3, 3), Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 5))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 5))); - assertEquals(Arrays.asList(4, 5, 6, 7, 8), Arrays.asList(DataAccessHelpers.getColumn(t1, "Z").get(0, 5))); + assertArrayEquals(new int[] {1, 1, 1, 3, 3}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); + assertArrayEquals(new int[] {4, 5, 6, 7, 8}, ColumnVectors.ofInt(t1, "Z").toArray()); t1 = table.ungroup(); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 3, 3), Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 5))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 5))); - assertEquals(Arrays.asList(4, 5, 6, 7, 8), Arrays.asList(DataAccessHelpers.getColumn(t1, "Z").get(0, 5))); + assertArrayEquals(new int[] {1, 1, 1, 3, 3}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); + assertArrayEquals(new int[] {4, 5, 6, 7, 8}, ColumnVectors.ofInt(t1, "Z").toArray()); int[][] data = new int[][] {new int[] {4, 5, 6}, new int[0], new int[] {7, 8}}; table = testRefreshingTable(col("X", 1, 2, 3), @@ -2681,36 +2670,32 @@ public void testUngroupingAgnostic() { t1 = table.ungroup("Y"); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2), Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 5))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 5))); + assertArrayEquals(new int[] {1, 1, 1, 2, 2}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); show(t1); show(t1.ungroup("Z")); t1 = t1.ungroup("Z"); assertEquals(9, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1), - Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 9))); - assertEquals(Arrays.asList("a", "a", "a", "b", "b", "b", "c", "c", "c"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 9))); - assertEquals(Arrays.asList(4, 5, 6, 4, 5, 6, 4, 5, 6), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Z").get(0, 9))); + assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "a", "a", "b", "b", "b", "c", "c", "c"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); + assertArrayEquals(new int[] {4, 5, 6, 4, 5, 6, 4, 5, 6}, ColumnVectors.ofInt(t1, "Z").toArray()); t1 = table.ungroup("Z"); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 3, 3), Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 5))); - assertEquals(Arrays.asList(4, 5, 6, 7, 8), Arrays.asList(DataAccessHelpers.getColumn(t1, "Z").get(0, 5))); + assertArrayEquals(new int[] {1, 1, 1, 3, 3}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new int[] {4, 5, 6, 7, 8}, ColumnVectors.ofInt(t1, "Z").toArray()); t1 = t1.ungroup("Y"); assertEquals(9, t1.size()); assertEquals(Arrays.asList("X", "Y", "Z"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1), - Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 9))); - assertEquals(Arrays.asList(4, 4, 4, 5, 5, 5, 6, 6, 6), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Z").get(0, 9))); - assertEquals(Arrays.asList("a", "b", "c", "a", "b", "c", "a", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 9))); + assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new int[] {4, 4, 4, 5, 5, 5, 6, 6, 6}, ColumnVectors.ofInt(t1, "Z").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "a", "b", "c", "a", "b", "c"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); } public void testUngroupConstructSnapshotOfBoxedNull() { @@ -2761,7 +2746,7 @@ public void testUngroupableColumnSources() { final Table t11 = t9.sortDescending("X").ungroup(); assertTableEquals(t11, t7); - final int[] intDirect = (int[]) DataAccessHelpers.getColumn(t2, "Int").getDirect(); + final int[] intDirect = (int[]) ColumnVectors.of(t2, "Int").toArray(); System.out.println(Arrays.toString(intDirect)); final int[] expected = new int[] {1, 2, 3, 4, 5, 6, 7, io.deephaven.util.QueryConstants.NULL_INT}; @@ -2800,9 +2785,9 @@ public void testUngroupOverflow() { final QueryTable t1 = (QueryTable) table.ungroup("Y"); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2), Arrays.asList(DataAccessHelpers.getColumn(t1, "X").get(0, 5))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), - Arrays.asList(DataAccessHelpers.getColumn(t1, "Y").get(0, 5))); + assertArrayEquals(new int[] {1, 1, 1, 2, 2}, ColumnVectors.ofInt(t1, "X").subVector(0, 5).toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class).subVector(0, 5).toArray()); final ErrorListener errorListener = new ErrorListener(t1); t1.addUpdateListener(errorListener); @@ -2838,10 +2823,9 @@ public void testUngroupWithRebase() { final QueryTable t1 = (QueryTable) table.ungroup("Y"); assertEquals(5, t1.size()); assertEquals(Arrays.asList("X", "Y"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2), - Ints.asList((int[]) DataAccessHelpers.getColumn(t1, "X").getDirect())); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), - Arrays.asList((String[]) DataAccessHelpers.getColumn(t1, "Y").getDirect())); + assertArrayEquals(new int[] {1, 1, 1, 2, 2}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); validateUpdates(t1); // This is too big, we should fail @@ -2854,10 +2838,9 @@ public void testUngroupWithRebase() { TableTools.showWithRowSet(t1); assertEquals(Arrays.asList("X", "Y"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3), - Ints.asList((int[]) (DataAccessHelpers.getColumn(t1, "X").getDirect()))); - assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), - Arrays.asList((String[]) DataAccessHelpers.getColumn(t1, "Y").getDirect())); + assertArrayEquals(new int[] {1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); assertEquals(Arrays.asList(1, 1, 1, 2, 2), Ints.asList( (int[]) IndexedDataColumn.makePreviousColumn(t1.getRowSet(), t1.getColumnSource("X")).getDirect())); @@ -2868,10 +2851,10 @@ public void testUngroupWithRebase() { }); assertEquals(Arrays.asList("X", "Y"), t1.getDefinition().getColumnNames()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3), - Ints.asList((int[]) DataAccessHelpers.getColumn(t1, "X").getDirect())); - assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), - Arrays.asList((String[]) DataAccessHelpers.getColumn(t1, "Y").getDirect())); + assertArrayEquals(new int[] {1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3}, ColumnVectors.ofInt(t1, "X").toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}, + ColumnVectors.ofObject(t1, "Y", String.class).toArray()); + assertEquals(Arrays.asList(1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3), Ints.asList( (int[]) IndexedDataColumn.makePreviousColumn(t1.getRowSet(), t1.getColumnSource("X")).getDirect())); assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), @@ -3244,12 +3227,9 @@ public void testMemoize() { } public void testMemoizeConcurrent() { - final ExecutorService dualPool = Executors.newFixedThreadPool(2, new ThreadFactory() { - @Override - public Thread newThread(Runnable runnable) { - ExecutionContext captured = ExecutionContext.getContext(); - return new Thread(() -> captured.apply(runnable)); - } + final ExecutorService dualPool = Executors.newFixedThreadPool(2, runnable -> { + ExecutionContext captured = ExecutionContext.getContext(); + return new Thread(() -> captured.apply(runnable)); }); final boolean old = QueryTable.setMemoizeResults(true); @@ -3571,9 +3551,8 @@ public void testDeferredGroupingPropagationInstantCol() { final Table t2 = t1.select("T"); - // noinspection rawtypes - final ColumnSource result = t2.getColumnSource("T"); - final ColumnSource reinterpreted = result.reinterpret(long.class); + final ColumnSource result = t2.getColumnSource("T"); + final ColumnSource reinterpreted = result.reinterpret(long.class); assertTrue(DataIndexer.of(t1.getRowSet()).hasDataIndex(cs)); assertTrue(DataIndexer.of(t2.getRowSet()).hasDataIndex(result)); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWhereTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWhereTest.java index 65343454965..dafc65cfe97 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWhereTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWhereTest.java @@ -26,6 +26,7 @@ import io.deephaven.engine.table.impl.sources.RowKeyColumnSource; import io.deephaven.engine.table.impl.sources.UnionRedirection; import io.deephaven.engine.table.impl.verify.TableAssertions; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.QueryTableTestBase.TableComparator; import io.deephaven.engine.testutil.generator.*; @@ -57,12 +58,10 @@ import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.printTableUpdates; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.simulateShiftAwareStep; import static io.deephaven.engine.util.TableTools.*; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.*; public abstract class QueryTableWhereTest { - private Logger log = LoggerFactory.getLogger(QueryTableWhereTest.class); + private final Logger log = LoggerFactory.getLogger(QueryTableWhereTest.class); @Rule public final EngineCleanup base = new EngineCleanup(); @@ -341,9 +340,9 @@ public void testWhereDynamicIn() { () -> filteredTable.whereNotIn(setTable, "X")); show(result); assertEquals(3, result.size()); - assertEquals(asList("A", "B", "C"), asList((String[]) DataAccessHelpers.getColumn(result, "X").getDirect())); + assertArrayEquals(new String[] {"A", "B", "C"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); assertEquals(2, resultInverse.size()); - assertEquals(asList("D", "E"), asList((String[]) DataAccessHelpers.getColumn(resultInverse, "X").getDirect())); + assertArrayEquals(new String[] {"D", "E"}, ColumnVectors.ofObject(resultInverse, "X", String.class).toArray()); updateGraph.runWithinUnitTestCycle(() -> { addToTable(filteredTable, i(6), col("X", "A")); @@ -351,10 +350,10 @@ public void testWhereDynamicIn() { }); show(result); assertEquals(4, result.size()); - assertEquals(asList("A", "B", "C", "A"), - asList((String[]) DataAccessHelpers.getColumn(result, "X").getDirect())); + assertArrayEquals(new String[] {"A", "B", "C", "A"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); assertEquals(2, resultInverse.size()); - assertEquals(asList("D", "E"), asList((String[]) DataAccessHelpers.getColumn(resultInverse, "X").getDirect())); + assertArrayEquals(new String[] {"D", "E"}, ColumnVectors.ofObject(resultInverse, "X", String.class).toArray()); updateGraph.runWithinUnitTestCycle(() -> { addToTable(setTable, i(7), col("X", "D")); @@ -362,10 +361,10 @@ public void testWhereDynamicIn() { }); showWithRowSet(result); assertEquals(5, result.size()); - assertEquals(asList("A", "B", "C", "D", "A"), - asList((String[]) DataAccessHelpers.getColumn(result, "X").getDirect())); + assertArrayEquals(new String[] {"A", "B", "C", "D", "A"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); assertEquals(1, resultInverse.size()); - assertEquals(asList("E"), asList((String[]) DataAccessHelpers.getColumn(resultInverse, "X").getDirect())); + assertArrayEquals(new String[] {"E"}, ColumnVectors.ofObject(resultInverse, "X", String.class).toArray()); // Real modification to set table, followed by spurious modification to set table IntStream.range(0, 2).forEach(ri -> { @@ -375,11 +374,11 @@ public void testWhereDynamicIn() { }); showWithRowSet(result); assertEquals(4, result.size()); - assertEquals(asList("A", "B", "C", "A"), - asList((String[]) DataAccessHelpers.getColumn(result, "X").getDirect())); + assertArrayEquals(new String[] {"A", "B", "C", "A"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); assertEquals(2, resultInverse.size()); - assertEquals(asList("D", "E"), - asList((String[]) DataAccessHelpers.getColumn(resultInverse, "X").getDirect())); + assertArrayEquals(new String[] {"D", "E"}, + ColumnVectors.ofObject(resultInverse, "X", String.class).toArray()); }); } @@ -1273,8 +1272,8 @@ public void testBigTable() { } assertEquals(1_000_000, result.size()); - assertEquals(6_000_000L, DataAccessHelpers.getColumn(result, "A").getLong(0)); - assertEquals(6_999_999L, DataAccessHelpers.getColumn(result, "A").getLong(result.size() - 1)); + assertEquals(6_000_000L, result.getColumnSource("A").getLong(result.getRowSet().firstRowKey())); + assertEquals(6_999_999L, result.getColumnSource("A").getLong(result.getRowSet().get(result.size() - 1))); } @Test @@ -1285,8 +1284,8 @@ public void testBigTableInitial() { final Table result = source.where("A >= 6_000_000L", "A < 7_000_000L"); assertEquals(1_000_000, result.size()); - assertEquals(6_000_000L, DataAccessHelpers.getColumn(result, "A").getLong(0)); - assertEquals(6_999_999L, DataAccessHelpers.getColumn(result, "A").getLong(result.size() - 1)); + assertEquals(6_000_000L, result.getColumnSource("A").getLong(result.getRowSet().firstRowKey())); + assertEquals(6_999_999L, result.getColumnSource("A").getLong(result.getRowSet().get(result.size() - 1))); } @Test @@ -1304,8 +1303,9 @@ public void testBigTableIndexed() { Table sorted = result.sort("A"); show(sorted); - Assert.geq(DataAccessHelpers.getColumn(sorted, "A").getLong(0), "lowest value", 600, "600"); - Assert.leq(DataAccessHelpers.getColumn(sorted, "A").getLong(result.size() - 1), "highest value", 699, "699"); + Assert.geq(sorted.getColumnSource("A").getLong(sorted.getRowSet().firstRowKey()), "lowest value", 600, "600"); + Assert.leq(sorted.getColumnSource("A").getLong(sorted.getRowSet().get(result.size() - 1)), "highest value", 699, + "699"); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWouldMatchTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWouldMatchTest.java index 49944dddad5..97969ef85f6 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWouldMatchTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableWouldMatchTest.java @@ -8,6 +8,7 @@ import io.deephaven.engine.table.ShiftObliviousListener; import io.deephaven.engine.table.WouldMatchPair; import io.deephaven.engine.table.impl.select.DynamicWhereFilter; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import junit.framework.TestCase; @@ -18,6 +19,7 @@ import static io.deephaven.engine.testutil.TstUtils.*; import static io.deephaven.engine.util.TableTools.col; import static io.deephaven.engine.util.TableTools.show; +import static org.junit.Assert.assertArrayEquals; public class QueryTableWouldMatchTest extends QueryTableTestBase { @@ -33,12 +35,12 @@ public void testMatch() { t1Matched.addUpdateListener(t1MatchedListener); show(t1Matched); - assertEquals(Arrays.asList(true, false, true, false, false, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "HasAnE").get(0, 6))); - assertEquals(Arrays.asList(false, false, false, false, true, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "isGt3").get(0, 6))); - assertEquals(Arrays.asList(true, true, true, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "Compound").get(0, 6))); + assertArrayEquals(new Boolean[] {true, false, true, false, false, true}, + ColumnVectors.ofObject(t1Matched, "HasAnE", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, false, false, false, true, true}, + ColumnVectors.ofObject(t1Matched, "isGt3", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, true, true, true, true, false}, + ColumnVectors.ofObject(t1Matched, "Compound", Boolean.class).toArray()); // Add final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -52,12 +54,12 @@ public void testMatch() { assertEquals(added, i(7, 9)); assertEquals(modified, i()); assertEquals(removed, i()); - assertEquals(Arrays.asList(true, false, true, false, false, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "HasAnE").get(0, 8))); - assertEquals(Arrays.asList(false, false, false, false, true, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "isGt3").get(0, 8))); - assertEquals(Arrays.asList(true, true, true, true, true, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "Compound").get(0, 8))); + assertArrayEquals(new Boolean[] {true, false, true, false, false, true, true, false}, + ColumnVectors.ofObject(t1Matched, "HasAnE", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, false, false, false, true, true, true, false}, + ColumnVectors.ofObject(t1Matched, "isGt3", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, true, true, true, true, false, true, false}, + ColumnVectors.ofObject(t1Matched, "Compound", Boolean.class).toArray()); // Remove updateGraph.runWithinUnitTestCycle(() -> { @@ -68,12 +70,12 @@ public void testMatch() { assertEquals(added, i()); assertEquals(modified, i()); assertEquals(removed, i(1, 3)); - assertEquals(Arrays.asList(true, true, false, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "HasAnE").get(0, 8))); - assertEquals(Arrays.asList(false, false, true, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "isGt3").get(0, 8))); - assertEquals(Arrays.asList(true, true, true, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "Compound").get(0, 8))); + assertArrayEquals(new Boolean[] {true, true, false, true, true, false}, + ColumnVectors.ofObject(t1Matched, "HasAnE", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, false, true, true, true, false}, + ColumnVectors.ofObject(t1Matched, "isGt3", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, true, true, false, true, false}, + ColumnVectors.ofObject(t1Matched, "Compound", Boolean.class).toArray()); // Modify updateGraph.runWithinUnitTestCycle(() -> { @@ -87,12 +89,12 @@ public void testMatch() { assertEquals(added, i()); assertEquals(modified, i(4, 5)); assertEquals(removed, i()); - assertEquals(Arrays.asList(true, true, true, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "HasAnE").get(0, 8))); - assertEquals(Arrays.asList(false, false, false, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "isGt3").get(0, 8))); - assertEquals(Arrays.asList(true, true, true, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "Compound").get(0, 8))); + assertArrayEquals(new Boolean[] {true, true, true, false, true, false}, + ColumnVectors.ofObject(t1Matched, "HasAnE", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, false, false, false, true, false}, + ColumnVectors.ofObject(t1Matched, "isGt3", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, true, true, true, true, false}, + ColumnVectors.ofObject(t1Matched, "Compound", Boolean.class).toArray()); // All 3 updateGraph.runWithinUnitTestCycle(() -> { @@ -107,12 +109,12 @@ public void testMatch() { assertEquals(added, i(1, 11)); assertEquals(modified, i(0, 4)); assertEquals(removed, i(9, 5)); - assertEquals(Arrays.asList(true, true, true, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "HasAnE").get(0, 11))); - assertEquals(Arrays.asList(true, false, false, true, true, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "isGt3").get(0, 11))); - assertEquals(Arrays.asList(true, false, true, true, true, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "Compound").get(0, 11))); + assertArrayEquals(new Boolean[] {true, true, true, false, true, false}, + ColumnVectors.ofObject(t1Matched, "HasAnE", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, false, false, true, true, true}, + ColumnVectors.ofObject(t1Matched, "isGt3", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, false, true, true, true, true}, + ColumnVectors.ofObject(t1Matched, "Compound", Boolean.class).toArray()); } public void testMatchRefilter() { @@ -138,10 +140,10 @@ private void doTestMatchRefilter(boolean isRefreshing) { final QueryTable t1Matched = (QueryTable) t1.wouldMatch(sp1, sp2); show(t1Matched); - assertEquals(Arrays.asList(false, false, false, true, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InText").get(0, 6))); - assertEquals(Arrays.asList(true, false, false, false, false, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InNum").get(0, 6))); + assertArrayEquals(new Boolean[] {false, false, false, true, true, false}, + ColumnVectors.ofObject(t1Matched, "InText", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, false, false, false, false, true}, + ColumnVectors.ofObject(t1Matched, "InNum", Boolean.class).toArray()); // Tick one filter table final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -150,10 +152,10 @@ private void doTestMatchRefilter(boolean isRefreshing) { textTable.notifyListeners(i(2), i(), i(0)); }); - assertEquals(Arrays.asList(false, true, false, false, true, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InText").get(0, 6))); - assertEquals(Arrays.asList(true, false, false, false, false, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InNum").get(0, 6))); + assertArrayEquals(new Boolean[] {false, true, false, false, true, true}, + ColumnVectors.ofObject(t1Matched, "InText", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {true, false, false, false, false, true}, + ColumnVectors.ofObject(t1Matched, "InNum", Boolean.class).toArray()); // Tick both of them updateGraph.runWithinUnitTestCycle(() -> { @@ -165,10 +167,10 @@ private void doTestMatchRefilter(boolean isRefreshing) { numberTable.notifyListeners(i(2), i(0), i()); }); - assertEquals(Arrays.asList(true, false, true, false, true, false), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InText").get(0, 6))); - assertEquals(Arrays.asList(false, false, true, false, false, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InNum").get(0, 6))); + assertArrayEquals(new Boolean[] {true, false, true, false, true, false}, + ColumnVectors.ofObject(t1Matched, "InText", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, false, true, false, false, true}, + ColumnVectors.ofObject(t1Matched, "InNum", Boolean.class).toArray()); if (isRefreshing) { // Tick both of them, and the table itself @@ -191,10 +193,10 @@ private void doTestMatchRefilter(boolean isRefreshing) { show(textTable); show(numberTable); - assertEquals(Arrays.asList(true, false, false, false, false, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InText").get(0, 11))); - assertEquals(Arrays.asList(false, true, true, false, true, true), - Arrays.asList(DataAccessHelpers.getColumn(t1Matched, "InNum").get(0, 11))); + assertArrayEquals(new Boolean[] {true, false, false, false, false, true}, + ColumnVectors.ofObject(t1Matched, "InText", Boolean.class).toArray()); + assertArrayEquals(new Boolean[] {false, true, true, false, true, true}, + ColumnVectors.ofObject(t1Matched, "InNum", Boolean.class).toArray()); } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java index f8c3ca06cf2..2cfa95250eb 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java @@ -15,9 +15,9 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.rowset.RowSet; import io.deephaven.engine.table.ColumnSource; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; @@ -40,7 +40,6 @@ import java.util.Collection; import java.util.List; import java.util.Random; -import java.util.Set; import static io.deephaven.api.agg.Aggregation.*; import static io.deephaven.engine.testutil.TstUtils.*; @@ -72,23 +71,23 @@ public void testBy() { "A"); show(minMax); assertEquals(2, minMax.size()); - DataColumn dc = DataAccessHelpers.getColumn(minMax, "Min"); - assertEquals(1, dc.get(0)); - assertEquals(3, dc.get(1)); - dc = DataAccessHelpers.getColumn(minMax, "Max"); - assertEquals(10, dc.get(0)); - assertEquals(8, dc.get(1)); + IntVector mins = ColumnVectors.ofInt(minMax, "Min"); + assertEquals(1, mins.get(0)); + assertEquals(3, mins.get(1)); + IntVector maxes = ColumnVectors.ofInt(minMax, "Max"); + assertEquals(10, maxes.get(0)); + assertEquals(8, maxes.get(1)); Table doubleCounted = table.aggBy(List.of(AggCount("Count1"), AggCount("Count2")), "A"); show(doubleCounted); assertEquals(2, doubleCounted.size()); - dc = DataAccessHelpers.getColumn(doubleCounted, "Count1"); - assertEquals(6L, dc.get(0)); - assertEquals(4L, dc.get(1)); - dc = DataAccessHelpers.getColumn(doubleCounted, "Count2"); - assertEquals(6L, dc.get(0)); - assertEquals(4L, dc.get(1)); + IntVector counts = ColumnVectors.ofInt(doubleCounted, "Count1"); + assertEquals(6L, counts.get(0)); + assertEquals(4L, counts.get(1)); + counts = ColumnVectors.ofInt(doubleCounted, "Count2"); + assertEquals(6L, counts.get(0)); + assertEquals(4L, counts.get(1)); // Lets do some interesting incremental computations, as this is the use case that I'm really aiming at. For // example, getting the count, and average on each update. @@ -498,10 +497,10 @@ public void testComboByCountDistinct() { Table result = dataTable.aggBy(AggCountDistinct("Account", "Qty"), "USym").sort("USym"); Table countNulls = dataTable.aggBy(AggCountDistinct(true, "Account", "Qty"), "USym").sort("USym"); assertEquals(4, result.size()); - assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"GOOG", 2L, 2L}, DataAccessHelpers.getRecord(result, 1)); - assertArrayEquals(new Object[] {"SPY", 3L, 4L}, DataAccessHelpers.getRecord(result, 2)); - assertArrayEquals(new Object[] {"VXX", 1L, 1L}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"GOOG", 2L, 2L}, getRowData(result, 1)); + assertArrayEquals(new Object[] {"SPY", 3L, 4L}, getRowData(result, 2)); + assertArrayEquals(new Object[] {"VXX", 1L, 1L}, getRowData(result, 3)); assertTableEquals(result, countNulls); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -513,11 +512,11 @@ public void testComboByCountDistinct() { dataTable.notifyListeners(i(10), i(), i(1)); }); - assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"VXX", 2L, 1L}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"VXX", 2L, 1L}, getRowData(result, 3)); - assertArrayEquals(new Object[] {"AAPL", 3L, 2L}, DataAccessHelpers.getRecord(countNulls, 0)); - assertArrayEquals(new Object[] {"VXX", 2L, 2L}, DataAccessHelpers.getRecord(countNulls, 3)); + assertArrayEquals(new Object[] {"AAPL", 3L, 2L}, getRowData(countNulls, 0)); + assertArrayEquals(new Object[] {"VXX", 2L, 2L}, getRowData(countNulls, 3)); updateGraph.runWithinUnitTestCycle(() -> { addToTable(dataTable, i(2), @@ -527,8 +526,8 @@ public void testComboByCountDistinct() { dataTable.notifyListeners(i(), i(), i(2)); }); - assertArrayEquals(new Object[] {"AAPL", 1L, 2L}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, DataAccessHelpers.getRecord(countNulls, 0)); + assertArrayEquals(new Object[] {"AAPL", 1L, 2L}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, getRowData(countNulls, 0)); TableTools.showWithRowSet(dataTable, dataTable.size()); @@ -544,8 +543,8 @@ public void testComboByCountDistinct() { TableTools.showWithRowSet(dataTable, dataTable.size()); - assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"SPY", 3L, 3L}, DataAccessHelpers.getRecord(countNulls, 2)); + assertArrayEquals(new Object[] {"AAPL", 2L, 2L}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"SPY", 3L, 3L}, getRowData(countNulls, 2)); } @Test @@ -569,10 +568,10 @@ public void testComboByAggUnique() { AggUnique(true, UnionObject.of(dtDefault), "Whee")), "USym").sort("USym"); assertEquals(4, result.size()); - assertArrayEquals(new Object[] {"AAPL", -1L, 100, dt1}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, DataAccessHelpers.getRecord(result, 1)); - assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, DataAccessHelpers.getRecord(result, 2)); - assertArrayEquals(new Object[] {"VXX", 5L, 50, null}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"AAPL", -1L, 100, dt1}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, getRowData(result, 1)); + assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, getRowData(result, 2)); + assertArrayEquals(new Object[] {"VXX", 5L, 50, null}, getRowData(result, 3)); assertTableEquals(result, countNulls); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); @@ -585,13 +584,13 @@ public void testComboByAggUnique() { dataTable.notifyListeners(i(10), i(), i(2)); }); - assertArrayEquals(new Object[] {"AAPL", 1L, 100, dt1}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, DataAccessHelpers.getRecord(result, 1)); - assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, DataAccessHelpers.getRecord(result, 2)); - assertArrayEquals(new Object[] {"VXX", 5L, 50, null}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"AAPL", 1L, 100, dt1}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, getRowData(result, 1)); + assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, getRowData(result, 2)); + assertArrayEquals(new Object[] {"VXX", 5L, 50, null}, getRowData(result, 3)); // Check the nulls table - assertArrayEquals(new Object[] {"VXX", 5L, -1, null}, DataAccessHelpers.getRecord(countNulls, 3)); + assertArrayEquals(new Object[] {"VXX", 5L, -1, null}, getRowData(countNulls, 3)); updateGraph.runWithinUnitTestCycle(() -> { addToTable(dataTable, i(11), @@ -603,12 +602,12 @@ public void testComboByAggUnique() { dataTable.notifyListeners(i(11), i(9, 10), i()); }); - assertArrayEquals(new Object[] {"AAPL", 1L, 100, dt1}, DataAccessHelpers.getRecord(result, 0)); - assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, DataAccessHelpers.getRecord(result, 1)); - assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, DataAccessHelpers.getRecord(result, 2)); - assertArrayEquals(new Object[] {"USO", 2L, 200, dt1}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"AAPL", 1L, 100, dt1}, getRowData(result, 0)); + assertArrayEquals(new Object[] {"GOOG", -1L, -1, dtDefault}, getRowData(result, 1)); + assertArrayEquals(new Object[] {"SPY", -1L, -1, dt2}, getRowData(result, 2)); + assertArrayEquals(new Object[] {"USO", 2L, 200, dt1}, getRowData(result, 3)); - assertArrayEquals(new Object[] {"AAPL", 1L, 100, dtDefault}, DataAccessHelpers.getRecord(countNulls, 0)); + assertArrayEquals(new Object[] {"AAPL", 1L, 100, dtDefault}, getRowData(countNulls, 0)); // updateGraph.runWithinUnitTestCycle(() -> { @@ -619,7 +618,7 @@ public void testComboByAggUnique() { col("Whee", dt2)); dataTable.notifyListeners(i(), i(), i(11)); }); - assertArrayEquals(new Object[] {"USO", null, null, dt2}, DataAccessHelpers.getRecord(result, 3)); + assertArrayEquals(new Object[] {"USO", null, null, dt2}, getRowData(result, 3)); // updateGraph.runWithinUnitTestCycle(() -> { @@ -631,9 +630,9 @@ public void testComboByAggUnique() { dataTable.notifyListeners(i(9, 10), i(), i(3, 4)); }); - assertArrayEquals(new Object[] {"GOOG", 2L, 350, dt2}, DataAccessHelpers.getRecord(result, 1)); - assertArrayEquals(new Object[] {"VXX", 99L, 50, dt1}, DataAccessHelpers.getRecord(result, 4)); - assertArrayEquals(new Object[] {"VXX", -1L, 50, dtDefault}, DataAccessHelpers.getRecord(countNulls, 4)); + assertArrayEquals(new Object[] {"GOOG", 2L, 350, dt2}, getRowData(result, 1)); + assertArrayEquals(new Object[] {"VXX", 99L, 50, dt1}, getRowData(result, 4)); + assertArrayEquals(new Object[] {"VXX", -1L, 50, dtDefault}, getRowData(countNulls, 4)); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggregatedSelect.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggregatedSelect.java index 3544299b6e2..165160e4a04 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggregatedSelect.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggregatedSelect.java @@ -6,7 +6,6 @@ import io.deephaven.base.FileUtils; import io.deephaven.engine.context.TestExecutionContext; import io.deephaven.engine.table.ColumnDefinition; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.util.SafeCloseable; @@ -156,30 +155,14 @@ public void testUngroup() { TableTools.show(s4); } - private void dumpColumn(DataColumn dc) { - boolean isArray = Vector.class.isAssignableFrom(dc.getType()); - System.out.println("Column Type: " + dc.getType().toString() + (isArray ? " (Array)" : "") + ", ComponentType: " - + dc.getComponentType()); - - for (int ii = 0; ii < dc.size(); ++ii) { - String prefix = dc.getName() + "[" + ii + "]"; - if (isArray) { - Vector vector = (Vector) dc.get(ii); - dumpArray(prefix, vector); - } else { - System.out.println(prefix + ":" + dc.get(ii).toString()); - } - } - } - - private void dumpArray(String prefix, Vector vector) { + private void dumpArray(String prefix, Vector vector) { System.out.println(prefix + ": Array of " + vector.getComponentType().toString()); String prefixsp = new String(new char[prefix.length()]).replace('\0', ' '); final boolean containsArrays = Vector.class.isAssignableFrom(vector.getComponentType()); final ArrayTypeUtils.ArrayAccessor arrayAccessor = ArrayTypeUtils.getArrayAccessor(vector.toArray()); for (int jj = 0; jj < vector.size(); ++jj) { if (containsArrays) { - dumpArray(prefix + "[" + jj + "] ", (Vector) arrayAccessor.get(jj)); + dumpArray(prefix + "[" + jj + "] ", (Vector) arrayAccessor.get(jj)); } else { System.out.println(prefixsp + "[" + jj + "]: " + arrayAccessor.get(jj).toString()); } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestConcurrentInstantiation.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestConcurrentInstantiation.java index 0ac26ce15d1..7acf777a0a6 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestConcurrentInstantiation.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestConcurrentInstantiation.java @@ -21,6 +21,7 @@ import io.deephaven.engine.table.impl.remote.ConstructSnapshot; import io.deephaven.engine.table.impl.select.*; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.BooleanGenerator; import io.deephaven.engine.testutil.generator.DoubleGenerator; @@ -103,8 +104,7 @@ public void testTreeTableFilter() throws ExecutionException, InterruptedExceptio final Table rawSorted = pool.submit(callable).get(TIMEOUT_LENGTH, TIMEOUT_UNIT); TableTools.show(rawSorted); - assertArrayEquals(new int[] {1, 3, 4, 6, 9}, - (int[]) DataAccessHelpers.getColumn(rawSorted, "Sentinel").getDirect()); + assertArrayEquals(new int[] {1, 3, 4, 6, 9}, ColumnVectors.ofInt(rawSorted, "Sentinel").toArray()); TstUtils.addToTable(source, i(10), @@ -142,7 +142,7 @@ public void testTreeTableFilter() throws ExecutionException, InterruptedExceptio assertArrayEquals( new int[] {1, 2, 3, 4, 6, 9, 10, 11, 12}, - (int[]) DataAccessHelpers.getColumn(rawSorted, "Sentinel").getDirect()); + ColumnVectors.ofInt(rawSorted, "Sentinel").toArray()); assertTableEquals(rawSorted, table2); assertTableEquals(table2, table3); assertTableEquals(table3, table4); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java index 4800b614fbe..5a94d867a3b 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java @@ -12,6 +12,7 @@ import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.*; import io.deephaven.engine.table.impl.perf.PerformanceEntry; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.TestErrorNotification; import io.deephaven.engine.testutil.TestNotification; @@ -26,6 +27,7 @@ import io.deephaven.chunk.WritableIntChunk; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.qst.column.Column; +import io.deephaven.vector.ObjectVector; import org.jetbrains.annotations.NotNull; import org.jmock.api.Invocation; import org.jmock.lib.action.CustomAction; @@ -612,10 +614,10 @@ public void testSelectDistinctDate() { }); final Table result = SUT.selectDistinct(PARTITIONING_COLUMN_DEFINITION.getName()); assertIsSatisfied(); - final DataColumn distinctDateColumn = - DataAccessHelpers.getColumn(result, PARTITIONING_COLUMN_DEFINITION.getName()); - assertEquals(expectedDistinctDates.length, distinctDateColumn.size()); - final String[] distinctDates = (String[]) distinctDateColumn.getDirect(); + final @NotNull String columnName = PARTITIONING_COLUMN_DEFINITION.getName(); + final ObjectVector distinctDatesVector = ColumnVectors.ofObject(result, columnName, String.class); + assertEquals(expectedDistinctDates.length, distinctDatesVector.size()); + final String[] distinctDates = distinctDatesVector.toArray(); Arrays.sort(expectedDistinctDates); Arrays.sort(distinctDates); assertArrayEquals(expectedDistinctDates, distinctDates); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionBy.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionBy.java index d525904979e..fbe803e9f8b 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionBy.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionBy.java @@ -11,6 +11,7 @@ import io.deephaven.engine.table.Table; import io.deephaven.engine.table.hierarchical.RollupTable; import io.deephaven.engine.table.impl.select.MatchFilter.MatchType; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.IntGenerator; import io.deephaven.engine.testutil.generator.SetGenerator; @@ -489,7 +490,8 @@ private void testPopulateKeys(final boolean refreshing) { } final PartitionedTable pt = table.partitionedAggBy(List.of(), true, testTable(col("USym", "SPY")), "USym"); final String keyColumnName = pt.keyColumnNames().stream().findFirst().get(); - final String[] keys = (String[]) DataAccessHelpers.getColumn(pt.table(), keyColumnName).getDirect(); + Table table1 = pt.table(); + final String[] keys = ColumnVectors.ofObject(table1, keyColumnName, String.class).toArray(); System.out.println(Arrays.toString(keys)); assertEquals(keys, new String[] {"SPY", "AAPL"}); assertEquals(pt.table().isRefreshing(), refreshing); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSharedContext.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSharedContext.java index e123d36a9a0..b1f3e1cbade 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSharedContext.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSharedContext.java @@ -9,9 +9,11 @@ import io.deephaven.engine.table.ResettableContext; import io.deephaven.engine.table.SharedContext; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.generator.TestDataGenerator; import io.deephaven.engine.testutil.generator.IntGenerator; import io.deephaven.engine.testutil.junit4.EngineCleanup; +import io.deephaven.vector.IntVector; import org.junit.Rule; import org.junit.Test; @@ -106,9 +108,9 @@ public void testConditionFilterWithSimpleRedirections() { final Table t2Filtered = t2.where(condition).reverse(); assertEquals(t2.size(), t1.size()); final Consumer columnChecker = (final String col) -> { - final int[] t2fcs = (int[]) DataAccessHelpers.getColumn(t2Filtered, col).getDirect(); + final int[] t2fcs = ColumnVectors.ofInt(t2Filtered, col).toArray(); assertEquals(t2Filtered.size(), t2fcs.length); - final int[] t1fcs = (int[]) DataAccessHelpers.getColumn(t1Filtered, col).getDirect(); + final int[] t1fcs = ColumnVectors.ofInt(t1Filtered, col).toArray(); assertEquals(t1Filtered.size(), t1fcs.length); assertArrayEquals(t1fcs, t2fcs); }; @@ -152,11 +154,11 @@ public void testConditionFilterWithMoreComplexRedirections() { final Table t2Filtered = t2.where(joinedCondition).reverse(); assertEquals(t2.size(), t1.size()); final Consumer columnChecker = (final String col) -> { - final int[] t2fcs = (int[]) DataAccessHelpers.getColumn(t2Filtered, col).getDirect(); - assertEquals(t2Filtered.size(), t2fcs.length); - final int[] t1fcs = (int[]) DataAccessHelpers.getColumn(t1Filtered, col).getDirect(); - assertEquals(t1Filtered.size(), t1fcs.length); - assertArrayEquals(t1fcs, t2fcs); + final IntVector t2fcs = ColumnVectors.ofInt(t2Filtered, col); + assertEquals(t2Filtered.size(), t2fcs.size()); + final IntVector t1fcs = ColumnVectors.ofInt(t1Filtered, col); + assertEquals(t1Filtered.size(), t1fcs.size()); + assertEquals(t1fcs, t2fcs); }; for (String col : cols) { columnChecker.accept(col); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java index 44393077569..ede03a45561 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java @@ -4,7 +4,8 @@ package io.deephaven.engine.table.impl; import io.deephaven.engine.exceptions.NotSortableException; -import io.deephaven.engine.table.DataColumn; +import io.deephaven.engine.primitive.iterator.CloseableIterator; +import io.deephaven.engine.primitive.iterator.CloseablePrimitiveIteratorOfInt; import io.deephaven.engine.table.Table; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; import io.deephaven.engine.rowset.RowSetFactory; @@ -22,6 +23,8 @@ import java.util.Map; import java.util.function.BiFunction; +import io.deephaven.util.mutable.MutableInt; +import io.deephaven.vector.IntVector; import org.jetbrains.annotations.NotNull; import org.junit.experimental.categories.Category; @@ -39,7 +42,7 @@ private void assertException(QueryTable t, ThrowingConsume r.consume(t); fail(failMessage); } catch (Exception e) { - assertTrue(e.getClass().toString() + " is not a " + excType.toString(), excType.isInstance(e)); + assertTrue(e.getClass() + " is not a " + excType.toString(), excType.isInstance(e)); } } @@ -594,13 +597,16 @@ private QueryTable generateSortTesterTable(int ncols, int size, DataGenerator da return new QueryTable(RowSetFactory.fromRange(0, size - 1).toTracking(), columns); } - private Comparable[][] createBoxedData(Table source, int ncols, int size) { - final Comparable[][] boxedData = new Comparable[ncols][]; + private Comparable[][] createBoxedData(Table source, int ncols, int size) { + final Comparable[][] boxedData = new Comparable[ncols][]; for (int ii = 0; ii < ncols; ++ii) { - final DataColumn column = DataAccessHelpers.getColumn(source, "Column" + ii); - boxedData[ii] = new Comparable[size]; - for (int jj = 0; jj < size; ++jj) { - boxedData[ii][jj] = (Comparable) column.get(jj); + try (final CloseableIterator> columnIter = source.columnIterator("Column" + ii)) { + boxedData[ii] = new Comparable[size]; + int jj = 0; + while (columnIter.hasNext()) { + boxedData[ii][jj] = columnIter.next(); + ++jj; + } } } @@ -652,22 +658,19 @@ private void sortTester(int ncols, int size, Comparable[][] columnData, Table so // Now sort the table by the sentinel, which should just give us a simple ordering. assertEquals(source.size(), size); - assertEquals(DataAccessHelpers.getColumn(source, "Sentinel").size(), size); Table result0 = source.sort("Sentinel"); // show(result0); - DataColumn col = DataAccessHelpers.getColumn(result0, "Sentinel"); - assertEquals(col.size(), size); - for (int jj = 0; jj < size; ++jj) { - assertEquals(jj + 1, col.get(jj)); + final MutableInt expected = new MutableInt(1); + try (final CloseablePrimitiveIteratorOfInt sentinelIterator = result0.integerColumnIterator("Sentinel")) { + sentinelIterator.forEachRemaining((final int actual) -> assertEquals(expected.getAndIncrement(), actual)); } Table result1 = source.sortDescending("Sentinel"); // show(result1); - col = DataAccessHelpers.getColumn(result1, "Sentinel"); - assertEquals(col.size(), size); - for (int jj = 0; jj < size; ++jj) { - assertEquals(size - jj, col.get(jj)); + expected.set(size); + try (final CloseablePrimitiveIteratorOfInt sentinelIterator = result1.integerColumnIterator("Sentinel")) { + sentinelIterator.forEachRemaining((final int actual) -> assertEquals(expected.getAndAdd(-1), actual)); } // Sort it by Column0 through (Column0, .. ColumnN-1) @@ -683,16 +686,17 @@ private void sortTester(int ncols, int size, Comparable[][] columnData, Table so // TableTools.show(resultAscending); // TableTools.show(resultDescending); - - DataColumn colAscending = DataAccessHelpers.getColumn(resultAscending, "Sentinel"); - assertEquals(colAscending.size(), size); - DataColumn colDescending = DataAccessHelpers.getColumn(resultDescending, "Sentinel"); - assertEquals(colDescending.size(), size); - - MultiColumnSortHelper multiColumnSortHelper = new MultiColumnSortHelper(columnData, ii); - for (int jj = 0; jj < size; ++jj) { - assertEquals(multiColumnSortHelper.getSentinel(jj), (int) colAscending.get(jj)); - assertEquals(multiColumnSortHelper.getReverseSentinel(jj), (int) colDescending.get(jj)); + final MultiColumnSortHelper multiColumnSortHelper = new MultiColumnSortHelper(columnData, ii); + try (final CloseablePrimitiveIteratorOfInt sentinelAscending = + resultAscending.integerColumnIterator("Sentinel"); + final CloseablePrimitiveIteratorOfInt sentinelDescending = + resultDescending.integerColumnIterator("Sentinel")) { + for (int jj = 0; jj < size; ++jj) { + assertEquals(multiColumnSortHelper.getSentinel(jj), sentinelAscending.nextInt()); + assertEquals(multiColumnSortHelper.getReverseSentinel(jj), sentinelDescending.nextInt()); + } + assertFalse(sentinelAscending.hasNext()); + assertFalse(sentinelDescending.hasNext()); } } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java index 977f2e90950..7e5915c1112 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java @@ -5,25 +5,23 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ColumnInfo; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.EvalNuggetInterface; import io.deephaven.engine.util.TotalsTableBuilder; -import io.deephaven.function.Numeric; -import io.deephaven.vector.DoubleVectorDirect; -import io.deephaven.engine.table.ColumnSource; import io.deephaven.util.QueryConstants; import java.util.Arrays; import java.util.LinkedHashSet; -import java.util.Map; import java.util.Random; import java.util.Set; import static io.deephaven.engine.testutil.TstUtils.getTable; import static io.deephaven.engine.testutil.TstUtils.initColumnInfos; +import static io.deephaven.function.Numeric.*; public class TestTotalsTable extends RefreshingTableTestCase { @@ -67,16 +65,16 @@ public void testTotalsTable() { assertEquals(new LinkedHashSet<>(Arrays.asList("intCol", "intCol2", "doubleCol", "doubleNullCol", "doubleCol2", "floatCol", "byteCol", "shortCol")), resultColumns); - assertEquals((long) Numeric.sum((int[]) DataAccessHelpers.getColumn(queryTable, "intCol").getDirect()), - DataAccessHelpers.getColumn(totals, "intCol").get(0)); - assertEquals(Numeric.sum((double[]) DataAccessHelpers.getColumn(queryTable, "doubleCol").getDirect()), - DataAccessHelpers.getColumn(totals, "doubleCol").get(0)); - assertEquals(Numeric.sum((double[]) DataAccessHelpers.getColumn(queryTable, "doubleNullCol").getDirect()), - DataAccessHelpers.getColumn(totals, "doubleNullCol").get(0)); - assertEquals("floatCol", Numeric.sum((float[]) DataAccessHelpers.getColumn(queryTable, "floatCol").getDirect()), - (float) DataAccessHelpers.getColumn(totals, "floatCol").get(0), 0.02); - assertEquals(shortSum((short[]) DataAccessHelpers.getColumn(queryTable, "shortCol").getDirect()), - DataAccessHelpers.getColumn(totals, "shortCol").get(0)); + assertEquals(sum(ColumnVectors.ofInt(queryTable, "intCol")), + totals.getColumnSource("intCol").getInt(totals.getRowSet().firstRowKey())); + assertEquals(sum(ColumnVectors.ofDouble(queryTable, "doubleCol")), + totals.getColumnSource("doubleCol").getDouble(totals.getRowSet().firstRowKey())); + assertEquals(sum(ColumnVectors.ofDouble(queryTable, "doubleNullCol")), + totals.getColumnSource("doubleNullCol").getDouble(totals.getRowSet().firstRowKey())); + assertEquals(sum(ColumnVectors.ofFloat(queryTable, "floatCol")), + totals.getColumnSource("floatCol").getFloat(totals.getRowSet().firstRowKey()), 0.02); + assertEquals(sum(ColumnVectors.ofShort(queryTable, "shortCol")), + totals.getColumnSource("shortCol").getShort(totals.getRowSet().firstRowKey())); builder.setDefaultOperation("skip"); builder.setOperation("byteCol", "min"); @@ -87,12 +85,13 @@ public void testTotalsTable() { () -> TotalsTableBuilder.makeTotalsTable(queryTable, builder)); assertEquals(new LinkedHashSet<>(Arrays.asList("Sym", "intCol2", "byteCol")), totals2.getDefinition().getColumnNameSet()); - assertEquals(Numeric.min((byte[]) DataAccessHelpers.getColumn(queryTable, "byteCol").getDirect()), - DataAccessHelpers.getColumn(totals2, "byteCol").get(0)); - assertEquals(DataAccessHelpers.getColumn(queryTable, "Sym").get(0), - DataAccessHelpers.getColumn(totals2, "Sym").get(0)); - assertEquals(DataAccessHelpers.getColumn(queryTable, "intCol2").get(queryTable.size() - 1), - DataAccessHelpers.getColumn(totals2, "intCol2").get(0)); + assertEquals(min(ColumnVectors.ofByte(queryTable, "byteCol")), + totals2.getColumnSource("byteCol").getByte(totals2.getRowSet().firstRowKey())); + assertEquals(queryTable.getColumnSource("Sym").get(queryTable.getRowSet().firstRowKey()), + totals2.getColumnSource("Sym").get(totals2.getRowSet().firstRowKey())); + assertEquals(queryTable.getColumnSource("intCol2").getInt(queryTable.getRowSet().get(queryTable.size() - 1)), + totals2.getColumnSource("intCol2") + .getInt(queryTable.getRowSet().get(totals2.getRowSet().firstRowKey()))); builder.setOperation("byteCol", "max"); builder.setOperation("doubleCol", "var"); @@ -109,26 +108,19 @@ public void testTotalsTable() { new LinkedHashSet<>(Arrays.asList("Sym", "intCol2", "doubleCol", "doubleNullCol__Std", "doubleNullCol__Count", "doubleCol2", "byteCol", "shortCol")), totals3.getDefinition().getColumnNameSet()); - assertEquals( - Numeric.max((byte[]) DataAccessHelpers.getColumn(queryTable, "byteCol").getDirect()), - DataAccessHelpers.getColumn(totals3, "byteCol").getByte(0)); - assertEquals( - Numeric.var(new DoubleVectorDirect( - (double[]) DataAccessHelpers.getColumn(queryTable, "doubleCol").getDirect())), - DataAccessHelpers.getColumn(totals3, "doubleCol").getDouble(0), - EPSILON); - assertEquals( - Numeric.std(new DoubleVectorDirect( - (double[]) DataAccessHelpers.getColumn(queryTable, "doubleNullCol").getDirect())), - DataAccessHelpers.getColumn(totals3, "doubleNullCol__Std").getDouble(0), - EPSILON); - assertEquals(queryTable.size(), DataAccessHelpers.getColumn(totals3, "doubleNullCol__Count").getLong(0)); - assertEquals( - Numeric.avg(new DoubleVectorDirect( - (double[]) DataAccessHelpers.getColumn(queryTable, "doubleCol2").getDirect())), - DataAccessHelpers.getColumn(totals3, "doubleCol2").getDouble(0), + assertEquals(max(ColumnVectors.ofByte(queryTable, "byteCol")), + totals3.getColumnSource("byteCol").getByte(totals3.getRowSet().firstRowKey())); + assertEquals(var(ColumnVectors.ofDouble(queryTable, "doubleCol")), + totals3.getColumnSource("doubleCol").getDouble(totals3.getRowSet().firstRowKey()), EPSILON); + assertEquals(std(ColumnVectors.ofDouble(queryTable, "doubleNullCol")), + totals3.getColumnSource("doubleNullCol__Std").getDouble(totals3.getRowSet().firstRowKey()), EPSILON); - assertEquals(queryTable.size(), (long) DataAccessHelpers.getColumn(totals3, "shortCol").get(0)); + assertEquals(queryTable.size(), + totals3.getColumnSource("doubleNullCol__Count").getLong(totals3.getRowSet().firstRowKey())); + assertEquals(avg(ColumnVectors.ofDouble(queryTable, "doubleCol2")), + totals3.getColumnSource("doubleCol2").getDouble(totals3.getRowSet().firstRowKey()), EPSILON); + assertEquals(queryTable.size(), + totals3.getColumnSource("shortCol").getLong(totals3.getRowSet().firstRowKey())); final Table totals4 = ExecutionContext.getContext().getUpdateGraph().exclusiveLock().computeLocked( () -> TotalsTableBuilder.makeTotalsTable(queryTable, builder)); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/by/TestSortedFirstOrLastByFactory.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/by/TestSortedFirstOrLastByFactory.java index 25e5b2268cd..bc2b48fc0c3 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/by/TestSortedFirstOrLastByFactory.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/by/TestSortedFirstOrLastByFactory.java @@ -6,8 +6,8 @@ import io.deephaven.api.agg.spec.AggSpec; import io.deephaven.configuration.Configuration; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.TableUpdateImpl; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.IntGenerator; import io.deephaven.engine.testutil.generator.SetGenerator; @@ -119,8 +119,8 @@ public void testIds6445() { tuvbuck.getResultTable().addUpdateListener(failureListenerBuck); showWithRowSet(sfb); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); - TestCase.assertEquals(2, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(2, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); + TestCase.assertEquals(2, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); // this part is the original bug, if we didn't change the actual value of the row redirection; because the // shift modify combination left it at the same row key; we would not notice the mdoification @@ -171,9 +171,9 @@ public void testIds6445() { System.out.println("Shifted SFB"); showWithRowSet(sfb); tuvsfb.deepValidation(); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); + TestCase.assertEquals(1, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); tuvbuck.deepValidation(); - TestCase.assertEquals(1, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(1, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); // here we are shifting, but not modifying the SFB column (but are modifying sentinel) updateGraph.runWithinUnitTestCycle(() -> { @@ -198,9 +198,9 @@ public void testIds6445() { System.out.println("Shifted and Modified SFB"); showWithRowSet(sfb); tuvsfb.deepValidation(); - TestCase.assertEquals(9, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); + TestCase.assertEquals(9, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); tuvbuck.deepValidation(); - TestCase.assertEquals(9, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(9, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); // we are shifting, and claiming to modify SFB but not actually doing it updateGraph.runWithinUnitTestCycle(() -> { @@ -225,9 +225,9 @@ public void testIds6445() { System.out.println("Shifted and Modified SFB"); showWithRowSet(sfb); tuvsfb.deepValidation(); - TestCase.assertEquals(9, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); + TestCase.assertEquals(9, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); tuvbuck.deepValidation(); - TestCase.assertEquals(9, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(9, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); // here we are shifting, and modifying SFB but not actually doing it updateGraph.runWithinUnitTestCycle(() -> { @@ -252,9 +252,9 @@ public void testIds6445() { System.out.println("Shifted and Really Really Modified SFB"); showWithRowSet(sfb); tuvsfb.deepValidation(); - TestCase.assertEquals(6, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); + TestCase.assertEquals(6, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); tuvbuck.deepValidation(); - TestCase.assertEquals(6, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(6, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); // claim to modify sfb, but don't really. Actually modify sentinel. updateGraph.runWithinUnitTestCycle(() -> { @@ -279,8 +279,8 @@ public void testIds6445() { System.out.println("Shifted and Really Really Modified SFB"); showWithRowSet(sfb); tuvsfb.deepValidation(); - TestCase.assertEquals(13, DataAccessHelpers.getColumn(sfb, "Sentinel").get(0)); + TestCase.assertEquals(13, ColumnVectors.ofInt(sfb, "Sentinel").get(0)); tuvbuck.deepValidation(); - TestCase.assertEquals(13, DataAccessHelpers.getColumn(bucketed, "Sentinel").get(0)); + TestCase.assertEquals(13, ColumnVectors.ofInt(bucketed, "Sentinel").get(0)); } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/TestClockFilters.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/TestClockFilters.java index 97928f38161..664ae3297e1 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/TestClockFilters.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/TestClockFilters.java @@ -5,8 +5,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.testutil.junit4.EngineCleanup; import static io.deephaven.engine.util.TableTools.*; @@ -56,7 +56,7 @@ public void testSorted1() { final SortedClockFilter filter = new SortedClockFilter("Timestamp", clock, true); final Table result = testInput1.sort("Timestamp").where(filter); - assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -64,14 +64,14 @@ public void testSorted1() { filter.run(); }); assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test @@ -80,7 +80,7 @@ public void testUnsorted1() { final UnsortedClockFilter filter = new UnsortedClockFilter("Timestamp", clock, true); final Table result = testInput1.where(filter); - assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1, 1, 1, 1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -88,14 +88,14 @@ public void testUnsorted1() { filter.run(); }); assertArrayEquals(new int[] {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test @@ -104,7 +104,7 @@ public void testSorted2() { final SortedClockFilter filter = new SortedClockFilter("Timestamp", clock, true); final Table result = testInput2.sort("Timestamp").where(filter); - assertArrayEquals(new int[] {1, 1, 1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1, 1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -112,14 +112,14 @@ public void testSorted2() { filter.run(); }); assertArrayEquals(new int[] {1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test @@ -128,7 +128,7 @@ public void testUnsorted2() { final UnsortedClockFilter filter = new UnsortedClockFilter("Timestamp", clock, true); final Table result = testInput2.where(filter); - assertArrayEquals(new int[] {1, 1, 1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1, 1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -136,14 +136,14 @@ public void testUnsorted2() { filter.run(); }); assertArrayEquals(new int[] {1, 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 2, 3, 1, 2, 3, 2, 2, 3, 2, 2, 3, 1, 2, 3, 1, 2, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test @@ -152,7 +152,7 @@ public void testSorted3() { final SortedClockFilter filter = new SortedClockFilter("Timestamp", clock, true); final Table result = testInput3.sort("Timestamp").where(filter); - assertArrayEquals(new int[] {1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -160,14 +160,14 @@ public void testSorted3() { filter.run(); }); assertArrayEquals(new int[] {1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test @@ -176,7 +176,7 @@ public void testUnsorted3() { final UnsortedClockFilter filter = new UnsortedClockFilter("Timestamp", clock, true); final Table result = testInput3.where(filter); - assertArrayEquals(new int[] {1, 1}, (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + assertArrayEquals(new int[] {1, 1}, ColumnVectors.ofInt(result, "Int").toArray()); final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast(); updateGraph.runWithinUnitTestCycle(() -> { @@ -184,14 +184,14 @@ public void testUnsorted3() { filter.run(); }); assertArrayEquals(new int[] {1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); updateGraph.runWithinUnitTestCycle(() -> { clock.run(); filter.run(); }); assertArrayEquals(new int[] {1, 2, 3, 1, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3}, - (int[]) DataAccessHelpers.getColumn(result, "Int").getDirect()); + ColumnVectors.ofInt(result, "Int").toArray()); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/WhereFilterFactoryTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/WhereFilterFactoryTest.java index cc41c935bb8..453479692cf 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/WhereFilterFactoryTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/WhereFilterFactoryTest.java @@ -6,7 +6,6 @@ import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.engine.context.QueryScope; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; import io.deephaven.time.DateTimeUtils; import io.deephaven.engine.util.TableTools; @@ -213,14 +212,14 @@ public void testInInstants() { assertEquals(MatchFilter.class, f.getClass()); RowSet idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(mon, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(mon, t.getColumnSource("Timestamp", Instant.class).get(idx.firstRowKey())); // match one of two items f = WhereFilterFactory.getExpression("Timestamp in '" + tues + "', '" + wed + "'"); f.init(t.getDefinition()); assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(tues, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(tues, t.getColumnSource("Timestamp", Instant.class).get(idx.firstRowKey())); // match two of two items f = WhereFilterFactory.getExpression("Timestamp in '" + tues + "', '" + thurs + "'"); @@ -228,8 +227,8 @@ public void testInInstants() { assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(2, idx.size()); - assertEquals(tues, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); - assertEquals(thurs, DataAccessHelpers.getColumn(t, 0).get(idx.lastRowKey())); + assertEquals(tues, t.getColumnSource("Timestamp", Instant.class).get(idx.firstRowKey())); + assertEquals(thurs, t.getColumnSource("Timestamp", Instant.class).get(idx.lastRowKey())); // match zero of one item f = WhereFilterFactory.getExpression("Timestamp in '" + wed + "'"); @@ -252,14 +251,14 @@ public void testBigDecimal() { assertEquals(MatchFilter.class, f.getClass()); RowSet idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(b, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(b, t.getColumnSource("BigDecimal", BigDecimal.class).get(idx.firstRowKey())); // match one of two items f = WhereFilterFactory.getExpression("BigDecimal in " + a + ", " + b); f.init(t.getDefinition()); assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(b, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(b, t.getColumnSource("BigDecimal", BigDecimal.class).get(idx.firstRowKey())); // match two of two items f = WhereFilterFactory.getExpression("BigDecimal in " + c + ", " + d); @@ -267,8 +266,8 @@ public void testBigDecimal() { assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(2, idx.size()); - assertEquals(c, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); - assertEquals(d, DataAccessHelpers.getColumn(t, 0).get(idx.lastRowKey())); + assertEquals(c, t.getColumnSource("BigDecimal", BigDecimal.class).get(idx.firstRowKey())); + assertEquals(d, t.getColumnSource("BigDecimal", BigDecimal.class).get(idx.lastRowKey())); // match zero of one item f = WhereFilterFactory.getExpression("BigDecimal == " + a); @@ -291,14 +290,14 @@ public void testBigIntegerl() { assertEquals(MatchFilter.class, f.getClass()); RowSet idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(b, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(b, t.getColumnSource("BigInteger", BigInteger.class).get(idx.firstRowKey())); // match one of two items f = WhereFilterFactory.getExpression("BigInteger in " + a + ", " + b); f.init(t.getDefinition()); assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(1, idx.size()); - assertEquals(b, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); + assertEquals(b, t.getColumnSource("BigInteger", BigInteger.class).get(idx.firstRowKey())); // match two of two items f = WhereFilterFactory.getExpression("BigInteger in " + c + ", " + d); @@ -306,8 +305,8 @@ public void testBigIntegerl() { assertEquals(MatchFilter.class, f.getClass()); idx = f.filter(t.getRowSet().copy(), t.getRowSet(), t, false); assertEquals(2, idx.size()); - assertEquals(c, DataAccessHelpers.getColumn(t, 0).get(idx.firstRowKey())); - assertEquals(d, DataAccessHelpers.getColumn(t, 0).get(idx.lastRowKey())); + assertEquals(c, t.getColumnSource("BigInteger", BigInteger.class).get(idx.firstRowKey())); + assertEquals(d, t.getColumnSource("BigInteger", BigInteger.class).get(idx.lastRowKey())); // match zero of one item f = WhereFilterFactory.getExpression("BigInteger == " + a); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumMinMax.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumMinMax.java index 684d08f6ead..ba1f0a95335 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumMinMax.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumMinMax.java @@ -8,8 +8,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.testutil.TstUtils; @@ -47,10 +47,8 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithCumMin(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col + "Min").getDirect()); - assertWithCumMax(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col + "Max").getDirect()); + assertWithCumMin(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(result, col + "Min").toArray()); + assertWithCumMax(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(result, col + "Max").toArray()); } } @@ -70,10 +68,12 @@ public void testStaticZeroKeyAllNulls() { if ("boolCol".equals(col)) { continue; } - assertWithCumMin(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col + "Min").getDirect()); - assertWithCumMax(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col + "Max").getDirect()); + assertWithCumMin( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col + "Min").toArray()); + assertWithCumMax( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col + "Max").toArray()); } } @@ -111,10 +111,12 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithCumMin(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col + "Min").getDirect()); - assertWithCumMax(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col + "Max").getDirect()); + assertWithCumMin( + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col + "Min").toArray()); + assertWithCumMax( + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col + "Max").toArray()); }); return source; }); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java index 0f75fe5b85e..09fbbc68a22 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java @@ -9,8 +9,8 @@ import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; import io.deephaven.api.updateby.UpdateByOperation; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.*; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.GenerateTableUpdates; import io.deephaven.engine.testutil.EvalNugget; @@ -22,7 +22,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; -import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; @@ -49,9 +48,10 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithCumProd(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getType()); + assertWithCumProd( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), + result.getDefinition().getColumn(col).getDataType()); } } @@ -64,9 +64,10 @@ public void testStaticZeroKeyAllNulls() { if ("boolCol".equals(col)) { continue; } - assertWithCumProd(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getType()); + assertWithCumProd( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), + result.getDefinition().getColumn(col).getDataType()); } } @@ -75,7 +76,7 @@ public void testStaticZeroKeyAllNulls() { // region Bucketed Tests @Test - public void testNullOnBucketChange() throws IOException { + public void testNullOnBucketChange() { final TableDefaults t = testTable(stringCol("Sym", "A", "A", "B", "B"), byteCol("ByteVal", (byte) 1, (byte) 2, NULL_BYTE, (byte) 3), shortCol("ShortVal", (short) 1, (short) 2, NULL_SHORT, (short) 3), @@ -122,9 +123,10 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithCumProd(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getType()); + assertWithCumProd( + ColumnVectors.of(source, col).getDirect(), + ColumnVectors.of(actual, col).getDirect(), + actual.getDefinition().getColumn(col).getDataType()); }); return source; }); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumSum.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumSum.java index 9ef95d01e31..86de3408e9a 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumSum.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumSum.java @@ -9,8 +9,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.*; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.GenerateTableUpdates; import io.deephaven.engine.testutil.EvalNugget; @@ -23,7 +23,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; -import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; @@ -51,9 +50,10 @@ public void testStaticZeroKey() { final Table summed = t.updateBy(UpdateByOperation.CumSum()); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithCumSum(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType()); + assertWithCumSum( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType()); } } @@ -66,9 +66,10 @@ public void testStaticZeroKeyAllNulls() { final Table summed = t.updateBy(UpdateByOperation.CumSum()); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithCumSum(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType()); + assertWithCumSum( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType()); } } @@ -77,7 +78,7 @@ public void testStaticZeroKeyAllNulls() { // region Bucketed Tests @Test - public void testNullOnBucketChange() throws IOException { + public void testNullOnBucketChange() { final TableDefaults t = testTable(stringCol("Sym", "A", "A", "B", "B"), byteCol("ByteVal", (byte) 1, (byte) 2, NULL_BYTE, (byte) 3), shortCol("ShortVal", (short) 1, (short) 2, NULL_SHORT, (short) 3), @@ -124,9 +125,10 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithCumSum(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getType()); + assertWithCumSum( + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), + actual.getDefinition().getColumn(col).getDataType()); }); return source; }); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java index 2775234ffab..2a87694ce8e 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java @@ -9,8 +9,8 @@ import io.deephaven.base.verify.Assert; import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.table.*; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.CharGenerator; import io.deephaven.engine.testutil.generator.SortedInstantGenerator; @@ -75,16 +75,16 @@ public void testManualVerification() { // default is NULL_DOMINATES QueryTable result = (QueryTable) table.updateBy(List.of(UpdateByOperation.Delta())); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(result, "Int").getDirect(), outputNullDominates); + assertArrayEquals(ColumnVectors.ofInt(result, "Int").toArray(), outputNullDominates); result = (QueryTable) table.updateBy(List.of(UpdateByOperation.Delta(DeltaControl.NULL_DOMINATES))); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(result, "Int").getDirect(), outputNullDominates); + assertArrayEquals(ColumnVectors.ofInt(result, "Int").toArray(), outputNullDominates); result = (QueryTable) table.updateBy(List.of(UpdateByOperation.Delta(DeltaControl.VALUE_DOMINATES))); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(result, "Int").getDirect(), outputValueDominates); + assertArrayEquals(ColumnVectors.ofInt(result, "Int").toArray(), outputValueDominates); result = (QueryTable) table.updateBy(List.of(UpdateByOperation.Delta(DeltaControl.ZERO_DOMINATES))); - assertArrayEquals((int[]) DataAccessHelpers.getColumn(result, "Int").getDirect(), outputZeroDominates); + assertArrayEquals(ColumnVectors.ofInt(result, "Int").toArray(), outputZeroDominates); } // region Zero Key Tests @@ -105,8 +105,9 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithDelta(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), + assertWithDelta( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), DeltaControl.DEFAULT); } @@ -116,8 +117,9 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithDelta(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), + assertWithDelta( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), DeltaControl.NULL_DOMINATES); } @@ -127,8 +129,9 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithDelta(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), + assertWithDelta( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), DeltaControl.VALUE_DOMINATES); } @@ -138,8 +141,9 @@ public void testStaticZeroKey() { if ("boolCol".equals(col)) { continue; } - assertWithDelta(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(result, col).getDirect(), + assertWithDelta( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(result, col).toArray(), DeltaControl.ZERO_DOMINATES); } } @@ -177,8 +181,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithDelta(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + assertWithDelta( + ColumnVectors.of(source, col).getDirect(), + ColumnVectors.of(actual, col).getDirect(), DeltaControl.DEFAULT); }); return source; @@ -191,8 +196,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithDelta(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + assertWithDelta( + ColumnVectors.of(source, col).getDirect(), + ColumnVectors.of(actual, col).getDirect(), DeltaControl.NULL_DOMINATES); }); return source; @@ -205,8 +211,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithDelta(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + assertWithDelta( + ColumnVectors.of(source, col).getDirect(), + ColumnVectors.of(actual, col).getDirect(), DeltaControl.VALUE_DOMINATES); }); return source; @@ -219,8 +226,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithDelta(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + assertWithDelta( + ColumnVectors.of(source, col).getDirect(), + ColumnVectors.of(actual, col).getDirect(), DeltaControl.ZERO_DOMINATES); }); return source; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmMinMax.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmMinMax.java index a6da9ea2420..bfdd242edb7 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmMinMax.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmMinMax.java @@ -17,13 +17,13 @@ import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.TableDefaults; import io.deephaven.engine.table.impl.locations.TableDataException; import io.deephaven.engine.table.impl.updateby.em.BaseBigNumberEMOperator; import io.deephaven.engine.table.impl.updateby.em.BasePrimitiveEMOperator; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.generator.CharGenerator; @@ -65,7 +65,7 @@ public class TestEmMinMax extends BaseUpdateByTest { }; final BaseBigNumberEMOperator.EmFunction bdMaxFunction = (prev, cur, alpha, oneMinusAlpha) -> { final BigDecimal decayedVal = prev.multiply(alpha, mathContextDefault); - return decayedVal.compareTo(cur) == 1 + return decayedVal.compareTo(cur) > 0 ? decayedVal : cur; }; @@ -76,7 +76,7 @@ public class TestEmMinMax extends BaseUpdateByTest { }; final BaseBigNumberEMOperator.EmFunction bdMinFunction = (prev, cur, alpha, oneMinusAlpha) -> { final BigDecimal decayedVal = prev.multiply(alpha, mathContextDefault); - return decayedVal.compareTo(cur) == -1 + return decayedVal.compareTo(cur) < 0 ? decayedVal : cur; }; @@ -119,7 +119,7 @@ public void testStaticZeroKey() { .onNullValue(BadDataBehavior.RESET) .onNanValue(BadDataBehavior.RESET).build(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = epochNanos(ts[i]); @@ -131,12 +131,12 @@ public void testStaticZeroKey() { Table actualReset = t.updateBy(UpdateByOperation.EmMin(resetControl, 100, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmTicks(skipControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkip, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(skipControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkip, col).toArray(), colType, doubleMinFunction, bdMinFunction); - assertWithEmTicks(resetControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualReset, col).getDirect(), + assertWithEmTicks(resetControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualReset, col).toArray(), colType, doubleMinFunction, bdMinFunction); } @@ -144,12 +144,12 @@ public void testStaticZeroKey() { Table actualResetTime = t.updateBy(UpdateByOperation.EmMin(resetControl, "ts", 10 * MINUTE, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmTime(skipControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkipTime, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmTime(skipControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkipTime, col).toArray(), colType, doubleMinFunction, bdMinFunction); - assertWithEmTime(resetControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualResetTime, col).getDirect(), + assertWithEmTime(resetControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualResetTime, col).toArray(), colType, doubleMinFunction, bdMinFunction); } @@ -159,12 +159,12 @@ public void testStaticZeroKey() { actualReset = t.updateBy(UpdateByOperation.EmMax(resetControl, 100, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmTicks(skipControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkip, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(skipControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkip, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); - assertWithEmTicks(resetControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualReset, col).getDirect(), + assertWithEmTicks(resetControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualReset, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); } @@ -172,12 +172,12 @@ public void testStaticZeroKey() { actualResetTime = t.updateBy(UpdateByOperation.EmMax(resetControl, "ts", 10 * MINUTE, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmTime(skipControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkipTime, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmTime(skipControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkipTime, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); - assertWithEmTime(resetControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualResetTime, col).getDirect(), + assertWithEmTime(resetControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualResetTime, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); } } @@ -221,9 +221,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkip, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmTicks(skipControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(skipControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMinFunction, bdMinFunction); }); return source; @@ -231,9 +231,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpReset, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmTicks(resetControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(resetControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMinFunction, bdMinFunction); }); return source; @@ -248,16 +248,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkipTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray();; final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmTime(skipControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMinFunction, bdMinFunction); }); return source; @@ -265,16 +265,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpResetTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray();; final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmTime(resetControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMinFunction, bdMinFunction); }); return source; @@ -291,9 +291,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkip, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmTicks(skipControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(skipControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); }); return source; @@ -301,9 +301,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpReset, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmTicks(resetControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmTicks(resetControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); }); return source; @@ -318,16 +318,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkipTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray();; final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmTime(skipControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); }); return source; @@ -335,16 +335,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpResetTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray();; final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmTime(resetControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType, doubleMaxFunction, bdMaxFunction); }); return source; @@ -882,7 +882,7 @@ public void testInterfaces() { .onNullValue(BadDataBehavior.RESET) .onNanValue(BadDataBehavior.RESET).build(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = epochNanos(ts[i]); @@ -1177,7 +1177,7 @@ final void assertWithEmTicks(final OperationControl control, final long ticks, @NotNull final Object expected, @NotNull final Object actual, - final Class type, + final Class type, final BasePrimitiveEMOperator.EmFunction doubleFunction, final BaseBigNumberEMOperator.EmFunction bdFunction) { if (expected instanceof byte[]) { @@ -1221,7 +1221,7 @@ final void assertWithEmTime(final OperationControl control, @NotNull final long[] timestamps, @NotNull final Object expected, @NotNull final Object actual, - final Class type, + final Class type, final BasePrimitiveEMOperator.EmFunction doubleFunction, final BaseBigNumberEMOperator.EmFunction bdFunction) { diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmStd.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmStd.java index 5f53a3b5146..90f8218d06d 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmStd.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEmStd.java @@ -17,11 +17,11 @@ import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.TableDefaults; import io.deephaven.engine.table.impl.locations.TableDataException; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.TstUtils; @@ -211,8 +211,8 @@ public void testVerifyVsPandas() { UpdateByOperation.EmStd(10, "emstd10=value"), UpdateByOperation.EmStd(50, "emstd50=value"))); - assertBDArrayEquals(bdStd10, (BigDecimal[]) DataAccessHelpers.getColumn(bdResult, "emstd10").getDirect()); - assertBDArrayEquals(bdStd50, (BigDecimal[]) DataAccessHelpers.getColumn(bdResult, "emstd50").getDirect()); + assertBDArrayEquals(bdStd10, ColumnVectors.ofObject(bdResult, "emstd10", BigDecimal.class).toArray()); + assertBDArrayEquals(bdStd50, ColumnVectors.ofObject(bdResult, "emstd50", BigDecimal.class).toArray()); } // region Zero Key Tests @@ -239,31 +239,31 @@ public void testStaticZeroKey() { final Table actualReset = t.updateBy(UpdateByOperation.EmStd(resetControl, ticks, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmStdTicks(skipControl, ticks, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkip, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmStdTicks(skipControl, ticks, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkip, col).toArray(), colType); - assertWithEmStdTicks(resetControl, ticks, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualReset, col).getDirect(), + assertWithEmStdTicks(resetControl, ticks, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualReset, col).toArray(), colType); } final Table actualSkipTime = t.updateBy(UpdateByOperation.EmStd(skipControl, "ts", 10 * MINUTE, columns)); final Table actualResetTime = t.updateBy(UpdateByOperation.EmStd(resetControl, "ts", 10 * MINUTE, columns)); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = epochNanos(ts[i]); } for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmStdTime(skipControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkipTime, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmStdTime(skipControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkipTime, col).toArray(), colType); - assertWithEmStdTime(resetControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualResetTime, col).getDirect(), + assertWithEmStdTime(resetControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualResetTime, col).toArray(), colType); } } @@ -305,9 +305,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkip, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmStdTicks(skipControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmStdTicks(skipControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -315,9 +315,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpReset, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmStdTicks(resetControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmStdTicks(resetControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -333,16 +333,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkipTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmStdTime(skipControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -350,16 +350,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpResetTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmStdTime(resetControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -611,13 +611,13 @@ public void testResetBehavior() { result = input.updateBy(UpdateByOperation.EmStd(dataResetControl, 10)); // Extract the BD result and fuzzy-validate against expectations - BigDecimal[] actualBD = (BigDecimal[]) DataAccessHelpers.getColumn(result, "col").getDirect(); + BigDecimal[] actualBD = ColumnVectors.ofObject(result, "col", BigDecimal.class).toArray(); assertBDArrayEquals(actualBD, expectedBD); input = testTable(RowSetFactory.flat(6).toTracking(), col("col", inputBD)); result = input.updateBy(UpdateByOperation.EmStd(dataResetControl, 10)); - actualBD = (BigDecimal[]) DataAccessHelpers.getColumn(result, "col").getDirect(); + actualBD = ColumnVectors.ofObject(result, "col", BigDecimal.class).toArray(); assertBDArrayEquals(actualBD, expectedBD); // Test reset for NaN values @@ -1355,7 +1355,7 @@ final void assertWithEmStdTicks(final OperationControl control, final long ticks, @NotNull final Object expected, @NotNull final Object actual, - final Class type) { + final Class type) { if (expected instanceof double[]) { assertArrayEquals(compute_emstd_ticks(control, ticks, (double[]) expected), (double[]) actual, .001d); } @@ -1397,7 +1397,7 @@ final void assertWithEmStdTime(final OperationControl control, @NotNull final long[] timestamps, @NotNull final Object expected, @NotNull final Object actual, - final Class type) { + final Class type) { if (expected instanceof double[]) { assertArrayEquals(compute_emstd_time(control, nanos, timestamps, (double[]) expected), (double[]) actual, .001d); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEma.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEma.java index 8787980663c..46aaf4ad6c2 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEma.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEma.java @@ -16,11 +16,11 @@ import io.deephaven.engine.rowset.RowSet; import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.TableDefaults; import io.deephaven.engine.table.impl.locations.TableDataException; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.generator.CharGenerator; @@ -614,7 +614,7 @@ public void testInterfaces() { .onNullValue(BadDataBehavior.RESET) .onNanValue(BadDataBehavior.RESET).build(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = epochNanos(ts[i]); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEms.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEms.java index 6167bd68ef8..c315cea4ec1 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEms.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestEms.java @@ -17,11 +17,11 @@ import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.TableDefaults; import io.deephaven.engine.table.impl.locations.TableDataException; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.generator.CharGenerator; @@ -101,31 +101,31 @@ public void testStaticZeroKey() { final Table actualReset = t.updateBy(UpdateByOperation.Ems(resetControl, 100, columns)); for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmsTicks(skipControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkip, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmsTicks(skipControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkip, col).toArray(), colType); - assertWithEmsTicks(resetControl, 100, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualReset, col).getDirect(), + assertWithEmsTicks(resetControl, 100, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualReset, col).toArray(), colType); } final Table actualSkipTime = t.updateBy(UpdateByOperation.Ems(skipControl, "ts", 10 * MINUTE, columns)); final Table actualResetTime = t.updateBy(UpdateByOperation.Ems(resetControl, "ts", 10 * MINUTE, columns)); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : columns) { - final Class colType = DataAccessHelpers.getColumn(t, col).getType(); - assertWithEmsTime(skipControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualSkipTime, col).getDirect(), + final Class colType = t.getDefinition().getColumn(col).getDataType(); + assertWithEmsTime(skipControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualSkipTime, col).toArray(), colType); - assertWithEmsTime(resetControl, 10 * MINUTE, timestamps, DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(actualResetTime, col).getDirect(), + assertWithEmsTime(resetControl, 10 * MINUTE, timestamps, ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(actualResetTime, col).toArray(), colType); } } @@ -167,9 +167,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkip, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmsTicks(skipControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmsTicks(skipControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -177,9 +177,9 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpReset, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); - assertWithEmsTicks(resetControl, 100, DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + final Class colType = source.getDefinition().getColumn(col).getDataType(); + assertWithEmsTicks(resetControl, 100, ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -194,16 +194,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpSkipTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmsTime(skipControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -211,16 +211,16 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOpResetTime, (source, actual) -> { final int sourceSize = source.intSize(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); final long[] timestamps = new long[sourceSize]; for (int i = 0; i < sourceSize; i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - final Class colType = DataAccessHelpers.getColumn(source, col).getType(); + final Class colType = source.getDefinition().getColumn(col).getDataType(); assertWithEmsTime(resetControl, 10 * MINUTE, timestamps, - DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), colType); }); return source; @@ -716,7 +716,7 @@ public void testInterfaces() { .onNullValue(BadDataBehavior.RESET) .onNanValue(BadDataBehavior.RESET).build(); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = epochNanos(ts[i]); @@ -996,7 +996,7 @@ final void assertWithEmsTicks(final OperationControl control, final long ticks, @NotNull final Object expected, @NotNull final Object actual, - final Class type) { + final Class type) { if (expected instanceof double[]) { assertArrayEquals(compute_ems_ticks(control, ticks, (double[]) expected), (double[]) actual, .001d); } @@ -1037,7 +1037,7 @@ final void assertWithEmsTime(final OperationControl control, @NotNull final long[] timestamps, @NotNull final Object expected, @NotNull final Object actual, - final Class type) { + final Class type) { if (expected instanceof double[]) { assertArrayEquals(compute_ems_time(control, nanos, timestamps, (double[]) expected), (double[]) actual, .001d); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestForwardFill.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestForwardFill.java index ebe40be7469..c1359bb4952 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestForwardFill.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestForwardFill.java @@ -9,8 +9,8 @@ import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.*; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.EvalNuggetInterface; @@ -49,8 +49,7 @@ public void testStaticZeroKey() { final Table filled = t.updateBy(UpdateByOperation.Fill()); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithForwardFill(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(filled, col).getDirect()); + assertWithForwardFill(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(filled, col).toArray()); } } @@ -68,8 +67,9 @@ public void testNoKeyAddOnly() throws Exception { assertEquals(8, result.intSize()); for (int ii = 0; ii < 2; ii++) { - assertWithForwardFill(DataAccessHelpers.getColumn(src, ii).getDirect(), - DataAccessHelpers.getColumn(result, ii).getDirect()); + assertWithForwardFill( + ColumnVectors.of(src, ((Table) src).getDefinition().getColumns().get(ii).getName()).toArray(), + ColumnVectors.of(result, result.getDefinition().getColumns().get(ii).getName()).toArray()); } updateAndValidate(src, result, () -> { @@ -127,8 +127,9 @@ public void testNoKeyAddAndRemoves() throws Exception { assertEquals(8, result.intSize()); for (int ii = 0; ii < 2; ii++) { - assertWithForwardFill(DataAccessHelpers.getColumn(src, ii).getDirect(), - DataAccessHelpers.getColumn(result, ii).getDirect()); + assertWithForwardFill( + ColumnVectors.of(src, ((Table) src).getDefinition().getColumns().get(ii).getName()).toArray(), + ColumnVectors.of(result, result.getDefinition().getColumns().get(ii).getName()).toArray()); } updateAndValidate(src, result, () -> { @@ -180,8 +181,9 @@ public void testNoKeyGeneral() throws Exception { assertEquals(8, result.intSize()); for (int ii = 0; ii < 2; ii++) { - assertWithForwardFill(DataAccessHelpers.getColumn(src, ii).getDirect(), - DataAccessHelpers.getColumn(result, ii).getDirect()); + assertWithForwardFill( + ColumnVectors.of(src, ((Table) src).getDefinition().getColumns().get(ii).getName()).toArray(), + ColumnVectors.of(result, result.getDefinition().getColumns().get(ii).getName()).toArray()); } // Add a key at the beginning and end, but null the end so it should fill as an L @@ -303,8 +305,9 @@ void updateAndValidate(QueryTable src, Table result, ThrowingRunnable updateF try { for (int ii = 0; ii < 2; ii++) { - assertWithForwardFill(DataAccessHelpers.getColumn(src, ii).getDirect(), - DataAccessHelpers.getColumn(result, ii).getDirect()); + assertWithForwardFill( + ColumnVectors.of(src, src.getDefinition().getColumns().get(ii).getName()).toArray(), + ColumnVectors.of(result, result.getDefinition().getColumns().get(ii).getName()).toArray()); } } catch (Throwable ex) { System.out.println("ERROR: Source table:"); @@ -353,8 +356,7 @@ public void testStaticBucketed() { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithForwardFill(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect()); + assertWithForwardFill(ColumnVectors.of(source, col).toArray(), ColumnVectors.of(actual, col).toArray()); }); return source; }); @@ -375,8 +377,7 @@ public void testStaticGroupedBucketed() { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithForwardFill(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect()); + assertWithForwardFill(ColumnVectors.of(source, col).toArray(), ColumnVectors.of(actual, col).toArray()); }); return source; }); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java index 8124ff6bd37..f24587e8ed9 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java @@ -10,8 +10,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -154,25 +154,25 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -189,25 +189,25 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -224,25 +224,25 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -260,25 +260,25 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java index 6f4d5735362..3198ee9d049 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java @@ -11,8 +11,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -111,23 +111,23 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); - long[] biActual = (long[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); + long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } - long[] bdActual = (long[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + long[] bdActual = ColumnVectors.ofLong(actual, "bigDecimalCol").toArray(); + long[] bdExpected = ColumnVectors.ofLong(expected, "bigDecimalCol").toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } } @@ -143,23 +143,23 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); - long[] biActual = (long[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); + long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } - long[] bdActual = (long[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + long[] bdActual = ColumnVectors.ofLong(actual, "bigDecimalCol").toArray(); + long[] bdExpected = ColumnVectors.ofLong(expected, "bigDecimalCol").toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } } @@ -174,23 +174,23 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); - long[] biActual = (long[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); + long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } - long[] bdActual = (long[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + long[] bdActual = ColumnVectors.ofLong(actual, "bigDecimalCol").toArray(); + long[] bdExpected = ColumnVectors.ofLong(expected, "bigDecimalCol").toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } } @@ -206,23 +206,23 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); - long[] biActual = (long[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); + long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } - long[] bdActual = (long[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + long[] bdActual = ColumnVectors.ofLong(actual, "bigDecimalCol").toArray(); + long[] bdExpected = ColumnVectors.ofLong(expected, "bigDecimalCol").toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { final long actualVal = biActual[ii]; - final long expectedVal = (long) biExpected[ii]; + final long expectedVal = biExpected[ii]; Assert.eq(actualVal, "values match", expectedVal); } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingGroup.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingGroup.java index dd3c0b03345..e9faa243e10 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingGroup.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingGroup.java @@ -12,8 +12,8 @@ import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -150,9 +150,8 @@ private void doTestStaticZeroKey(final int prevTicks, final int postTicks) { final Table summed = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, columns)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingGroupTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingGroupTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -166,16 +165,16 @@ private void doTestStaticZeroKeyTimed(final Duration prevTime, final Duration po t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, columns)); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingGroupTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingGroupTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -286,9 +285,9 @@ private void doTestStaticBucketed(boolean grouped, int prevTicks, int postTicks) preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithRollingGroupTicks(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getType(), prevTicks, postTicks); + assertWithRollingGroupTicks( + ColumnVectors.of(source, col).toArray(), ColumnVectors.of(actual, col).toArray(), + actual.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); }); return source; }); @@ -310,16 +309,16 @@ private void doTestStaticBucketedTimed(boolean grouped, Duration prevTime, Durat String[] columns = t.getDefinition().getColumnStream().map(ColumnDefinition::getName).toArray(String[]::new); preOp.partitionedTransform(postOp, (source, actual) -> { - Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); long[] timestamps = new long[source.intSize()]; for (int i = 0; i < source.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - assertWithRollingGroupTime(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - timestamps, - DataAccessHelpers.getColumn(actual, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingGroupTime( + ColumnVectors.of(source, col).toArray(), ColumnVectors.of(actual, col).toArray(), + timestamps, actual.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); }); return source; }); @@ -1041,39 +1040,39 @@ public void testFilteredUngroup() { // Test mod 2. Table filteredTable = ungrouped.where("mod2==0"); - int[] filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + int[] filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(0, "filteredArray[ii] % 2", filteredArray[ii] % 2); } filteredTable = ungrouped.where("mod2==1"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(1, "filteredArray[ii] % 2", filteredArray[ii] % 2); } // Test mod 5 filteredTable = ungrouped.where("mod5==0"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(0, "filteredArray[ii] % 5", filteredArray[ii] % 5); } filteredTable = ungrouped.where("mod5==1"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(1, "filteredArray[ii] % 5", filteredArray[ii] % 5); } filteredTable = ungrouped.where("mod5==2"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(2, "filteredArray[ii] % 5", filteredArray[ii] % 5); } filteredTable = ungrouped.where("mod5==3"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(3, "filteredArray[ii] % 5", filteredArray[ii] % 5); } filteredTable = ungrouped.where("mod5==4"); - filteredArray = (int[]) DataAccessHelpers.getColumn(filteredTable, "idx").getDirect(); + filteredArray = ColumnVectors.ofInt(filteredTable, "idx").toArray(); for (int ii = 0; ii < filteredArray.length; ii++) { Assert.eq(4, "filteredArray[ii] % 5", filteredArray[ii] % 5); } @@ -1099,9 +1098,8 @@ public void testCombinedGroupStatic() { final Table summed = t.updateBy(ops); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingGroupTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingGroupTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java index ed4be9a2cd2..e3d0b3cd7c3 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java @@ -10,8 +10,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -211,25 +211,25 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -241,25 +241,25 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); - biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -280,25 +280,25 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -310,25 +310,25 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); - biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -349,25 +349,25 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -379,25 +379,25 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); - biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -419,25 +419,25 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -451,25 +451,25 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); - biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java index 9c321168d39..d81866adbb8 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java @@ -11,9 +11,9 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.indexer.DataIndexer; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.*; import io.deephaven.engine.util.TableDiff; @@ -210,25 +210,25 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { // Do a fuzzy compare. BigDecimal diff = actualVal.subtract(expectedVal, mathContextDefault).abs(); @@ -252,25 +252,25 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { // Do a fuzzy compare. BigDecimal diff = actualVal.subtract(expectedVal, mathContextDefault).abs(); @@ -293,25 +293,25 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { // Do a fuzzy compare. BigDecimal diff = actualVal.subtract(expectedVal, mathContextDefault).abs(); @@ -335,25 +335,25 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); - BigInteger[] biActual = (BigInteger[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); + BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigInteger actualVal = biActual[ii]; - BigInteger expectedVal = (BigInteger) biExpected[ii]; + BigInteger expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { // Do a fuzzy compare. BigDecimal diff = actualVal.subtract(expectedVal, mathContextDefault).abs(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java index 50e13e91b73..2ad5b0bea49 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java @@ -10,8 +10,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -180,25 +180,25 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -215,25 +215,25 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -250,25 +250,25 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } @@ -286,25 +286,25 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; if (actualVal != null || expectedVal != null) { Assert.eqTrue(actualVal.compareTo(expectedVal) == 0, "values match"); } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingSum.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingSum.java index c92fe6f46d8..c985d4dd766 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingSum.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingSum.java @@ -9,9 +9,9 @@ import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.TableDefaults; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -73,9 +73,10 @@ public void testStaticZeroKeyWithAllNullWindows() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks( + ColumnVectors.of(t, col).toArray(), + ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -89,9 +90,8 @@ public void testStaticZeroKeyRev() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -105,9 +105,8 @@ public void testStaticZeroKeyRevExclusive() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -121,9 +120,8 @@ public void testStaticZeroKeyFwd() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -137,9 +135,8 @@ public void testStaticZeroKeyFwdExclusive() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -153,9 +150,8 @@ public void testStaticZeroKeyFwdRevWindow() { final Table summed = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks)); for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + summed.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); } } @@ -175,16 +171,16 @@ public void testStaticZeroKeyTimedRev() { "doubleCol", "boolCol", "bigIntCol", "bigDecimalCol")); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -204,16 +200,16 @@ public void testStaticZeroKeyTimedRevExclusive() { "doubleCol", "boolCol", "bigIntCol", "bigDecimalCol")); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -233,16 +229,16 @@ public void testStaticZeroKeyTimedFwd() { "doubleCol", "boolCol", "bigIntCol", "bigDecimalCol")); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -262,16 +258,16 @@ public void testStaticZeroKeyTimedFwdExclusive() { "doubleCol", "boolCol", "bigIntCol", "bigDecimalCol")); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -291,16 +287,16 @@ public void testStaticZeroKeyTimedFwdRev() { "doubleCol", "boolCol", "bigIntCol", "bigDecimalCol")); - final Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(t, "ts").getDirect(); + final Instant[] ts = ColumnVectors.ofObject(t, "ts", Instant.class).toArray(); final long[] timestamps = new long[t.intSize()]; for (int i = 0; i < t.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } for (String col : t.getDefinition().getColumnNamesArray()) { - assertWithRollingSumTime(DataAccessHelpers.getColumn(t, col).getDirect(), - DataAccessHelpers.getColumn(summed, col).getDirect(), timestamps, - DataAccessHelpers.getColumn(summed, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime(ColumnVectors.of(t, col).toArray(), ColumnVectors.of(summed, col).toArray(), + timestamps, summed.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); } } @@ -391,9 +387,10 @@ private void doTestStaticBucketed(boolean grouped, int prevTicks, int postTicks) preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { - assertWithRollingSumTicks(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getType(), prevTicks, postTicks); + assertWithRollingSumTicks( + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), + actual.getDefinition().getColumn(col).getDataType(), prevTicks, postTicks); }); return source; }); @@ -452,16 +449,17 @@ private void doTestStaticBucketedTimed(boolean grouped, Duration prevTime, Durat String[] columns = t.getDefinition().getColumnStream().map(ColumnDefinition::getName).toArray(String[]::new); preOp.partitionedTransform(postOp, (source, actual) -> { - Instant[] ts = (Instant[]) DataAccessHelpers.getColumn(source, "ts").getDirect(); + Instant[] ts = ColumnVectors.ofObject(source, "ts", Instant.class).toArray(); long[] timestamps = new long[source.intSize()]; for (int i = 0; i < source.intSize(); i++) { timestamps[i] = DateTimeUtils.epochNanos(ts[i]); } Arrays.stream(columns).forEach(col -> { - assertWithRollingSumTime(DataAccessHelpers.getColumn(source, col).getDirect(), - DataAccessHelpers.getColumn(actual, col).getDirect(), - timestamps, - DataAccessHelpers.getColumn(actual, col).getType(), prevTime.toNanos(), postTime.toNanos()); + assertWithRollingSumTime( + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), + timestamps, actual.getDefinition().getColumn(col).getDataType(), + prevTime.toNanos(), postTime.toNanos()); }); return source; }); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java index 30ac4b6ecba..c9d8c77fbeb 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java @@ -10,8 +10,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.QueryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.GenerateTableUpdates; @@ -395,24 +395,24 @@ private void doTestStaticBigNumbers(final QueryTable t, .update(updateCols); } - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; Assert.eqTrue(fuzzyEquals(actualVal, expectedVal), "values match"); } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; Assert.eqTrue(fuzzyEquals(actualVal, expectedVal), "values match"); } @@ -452,24 +452,24 @@ private void doTestStaticTimedBigNumbers(final QueryTable t, .update(updateCols); } - BigDecimal[] biActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigIntCol").getDirect(); - Object[] biExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigIntCol").getDirect(); + BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); + BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); Assert.eq(biActual.length, "array length", biExpected.length); for (int ii = 0; ii < biActual.length; ii++) { BigDecimal actualVal = biActual[ii]; - BigDecimal expectedVal = (BigDecimal) biExpected[ii]; + BigDecimal expectedVal = biExpected[ii]; Assert.eqTrue(fuzzyEquals(actualVal, expectedVal), "values match"); } - BigDecimal[] bdActual = (BigDecimal[]) DataAccessHelpers.getColumn(actual, "bigDecimalCol").getDirect(); - Object[] bdExpected = (Object[]) DataAccessHelpers.getColumn(expected, "bigDecimalCol").getDirect(); + BigDecimal[] bdActual = ColumnVectors.ofObject(actual, "bigDecimalCol", BigDecimal.class).toArray(); + BigDecimal[] bdExpected = ColumnVectors.ofObject(expected, "bigDecimalCol", BigDecimal.class).toArray(); Assert.eq(bdActual.length, "array length", bdExpected.length); for (int ii = 0; ii < bdActual.length; ii++) { BigDecimal actualVal = bdActual[ii]; - BigDecimal expectedVal = (BigDecimal) bdExpected[ii]; + BigDecimal expectedVal = bdExpected[ii]; Assert.eqTrue(fuzzyEquals(actualVal, expectedVal), "values match"); } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/TestSyncTableFilter.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/TestSyncTableFilter.java index b90ce4bf90d..96a7bdb9e8a 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/TestSyncTableFilter.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/TestSyncTableFilter.java @@ -6,8 +6,8 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.rowset.RowSet; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.ControlledUpdateGraph; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.testutil.TstUtils; import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; import io.deephaven.engine.util.TableTools; @@ -393,7 +393,7 @@ public void testDependencies() { updateGraph.completeCycleForUnitTests(); showWithRowSet(sentSum); - int[] actual = (int[]) DataAccessHelpers.getColumn(sentSum, "SS").getDirect(); + int[] actual = ColumnVectors.ofInt(sentSum, "SS").toArray(); int[] expected = new int[] {606, 610}; assertEquals(expected, actual); } diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestCalendarMethodsFromTable.java b/engine/table/src/test/java/io/deephaven/engine/util/TestCalendarMethodsFromTable.java index 0bdeacd8ea4..e69943a0145 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestCalendarMethodsFromTable.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestCalendarMethodsFromTable.java @@ -6,7 +6,7 @@ import io.deephaven.engine.context.ExecutionContext; import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; @@ -63,8 +63,7 @@ public class TestCalendarMethodsFromTable { @SuppressWarnings("SameParameterValue") private Object getVal(final Table t, final String column) { - // noinspection deprecation - return DataAccessHelpers.getColumn(t, column).get(0); + return t.getColumnSource(column).get(t.getRowSet().firstRowKey()); } @SuppressWarnings("StringConcatenationInLoop") diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestColorUtil.java b/engine/table/src/test/java/io/deephaven/engine/util/TestColorUtil.java index b32ca284c35..cd0b0f41687 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestColorUtil.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestColorUtil.java @@ -5,11 +5,12 @@ import io.deephaven.base.testing.BaseArrayTestCase; import io.deephaven.engine.context.TestExecutionContext; -import io.deephaven.engine.table.impl.DataAccessHelpers; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.gui.color.Color; import io.deephaven.engine.table.Table; import io.deephaven.util.QueryConstants; import io.deephaven.util.SafeCloseable; +import org.jetbrains.annotations.NotNull; import static io.deephaven.gui.color.Color.*; @@ -291,8 +292,7 @@ public void testIsForegroundSet() { private void testRowFormatWhere(final Table colorTable, final Color color) { final long[] colorTableCol = - DataAccessHelpers.getColumn(colorTable, ColumnFormatting.getRowStyleFormatColumn()) - .getLongs(0, size); + ColumnVectors.ofLong(colorTable, ColumnFormatting.getRowStyleFormatColumn()).toArray(); for (int i = 0; i < 6; i++) { // assertEquals(0L, colorTableCol[i]); @@ -303,8 +303,8 @@ private void testRowFormatWhere(final Table colorTable, final Color color) { } private void testFormatColumns(final Table colorTable, final Color color) { - final long[] colorTableCol = - DataAccessHelpers.getColumn(colorTable, ColumnFormatting.getStyleFormatColumn("X")).getLongs(0, size); + final @NotNull String columnName = ColumnFormatting.getStyleFormatColumn("X"); + final long[] colorTableCol = ColumnVectors.ofLong(colorTable, columnName).toArray(); for (long aColorTableCol : colorTableCol) { assertEquals(ColorUtil.toLong(color), aColorTableCol); } diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestOuterJoinTools.java b/engine/table/src/test/java/io/deephaven/engine/util/TestOuterJoinTools.java index 037c90cf7fc..adb30d4dc77 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestOuterJoinTools.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestOuterJoinTools.java @@ -4,17 +4,17 @@ package io.deephaven.engine.util; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.junit4.EngineCleanup; import org.junit.Rule; import org.junit.Test; -import java.util.Arrays; - import static io.deephaven.engine.testutil.TstUtils.testRefreshingTable; import static io.deephaven.engine.testutil.TstUtils.testTable; import static io.deephaven.engine.util.TableTools.col; import static io.deephaven.engine.util.TableTools.intCol; +import static io.deephaven.util.QueryConstants.NULL_INT; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; public class TestOuterJoinTools { @@ -27,35 +27,35 @@ public void testLeftOuterJoin() { Table rTable = testRefreshingTable(col("Y", "a", "b", "b"), intCol("Z", 1, 2, 3)); Table result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X=Y"); assertEquals(4, result.size()); - assertEquals(3, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals("Z", DataAccessHelpers.getColumns(result)[2].getName()); - assertEquals(Arrays.asList("a", "b", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", "b", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); - assertEquals(Arrays.asList(1, 2, 3, null), Arrays.asList(DataAccessHelpers.getColumn(result, "Z").get(0, 4))); + assertEquals(3, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertEquals("Z", result.getDefinition().getColumnsArray()[2].getName()); + assertArrayEquals(new String[] {"a", "b", "b", "c"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "b", null}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3, NULL_INT}, ColumnVectors.ofInt(result, "Z").toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b")); result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X=Y"); TableTools.show(result); assertEquals(3, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); - assertEquals(Arrays.asList("a", "b", null), Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 3))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null}, ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("X", "a", "b", "d")); result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X"); TableTools.show(result); assertEquals(3, result.size()); - assertEquals(1, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals(Arrays.asList("a", "b", "c"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); + assertEquals(1, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); } @Test @@ -64,35 +64,35 @@ public void testLeftOuterJoinStatic() { Table rTable = testTable(col("Y", "a", "b", "b"), col("Z", 1, 2, 3)); Table result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X=Y").select(); assertEquals(4, result.size()); - assertEquals(3, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals("Z", DataAccessHelpers.getColumns(result)[2].getName()); - assertEquals(Arrays.asList("a", "b", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", "b", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); - assertEquals(Arrays.asList(1, 2, 3, null), Arrays.asList(DataAccessHelpers.getColumn(result, "Z").get(0, 4))); + assertEquals(3, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertEquals("Z", result.getDefinition().getColumnsArray()[2].getName()); + assertArrayEquals(new String[] {"a", "b", "b", "c"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "b", null}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3, NULL_INT}, ColumnVectors.ofInt(result, "Z").toArray()); lTable = testTable(col("X", "a", "b", "c")); rTable = testTable(col("Y", "a", "b")); result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X=Y").select(); TableTools.show(result); assertEquals(3, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); - assertEquals(Arrays.asList("a", "b", null), Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 3))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null}, ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testTable(col("X", "a", "b", "c")); rTable = testTable(col("X", "a", "b", "d")); result = OuterJoinTools.leftOuterJoin(lTable, rTable, "X").select(); TableTools.show(result); assertEquals(3, result.size()); - assertEquals(1, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals(Arrays.asList("a", "b", "c"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); + assertEquals(1, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); } @Test @@ -101,15 +101,15 @@ public void testFullOuterJoin() { Table rTable = testRefreshingTable(col("Y", "a", "b", "b"), intCol("Z", 1, 2, 3)); Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y"); assertEquals(4, result.size()); - assertEquals(3, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals("Z", DataAccessHelpers.getColumns(result)[2].getName()); - assertEquals(Arrays.asList("a", "b", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", "b", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); - assertEquals(Arrays.asList(1, 2, 3, null), Arrays.asList(DataAccessHelpers.getColumn(result, "Z").get(0, 4))); + assertEquals(3, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertEquals("Z", result.getDefinition().getColumnsArray()[2].getName()); + assertArrayEquals(new String[] {"a", "b", "b", "c"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "b", null}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); + assertArrayEquals(new int[] {1, 2, 3, NULL_INT}, ColumnVectors.ofInt(result, "Z").toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b", "d"), intCol("Z", 1, 2, 3)); @@ -118,60 +118,60 @@ public void testFullOuterJoin() { TableTools.showWithRowSet(rTable); TableTools.showWithRowSet(result); assertEquals(4, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", null, "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null, "d"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b")); result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y"); TableTools.show(result); assertEquals(3, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c"), Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 3))); - assertEquals(Arrays.asList("a", "b", null), Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 3))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c"}, ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null}, ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b", "d")); result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y"); TableTools.show(result); assertEquals(4, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", null, "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null, "d"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b", "b")); result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y"); TableTools.show(result); assertEquals(4, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "b", "c"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", "b", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "b", "c"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", "b", null}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); lTable = testRefreshingTable(col("X", "a", "b", "c")); rTable = testRefreshingTable(col("X", "a", "b", "d")); result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X"); TableTools.show(result); assertEquals(4, result.size()); - assertEquals(1, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals(Arrays.asList("a", "b", "c", "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); + assertEquals(1, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertArrayEquals(new String[] {"a", "b", "c", "d"}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); } @Test @@ -180,13 +180,13 @@ public void testFullOuterJoinAddColumnsDoesNotIncludeRightMatchColumns() { Table rTable = testRefreshingTable(col("Y", "a", "b", "d"), intCol("Z", 1, 2, 3)); Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y", "A=Y"); assertEquals(4, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("A", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("a", "b", null, "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "A").get(0, 4))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("A", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "b", null, "d"}, + ColumnVectors.ofObject(result, "A", String.class).toArray()); } @Test @@ -195,13 +195,13 @@ public void testFullOuterJoinAddColumnRenamesToOverrideMatchColumnName() { Table rTable = testRefreshingTable(col("Y", "a", "b", "d"), col("Z", "e", "f", "g")); Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y", "Y=Z"); assertEquals(4, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4))); - assertEquals(Arrays.asList("e", "f", null, "g"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"e", "f", null, "g"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); } @Test @@ -212,16 +212,15 @@ public void testFullOuterJoinMultipleMatchesBothSides() { intCol("Z", 1, 2, 3, 4)); Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y"); assertEquals(6, result.size()); - assertEquals(3, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals("Z", DataAccessHelpers.getColumns(result)[2].getName()); - assertEquals(Arrays.asList("a", "a", "b", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 6))); - assertEquals(Arrays.asList("a", "a", "b", "b", null, "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 6))); - assertEquals(Arrays.asList(1, 1, 2, 3, null, 4), - Arrays.asList(DataAccessHelpers.getColumn(result, "Z").get(0, 6))); + assertEquals(3, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertEquals("Z", result.getDefinition().getColumnsArray()[2].getName()); + assertArrayEquals(new String[] {"a", "a", "b", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "a", "b", "b", null, "d"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); + assertArrayEquals(new int[] {1, 1, 2, 3, NULL_INT, 4}, ColumnVectors.ofInt(result, "Z").toArray()); lTable = testRefreshingTable(col("X", "a", "a", "b", "c")); rTable = testRefreshingTable(col("Y", "a", "b", "b", "d"), intCol("Z", 1, 2, 3, 4)); @@ -230,13 +229,13 @@ public void testFullOuterJoinMultipleMatchesBothSides() { TableTools.showWithRowSet(rTable); TableTools.showWithRowSet(result); assertEquals(6, result.size()); - assertEquals(2, DataAccessHelpers.getColumns(result).length); - assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals(Arrays.asList("a", "a", "b", "b", "c", null), - Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 6))); - assertEquals(Arrays.asList("a", "a", "b", "b", null, "d"), - Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 6))); + assertEquals(2, result.numColumns()); + assertEquals("X", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("Y", result.getDefinition().getColumnsArray()[1].getName()); + assertArrayEquals(new String[] {"a", "a", "b", "b", "c", null}, + ColumnVectors.ofObject(result, "X", String.class).toArray()); + assertArrayEquals(new String[] {"a", "a", "b", "b", null, "d"}, + ColumnVectors.ofObject(result, "Y", String.class).toArray()); } @Test @@ -246,12 +245,12 @@ public void testFullOuterJoinIdentityMatchWithAddColumn() { Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "a", "c"); assertEquals(4, result.size()); - assertEquals(3, DataAccessHelpers.getColumns(result).length); - assertEquals("a", DataAccessHelpers.getColumns(result)[0].getName()); - assertEquals("b", DataAccessHelpers.getColumns(result)[1].getName()); - assertEquals("c", DataAccessHelpers.getColumns(result)[2].getName()); - assertEquals(Arrays.asList(0, 1, 2, 3), Arrays.asList(DataAccessHelpers.getColumn(result, "a").get(0, 9))); - assertEquals(Arrays.asList(0, 2, 4, 6), Arrays.asList(DataAccessHelpers.getColumn(result, "b").get(0, 9))); - assertEquals(Arrays.asList(0, 3, 6, 9), Arrays.asList(DataAccessHelpers.getColumn(result, "c").get(0, 9))); + assertEquals(3, result.numColumns()); + assertEquals("a", result.getDefinition().getColumnsArray()[0].getName()); + assertEquals("b", result.getDefinition().getColumnsArray()[1].getName()); + assertEquals("c", result.getDefinition().getColumnsArray()[2].getName()); + assertArrayEquals(new int[] {0, 1, 2, 3}, ColumnVectors.ofInt(result, "a").toArray()); + assertArrayEquals(new int[] {0, 2, 4, 6}, ColumnVectors.ofInt(result, "b").toArray()); + assertArrayEquals(new int[] {0, 3, 6, 9}, ColumnVectors.ofInt(result, "c").toArray()); } } diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java b/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java index fcdccf4a1f5..851d4112b16 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java @@ -13,10 +13,10 @@ import io.deephaven.engine.table.*; import io.deephaven.engine.table.impl.InstrumentedTableUpdateListener; import io.deephaven.engine.table.impl.QueryTable; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.TableUpdateImpl; import io.deephaven.engine.table.impl.sources.UnionRedirection; import io.deephaven.engine.table.impl.util.ColumnHolder; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.*; import io.deephaven.engine.testutil.generator.DoubleGenerator; import io.deephaven.engine.testutil.generator.IntGenerator; @@ -28,6 +28,7 @@ import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; import io.deephaven.util.QueryConstants; +import io.deephaven.vector.IntVector; import junit.framework.TestCase; import org.junit.Assert; import org.junit.Before; @@ -44,6 +45,7 @@ import static io.deephaven.util.QueryConstants.NULL_FLOAT; import static io.deephaven.util.QueryConstants.NULL_INT; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; /** * Unit tests for {@link TableTools}. @@ -152,70 +154,69 @@ public void testMergeWithWhere() { TableTools.show(t_3_4_filtered); TableTools.show(t_all); - Assert.assertEquals(t_all.size(), 3); - assertArrayEquals((Object[]) DataAccessHelpers.getColumn(t_all, "Col").getDirect(), - new String[] {"A", "B", "D"}); + assertEquals(t_all.size(), 3); + assertArrayEquals(new String[] {"A", "B", "D"}, ColumnVectors.ofObject(t_all, "Col", String.class).toArray()); } @Test public void testDiff() { - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2 expected null\n", TableTools.diff(TableTools.newTable(intCol("x", 1, 2, 3)), TableTools.newTable(intCol("x", 1, NULL_INT, NULL_INT)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered null expected 2\n", TableTools.diff(TableTools.newTable(intCol("x", 1, NULL_INT, NULL_INT)), TableTools.newTable(intCol("x", 1, 2, 3)), 10)); - Assert.assertEquals("", + assertEquals("", TableTools.diff(TableTools.newTable(col("x", 1, 2, 3)), TableTools.newTable(col("x", 1, 2, 3)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0 expected null\n", TableTools.diff(TableTools.newTable(col("x", 1.0, 2.0, 3.0)), TableTools.newTable(col("x", 1.0, null, null)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered null expected 2.0\n", TableTools.diff(TableTools.newTable(col("x", 1.0, null, null)), TableTools.newTable(col("x", 1.0, 2.0, 3.0)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0E-12 expected null\n", TableTools.diff(TableTools.newTable(col("x", 0.000000000001, 0.000000000002, 0.000000000003)), TableTools.newTable(col("x", 0.000000000001, null, null)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0E-12 expected null\n", TableTools.diff(TableTools.newTable(col("x", 0.000000000001, 0.000000000002, 0.000000000003)), TableTools.newTable(col("x", 0.000000000002, null, null)), 10, EnumSet.of(TableDiff.DiffItems.DoublesExact))); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 0 encountered 1.0E-12 expected 2.0E-12 (difference = 1.0E-12)\n", TableTools.diff(TableTools.newTable(col("x", 0.000000000001, 0.000000000002, 0.000000000003)), TableTools.newTable(col("x", 0.000000000002, null, null)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered null expected 2.0\n", TableTools.diff(TableTools.newTable(floatCol("x", 1.0f, NULL_FLOAT, NULL_FLOAT)), TableTools.newTable(floatCol("x", 1.0f, 2.0f, 3.0f)), 10)); - Assert.assertEquals("", TableTools.diff(TableTools.newTable(floatCol("x", 1, 2, 3)), + assertEquals("", TableTools.diff(TableTools.newTable(floatCol("x", 1, 2, 3)), TableTools.newTable(floatCol("x", 1.0f, 2.0f, 3.0f)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0 expected null\n", TableTools.diff(TableTools.newTable(floatCol("x", 1.0f, 2.0f, 3.0f)), TableTools.newTable(floatCol("x", 1.0f, NULL_FLOAT, NULL_FLOAT)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered null expected 2.0\n", TableTools.diff(TableTools.newTable(floatCol("x", 1.0f, NULL_FLOAT, NULL_FLOAT)), TableTools.newTable(floatCol("x", 1.0f, 2.0f, 3.0f)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0E-12 expected null\n", TableTools.diff(TableTools.newTable(floatCol("x", 0.000000000001f, 0.000000000002f, 0.000000000003f)), TableTools.newTable(floatCol("x", 0.000000000001f, NULL_FLOAT, NULL_FLOAT)), 10)); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 1 encountered 2.0E-12 expected null\n", TableTools.diff(TableTools.newTable(floatCol("x", 0.000000000001f, 0.000000000002f, 0.000000000003f)), TableTools.newTable(floatCol("x", 0.000000000002f, NULL_FLOAT, NULL_FLOAT)), 10, EnumSet.of(TableDiff.DiffItems.DoublesExact))); - Assert.assertEquals( + assertEquals( "Column x different from the expected set, first difference at row 0 encountered 1.0E-12 expected 2.0E-12 (difference = 1.0E-12)\n", TableTools.diff(TableTools.newTable(floatCol("x", 0.000000000001f, 0.000000000002f, 0.000000000003f)), TableTools.newTable(floatCol("x", 0.000000000002f, NULL_FLOAT, NULL_FLOAT)), 10)); @@ -262,45 +263,40 @@ public void testRoundDecimalColumns() { // Test whether we're rounding all columns properly Table roundedColumns = TableTools.roundDecimalColumns(table); - Assert.assertArrayEquals((String[]) DataAccessHelpers.getColumn(roundedColumns, "String").getDirect(), - (String[]) DataAccessHelpers.getColumn(table, "String").getDirect()); - Assert.assertArrayEquals((int[]) DataAccessHelpers.getColumn(roundedColumns, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(table, "Int").getDirect()); - Assert.assertEquals(Math.round((double) DataAccessHelpers.getColumn(table, "Double").get(0)), - DataAccessHelpers.getColumn(roundedColumns, "Double").get(0)); - Assert.assertEquals(Math.round((double) DataAccessHelpers.getColumn(table, "Double").get(1)), - DataAccessHelpers.getColumn(roundedColumns, "Double").get(1)); - Assert.assertEquals(Math.round((double) DataAccessHelpers.getColumn(table, "Double").get(2)), - DataAccessHelpers.getColumn(roundedColumns, "Double").get(2)); + assertEquals(ColumnVectors.of(roundedColumns, "String"), ColumnVectors.of(table, "String")); + assertEquals(ColumnVectors.of(roundedColumns, "Int"), ColumnVectors.of(table, "Int")); + assertEquals(Math.round(table.getColumnSource("Double").getDouble(table.getRowSet().get(0))), + roundedColumns.getColumnSource("Double").getLong(roundedColumns.getRowSet().get(0))); + assertEquals(Math.round(table.getColumnSource("Double").getDouble(table.getRowSet().get(1))), + roundedColumns.getColumnSource("Double").getLong(roundedColumns.getRowSet().get(1))); + assertEquals(Math.round(table.getColumnSource("Double").getDouble(table.getRowSet().get(2))), + roundedColumns.getColumnSource("Double").getLong(roundedColumns.getRowSet().get(2))); // Cast these cause the DB rounds floats to longs - Assert.assertEquals((long) Math.round((float) DataAccessHelpers.getColumn(table, "Float").get(0)), - DataAccessHelpers.getColumn(roundedColumns, "Float").get(0)); - Assert.assertEquals((long) Math.round((float) DataAccessHelpers.getColumn(table, "Float").get(1)), - DataAccessHelpers.getColumn(roundedColumns, "Float").get(1)); - Assert.assertEquals((long) Math.round((float) DataAccessHelpers.getColumn(table, "Float").get(2)), - DataAccessHelpers.getColumn(roundedColumns, "Float").get(2)); + assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(0))), + roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(0))); + assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(1))), + roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(1))); + assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(2))), + roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(2))); // Test whether it works when we specify the columns, by comparing to the validated results from before - Table specificRoundedColums = TableTools.roundDecimalColumns(table, "Double", "Float"); - Assert.assertArrayEquals((String[]) DataAccessHelpers.getColumn(roundedColumns, "String").getDirect(), - (String[]) DataAccessHelpers.getColumn(specificRoundedColums, "String").getDirect()); - Assert.assertArrayEquals((int[]) DataAccessHelpers.getColumn(roundedColumns, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(specificRoundedColums, "Int").getDirect()); - Assert.assertArrayEquals((long[]) DataAccessHelpers.getColumn(roundedColumns, "Double").getDirect(), - (long[]) DataAccessHelpers.getColumn(specificRoundedColums, "Double").getDirect()); - Assert.assertArrayEquals((long[]) DataAccessHelpers.getColumn(roundedColumns, "Float").getDirect(), - (long[]) DataAccessHelpers.getColumn(specificRoundedColums, "Float").getDirect()); + Table specificRoundedColumns = TableTools.roundDecimalColumns(table, "Double", "Float"); + assertEquals(ColumnVectors.ofObject(roundedColumns, "String", String.class), + ColumnVectors.ofObject(specificRoundedColumns, "String", String.class)); + assertEquals(ColumnVectors.ofInt(roundedColumns, "Int"), ColumnVectors.ofInt(specificRoundedColumns, "Int")); + assertEquals(ColumnVectors.ofLong(roundedColumns, "Double"), + ColumnVectors.ofLong(specificRoundedColumns, "Double")); + assertEquals(ColumnVectors.ofLong(roundedColumns, "Float"), + ColumnVectors.ofLong(specificRoundedColumns, "Float")); // Test whether it works properly when we specify what NOT to round Table onlyOneRoundedColumn = TableTools.roundDecimalColumnsExcept(table, "Float"); - Assert.assertArrayEquals((String[]) DataAccessHelpers.getColumn(roundedColumns, "String").getDirect(), - (String[]) DataAccessHelpers.getColumn(onlyOneRoundedColumn, "String").getDirect()); - Assert.assertArrayEquals((int[]) DataAccessHelpers.getColumn(table, "Int").getDirect(), - (int[]) DataAccessHelpers.getColumn(onlyOneRoundedColumn, "Int").getDirect()); - Assert.assertArrayEquals((long[]) DataAccessHelpers.getColumn(roundedColumns, "Double").getDirect(), - (long[]) DataAccessHelpers.getColumn(onlyOneRoundedColumn, "Double").getDirect()); - Assert.assertArrayEquals((float[]) DataAccessHelpers.getColumn(table, "Float").getDirect(), - (float[]) DataAccessHelpers.getColumn(onlyOneRoundedColumn, "Float").getDirect(), 0.0f); + assertEquals(ColumnVectors.ofObject(roundedColumns, "String", String.class), + ColumnVectors.ofObject(onlyOneRoundedColumn, "String", String.class)); + assertEquals(ColumnVectors.ofInt(table, "Int"), ColumnVectors.ofInt(onlyOneRoundedColumn, "Int")); + assertEquals(ColumnVectors.ofLong(roundedColumns, "Double"), + ColumnVectors.ofLong(onlyOneRoundedColumn, "Double")); + assertEquals(ColumnVectors.ofFloat(table, "Float"), ColumnVectors.ofFloat(onlyOneRoundedColumn, "Float")); try { // Make sure we complain if you try to round the unroundable @@ -327,24 +323,23 @@ public void testInstantColumnHolder() { // make sure both columns are in fact Instant columns final Table meta = table.meta(); - Assert.assertEquals(Instant.class.getCanonicalName(), DataAccessHelpers.getColumn(meta, "DataType").get(0)); - Assert.assertEquals(Instant.class.getCanonicalName(), DataAccessHelpers.getColumn(meta, "DataType").get(1)); + assertEquals(Instant.class.getCanonicalName(), meta.getColumnSource("DataType", String.class).get(0)); + assertEquals(Instant.class.getCanonicalName(), meta.getColumnSource("DataType", String.class).get(1)); // make sure this doesn't crash showWithRowSet(table); // validate column1 (backed with Instant objects) - Assert.assertEquals(data[0], DataAccessHelpers.getColumn(table, 0).get(0)); - Assert.assertEquals(data[1], DataAccessHelpers.getColumn(table, 0).get(1)); - Assert.assertEquals(data[2], DataAccessHelpers.getColumn(table, 0).get(2)); + final String column1Name = table.getDefinition().getColumns().get(0).getName(); + assertArrayEquals(data, ColumnVectors.ofObject(table, column1Name, Instant.class).toArray()); // validate column2 (backed with longs, but should be get-able as Instants as well) - Assert.assertEquals(data[0], DataAccessHelpers.getColumn(table, 1).get(0)); - Assert.assertEquals(data[1], DataAccessHelpers.getColumn(table, 1).get(1)); - Assert.assertEquals(data[2], DataAccessHelpers.getColumn(table, 1).get(2)); - Assert.assertEquals(longData[0], DataAccessHelpers.getColumn(table, 1).getLong(0)); - Assert.assertEquals(longData[1], DataAccessHelpers.getColumn(table, 1).getLong(1)); - Assert.assertEquals(longData[2], DataAccessHelpers.getColumn(table, 1).getLong(2)); + final String column2Name = table.getDefinition().getColumns().get(1).getName(); + final ColumnSource column2Source = table.getColumnSource(column2Name, Instant.class); + assertArrayEquals(data, ColumnVectors.ofObject(table, column2Name, Instant.class).toArray()); + assertEquals(longData[0], column2Source.getLong(table.getRowSet().get(0))); + assertEquals(longData[1], column2Source.getLong(table.getRowSet().get(1))); + assertEquals(longData[2], column2Source.getLong(table.getRowSet().get(2))); } @Test @@ -595,7 +590,7 @@ public void testMergeRecursive() { else result = TableTools.merge(result, table1); - Assert.assertEquals(table1.size() * (ii + 1), result.size()); + assertEquals(table1.size() * (ii + 1), result.size()); for (int jj = 0; jj <= ii; ++jj) tableRangesAreEqual(table1, result, 0, table1.size() * jj, table1.size()); @@ -610,7 +605,7 @@ public void testMergeRecursive2() { .view("StringKeys"); Table merge2 = TableTools.merge(merge1, table1.view("StringKeys")); - Assert.assertEquals(table1.size() * 2 + table2.size(), merge2.size()); + assertEquals(table1.size() * 2 + table2.size(), merge2.size()); tableRangesAreEqual(table1.view("StringKeys"), merge1, 0, 0, table1.size()); tableRangesAreEqual(table1.view("StringKeys"), merge2, 0, 0, table1.size()); @@ -635,7 +630,7 @@ public void testUncollapsableMerge() { result = TableTools.merge(result, table1).updateView("GroupedInts=GroupedInts+1") .updateView("GroupedInts=GroupedInts-1"); - Assert.assertEquals(table1.size() * (ii + 1), result.size()); + assertEquals(table1.size() * (ii + 1), result.size()); } for (int jj = 0; jj < numRecursions; ++jj) { @@ -899,13 +894,13 @@ public void testMergeGetChunk() { ? resCol.getPrevChunk(resContext, resRowSet).asIntChunk() : resCol.getChunk(resContext, resRowSet).asIntChunk(); - Assert.assertEquals(numElements, origContent.size()); - Assert.assertEquals(3 * numElements, resContent.size()); + assertEquals(numElements, origContent.size()); + assertEquals(3 * numElements, resContent.size()); for (int ii = 0; ii < numElements; ++ii) { - Assert.assertEquals(origContent.get(ii), resContent.get(ii)); - Assert.assertEquals(origContent.get(ii), resContent.get(ii + numElements) - 1); - Assert.assertEquals(origContent.get(ii), resContent.get(ii + 2 * numElements) - 1); + assertEquals(origContent.get(ii), resContent.get(ii)); + assertEquals(origContent.get(ii), resContent.get(ii + numElements) - 1); + assertEquals(origContent.get(ii), resContent.get(ii + 2 * numElements) - 1); } } } @@ -955,8 +950,8 @@ public void testMergeGetChunkEmpty() { ? resCol.getPrevChunk(resContext, rowSet).asIntChunk() : resCol.getChunk(resContext, rowSet).asIntChunk(); - Assert.assertEquals(0, origContent.size()); - Assert.assertEquals(0, resContent.size()); + assertEquals(0, origContent.size()); + assertEquals(0, resContent.size()); } } }; @@ -972,19 +967,19 @@ public void testEmptyTable() { Table emptyTable2 = TableTools.emptyTable(2).update("col=1"); TestCase.assertEquals(2, emptyTable2.size()); - DataColumn dataColumn = DataAccessHelpers.getColumn(emptyTable2, "col"); - TestCase.assertEquals(2, dataColumn.size()); - TestCase.assertEquals(1, dataColumn.get(0)); - TestCase.assertEquals(1, dataColumn.get(1)); + IntVector columnVector = ColumnVectors.ofInt(emptyTable2, "col"); + TestCase.assertEquals(2, columnVector.size()); + TestCase.assertEquals(1, columnVector.get(0)); + TestCase.assertEquals(1, columnVector.get(1)); TableTools.show(emptyTable2); Table emptyTable3 = TableTools.emptyTable(2).updateView("col=1"); TestCase.assertEquals(2, emptyTable3.size()); - dataColumn = DataAccessHelpers.getColumn(emptyTable3, "col"); - TestCase.assertEquals(2, dataColumn.size()); - TestCase.assertEquals(1, dataColumn.get(0)); - TestCase.assertEquals(1, dataColumn.get(1)); + columnVector = ColumnVectors.ofInt(emptyTable3, "col"); + TestCase.assertEquals(2, columnVector.size()); + TestCase.assertEquals(1, columnVector.get(0)); + TestCase.assertEquals(1, columnVector.get(1)); TableTools.show(emptyTable3); } diff --git a/engine/test-utils/src/main/java/io/deephaven/engine/testutil/TstUtils.java b/engine/test-utils/src/main/java/io/deephaven/engine/testutil/TstUtils.java index 6e6266b8a2c..4975d53fc13 100644 --- a/engine/test-utils/src/main/java/io/deephaven/engine/testutil/TstUtils.java +++ b/engine/test-utils/src/main/java/io/deephaven/engine/testutil/TstUtils.java @@ -1075,4 +1075,28 @@ public void fillPrevChunk( fillChunk(context, destination, rowSequence); } } + + /** + * Fetch row data as boxed Objects for the specified row position and column names. This is not an efficient + * data-retrieval mechanism, just a convenient one. + * + * @param table The table to fetch from + * @param rowPosition The row position to fetch + * @param columnNames The names of columns to fetch; if empty, fetch all columns + * @return An array of row data as boxed Objects + */ + public static Object[] getRowData( + @NotNull Table table, + final long rowPosition, + @NotNull final String... columnNames) { + try (final SafeCloseable ignored = LivenessScopeStack.open()) { + table = table.coalesce(); + final long rowKey = table.getRowSet().get(rowPosition); + return (columnNames.length > 0 + ? Arrays.stream(columnNames).map(table::getColumnSource) + : table.getColumnSources().stream()) + .map(columnSource -> columnSource.get(rowKey)) + .toArray(Object[]::new); + } + } } diff --git a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java index 76aa701ae8f..cff4d938be4 100644 --- a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java +++ b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java @@ -29,16 +29,11 @@ import io.deephaven.csv.tokenization.Tokenizer.CustomTimeZoneParser; import io.deephaven.csv.util.CsvReaderException; import io.deephaven.datastructures.util.CollectionUtil; -import io.deephaven.engine.rowset.RowSequence; -import io.deephaven.engine.rowset.RowSequenceFactory; -import io.deephaven.engine.rowset.RowSetFactory; -import io.deephaven.engine.rowset.TrackingRowSet; +import io.deephaven.engine.rowset.*; import io.deephaven.engine.table.ChunkSink; import io.deephaven.engine.table.ColumnSource; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.impl.InMemoryTable; import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder; @@ -872,12 +867,9 @@ public static void writeCsvContents(Table source, Writer out, ZoneId timeZone, if (colNames.length == 0) { return; } - final DataColumn[] cols = new DataColumn[colNames.length]; - for (int c = 0; c < colNames.length; ++c) { - cols[c] = DataAccessHelpers.getColumn(source, colNames[c]); - } - final long size = cols[0].size(); - writeCsvContentsSeq(out, timeZone, cols, size, nullsAsEmpty, separator, progress); + final ColumnSource[] cols = + Arrays.stream(colNames).map(source::getColumnSource).toArray(ColumnSource[]::new); + writeCsvContentsSeq(out, timeZone, source.getRowSet(), cols, nullsAsEmpty, separator, progress); } /** @@ -901,8 +893,8 @@ protected static String separatorCsvEscape(String str, String separator) { * * @param out a Writer to which the header should be written * @param timeZone a time zone constant relative to which date time data should be adjusted - * @param cols an array of Deephaven DataColumns to be written - * @param size the size of the DataColumns + * @param rows a RowSet containing the row keys to be written + * @param cols an array of ColumnSources to be written * @param nullsAsEmpty if nulls should be written as blank instead of '(null)' * @param separator the delimiter for the CSV * @param progress a procedure that implements BiConsumer, and takes a progress Integer and a total size Integer to @@ -912,22 +904,25 @@ protected static String separatorCsvEscape(String str, String separator) { private static void writeCsvContentsSeq( final Writer out, final ZoneId timeZone, - final DataColumn[] cols, - final long size, + final RowSet rows, + final ColumnSource[] cols, final boolean nullsAsEmpty, final char separator, @Nullable final BiConsumer progress) throws IOException { + final long size = rows.size(); try (final SafeCloseable ignored = - QueryPerformanceRecorder.getInstance().getNugget("CsvTools.writeCsvContentsSeq()")) { + QueryPerformanceRecorder.getInstance().getNugget("CsvTools.writeCsvContentsSeq()"); + final RowSet.Iterator rowsIter = rows.iterator()) { String separatorStr = String.valueOf(separator); - for (long i = 0; i < size; i++) { + for (long ri = 0; ri < size; ri++) { for (int j = 0; j < cols.length; j++) { if (j > 0) { out.write(separatorStr); } else { out.write("\n"); } - final Object o = cols[j].get(i); + final long rowKey = rowsIter.nextLong(); + final Object o = cols[j].get(rowKey); if (o instanceof String) { out.write("" + separatorCsvEscape((String) o, separatorStr)); } else if (o instanceof Instant) { @@ -941,7 +936,7 @@ private static void writeCsvContentsSeq( } } if (progress != null) { - progress.accept(i, size); + progress.accept(ri, size); } } } diff --git a/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java b/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java index 2f94b436908..d6393ed9dc1 100644 --- a/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java +++ b/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java @@ -7,8 +7,8 @@ import io.deephaven.csv.util.CsvReaderException; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.InMemoryTable; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.TstUtils; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.test.types.OutOfBandTest; @@ -60,9 +60,11 @@ public void testTableDividendsCSV() throws CsvReaderException { Table tableDividends = CsvTools.readCsv(new ByteArrayInputStream(fileDividends.getBytes())); Assert.assertEquals(3, tableDividends.size()); Assert.assertEquals(4, tableDividends.meta().size()); - Assert.assertEquals(0.15, DataAccessHelpers.getColumn(tableDividends, 2).getDouble(1), 0.000001); - Assert.assertEquals(300, DataAccessHelpers.getColumn(tableDividends, 3).getInt(1)); - Assert.assertEquals("Z", DataAccessHelpers.getColumn(tableDividends, 0).get(2)); + Assert.assertEquals(0.15, tableDividends.getColumnSource("Price").getDouble(tableDividends.getRowSet().get(1)), + 0.000001); + Assert.assertEquals(300, + tableDividends.getColumnSource("SecurityId").getInt(tableDividends.getRowSet().get(1))); + Assert.assertEquals("Z", tableDividends.getColumnSource("Sym").get(tableDividends.getRowSet().get(2))); } @Test @@ -71,13 +73,14 @@ public void testTableDividendsCSVNoTrim() throws CsvReaderException { "GOOG, Dividend, 0.25, 200\n" + "T, Dividend, 0.15, 300\n" + " Z, Dividend, 0.18, 500"; - Table tableDividends = CsvTools - .readCsv(new ByteArrayInputStream(fileDividends.getBytes()), "DEFAULT"); + Table tableDividends = CsvTools.readCsv(new ByteArrayInputStream(fileDividends.getBytes()), "DEFAULT"); Assert.assertEquals(3, tableDividends.size()); Assert.assertEquals(4, tableDividends.meta().size()); - Assert.assertEquals(0.15, DataAccessHelpers.getColumn(tableDividends, 2).get(1)); - Assert.assertEquals(300, DataAccessHelpers.getColumn(tableDividends, 3).get(1)); - Assert.assertEquals(" Z", DataAccessHelpers.getColumn(tableDividends, 0).get(2)); + Assert.assertEquals(0.15, tableDividends.getColumnSource("Price").getDouble(tableDividends.getRowSet().get(1)), + 0.000001); + Assert.assertEquals(300, + tableDividends.getColumnSource("SecurityId").getInt(tableDividends.getRowSet().get(1))); + Assert.assertEquals(" Z", tableDividends.getColumnSource("Sym").get(tableDividends.getRowSet().get(2))); } @Test @@ -182,22 +185,25 @@ public void testLoadCsv() throws Exception { Assert.assertEquals(Boolean.class, definition.getColumns().get(6).getDataType()); Assert.assertEquals(String.format("mark1%smark2", separator), - DataAccessHelpers.getColumn(table, "colA").get(0)); - Assert.assertEquals(1, DataAccessHelpers.getColumn(table, "colB").getInt(0)); - Assert.assertEquals(1.0, DataAccessHelpers.getColumn(table, "colC").getDouble(0), 0.000001); - Assert.assertEquals("1", DataAccessHelpers.getColumn(table, "colD").get(0)); - Assert.assertNull(DataAccessHelpers.getColumn(table, "colE").get(0)); - Assert.assertNull(DataAccessHelpers.getColumn(table, "colF").get(0)); - Assert.assertEquals(Boolean.TRUE, DataAccessHelpers.getColumn(table, "colG").getBoolean(0)); - - Assert.assertNull(DataAccessHelpers.getColumn(table, "colA").get(2)); - Assert.assertEquals(QueryConstants.NULL_INT, DataAccessHelpers.getColumn(table, "colB").getInt(2)); - Assert.assertEquals(QueryConstants.NULL_DOUBLE, DataAccessHelpers.getColumn(table, "colC").getDouble(2), + table.getColumnSource("colA").get(table.getRowSet().get(0))); + Assert.assertEquals(1, table.getColumnSource("colB").getInt(table.getRowSet().get(0))); + Assert.assertEquals(1.0, table.getColumnSource("colC").getDouble(table.getRowSet().get(0)), 0.000001); + Assert.assertEquals("1", table.getColumnSource("colD").get(table.getRowSet().get(0))); + Assert.assertNull(table.getColumnSource("colE").get(table.getRowSet().get(0))); + Assert.assertNull(table.getColumnSource("colF").get(table.getRowSet().get(0))); + Assert.assertEquals(Boolean.TRUE, table.getColumnSource("colG").getBoolean(table.getRowSet().get(0))); + + Assert.assertNull(table.getColumnSource("colA").get(table.getRowSet().get(2))); + Assert.assertEquals(QueryConstants.NULL_INT, + table.getColumnSource("colB").getInt(table.getRowSet().get(2))); + Assert.assertEquals(QueryConstants.NULL_DOUBLE, + table.getColumnSource("colC").getDouble(table.getRowSet().get(2)), 0.0000001); - Assert.assertNull(DataAccessHelpers.getColumn(table, "colD").get(2)); - Assert.assertNull(DataAccessHelpers.getColumn(table, "colE").get(2)); - Assert.assertNull(DataAccessHelpers.getColumn(table, "colF").get(2)); - Assert.assertEquals(QueryConstants.NULL_BOOLEAN, DataAccessHelpers.getColumn(table, "colG").getBoolean(2)); + Assert.assertNull(table.getColumnSource("colD").get(table.getRowSet().get(2))); + Assert.assertNull(table.getColumnSource("colE").get(table.getRowSet().get(2))); + Assert.assertNull(table.getColumnSource("colF").get(table.getRowSet().get(2))); + Assert.assertEquals(QueryConstants.NULL_BOOLEAN, + table.getColumnSource("colG").getBoolean(table.getRowSet().get(2))); } } @@ -205,7 +211,6 @@ public void testLoadCsv() throws Exception { public void testWriteCsv() throws Exception { final File csvFile = new File(tmpDir, "tmp.csv"); final String[] colNames = {"StringKeys", "GroupedInts", "Doubles", "DateTime"}; - final long numCols = colNames.length; final Table tableToTest = new InMemoryTable( colNames, new Object[] { diff --git a/extensions/parquet/table/src/test/java/io/deephaven/parquet/table/TestParquetTools.java b/extensions/parquet/table/src/test/java/io/deephaven/parquet/table/TestParquetTools.java index 644fda8bbe7..1fed4ed7f92 100644 --- a/extensions/parquet/table/src/test/java/io/deephaven/parquet/table/TestParquetTools.java +++ b/extensions/parquet/table/src/test/java/io/deephaven/parquet/table/TestParquetTools.java @@ -9,11 +9,11 @@ import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.impl.InMemoryTable; import io.deephaven.engine.table.impl.UncoalescedTable; import io.deephaven.engine.table.impl.indexer.DataIndexer; import io.deephaven.engine.table.impl.locations.TableDataException; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.engine.util.TableTools; import io.deephaven.parquet.base.InvalidParquetFileException; @@ -39,7 +39,7 @@ import static io.deephaven.engine.testutil.TstUtils.assertTableEquals; import static io.deephaven.engine.testutil.TstUtils.tableRangesAreEqual; import static io.deephaven.engine.util.TableTools.*; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Tests for {@link ParquetTools}. @@ -140,14 +140,14 @@ public void testWriteTable() { path = testRoot + File.separator + "Table2.parquet"; ParquetTools.writeTable(test, path); Table test2 = ParquetTools.readTable(path); - Assert.assertEquals(10, test2.size()); - Assert.assertEquals(2, test2.numColumns()); - Assert.assertEquals(Arrays.asList(toString((Enum[]) DataAccessHelpers.getColumn(test, "enumC").get(0, 10))), - Arrays.asList(toString((Enum[]) DataAccessHelpers.getColumn(test2, "enumC").get(0, 10)))); - StringSet[] objects = (StringSet[]) DataAccessHelpers.getColumn(test, "enumSet").get(0, 10); - StringSet[] objects1 = (StringSet[]) DataAccessHelpers.getColumn(test2, "enumSet").get(0, 10); + assertEquals(10, test2.size()); + assertEquals(2, test2.numColumns()); + assertEquals(ColumnVectors.of(test, "enumC"), ColumnVectors.of(test2, "enumC")); + assertEquals(ColumnVectors.of(test, "enumSet"), ColumnVectors.of(test2, "enumSet")); + StringSet[] objects = ColumnVectors.ofObject(test, "enumSet", StringSet.class).toArray(); + StringSet[] objects1 = ColumnVectors.ofObject(test2, "enumSet", StringSet.class).toArray(); for (int i = 0; i < objects1.length; i++) { - Assert.assertEquals(new HashSet<>(Arrays.asList(objects[i].values())), + assertEquals(new HashSet<>(Arrays.asList(objects[i].values())), new HashSet<>(Arrays.asList(objects1[i].values()))); } test2.close(); @@ -157,12 +157,10 @@ public void testWriteTable() { path = testRoot + File.separator + "Table3.parquet"; ParquetTools.writeTable(test, path); test2 = ParquetTools.readTable(path); - Assert.assertEquals(10, test2.size()); - Assert.assertEquals(2, test2.numColumns()); - Assert.assertEquals(Arrays.asList(DataAccessHelpers.getColumn(test, "enumC").get(0, 10)), - Arrays.asList(DataAccessHelpers.getColumn(test2, "enumC").get(0, 10))); - Assert.assertEquals(Arrays.asList(DataAccessHelpers.getColumn(test, "enumSet").get(0, 10)), - Arrays.asList(DataAccessHelpers.getColumn(test2, "enumSet").get(0, 10))); + assertEquals(10, test2.size()); + assertEquals(2, test2.numColumns()); + assertEquals(ColumnVectors.of(test, "enumC"), ColumnVectors.of(test2, "enumC")); + assertEquals(ColumnVectors.of(test, "enumSet"), ColumnVectors.of(test2, "enumSet")); test2.close(); test = TableTools.newTable(TableDefinition.of( diff --git a/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SnapshotExampleBase.java b/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SnapshotExampleBase.java index 288c22e23ba..edff450cf78 100644 --- a/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SnapshotExampleBase.java +++ b/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SnapshotExampleBase.java @@ -8,7 +8,6 @@ import io.deephaven.engine.rowset.RowSet; import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.util.TableTools; import io.deephaven.extensions.barrage.BarrageSnapshotOptions; import io.deephaven.extensions.barrage.BarrageSubscriptionOptions; @@ -107,8 +106,7 @@ protected void execute(final BarrageSession client) throws Exception { final Table table = snapshot.partialTable(null, columns).get(); - System.out.println("Table info: rows = " + table.size() - + ", cols = " + table.numColumns()); + System.out.println("Table info: rows = " + table.size() + ", cols = " + table.numColumns()); TableTools.show(table); System.out.println(""); System.out.println(""); @@ -191,8 +189,7 @@ protected void execute(final BarrageSession client) throws Exception { final Table table = subscription.snapshotEntireTable().get(); - System.out.println( - "Table info: rows = " + table.size() + ", cols = " + DataAccessHelpers.getColumns(table).length); + System.out.println("Table info: rows = " + table.size() + ", cols = " + table.numColumns()); TableTools.show(table); System.out.println(""); } diff --git a/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SubscribeExampleBase.java b/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SubscribeExampleBase.java index 0474785125e..ca802d34111 100644 --- a/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SubscribeExampleBase.java +++ b/java-client/barrage-examples/src/main/java/io/deephaven/client/examples/SubscribeExampleBase.java @@ -10,7 +10,6 @@ import io.deephaven.engine.liveness.LivenessScopeStack; import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.Table; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.table.TableUpdate; import io.deephaven.engine.table.TableUpdateListener; import io.deephaven.engine.table.impl.InstrumentedTableUpdateListener; @@ -73,7 +72,7 @@ protected void execute(final BarrageSession client) throws Exception { System.out.println("Subscription established"); System.out.println("Table info: rows = " + subscriptionTable.size() + ", cols = " + - DataAccessHelpers.getColumns(subscriptionTable).length); + subscriptionTable.numColumns()); TableTools.show(subscriptionTable); System.out.println(); diff --git a/py/server/deephaven/numpy.py b/py/server/deephaven/numpy.py index 583c9d41514..c87f24ea40c 100644 --- a/py/server/deephaven/numpy.py +++ b/py/server/deephaven/numpy.py @@ -17,7 +17,7 @@ from deephaven.table import Table from deephaven.jcompat import j_list_to_list -_JDataAccessHelpers = jpy.get_type("io.deephaven.engine.table.impl.DataAccessHelpers") +_JColumnVectors = jpy.get_type("io.deephaven.engine.table.vectors.ColumnVectors") _JDayOfWeek = jpy.get_type("java.time.DayOfWeek") _JArrayList = jpy.get_type("java.util.ArrayList") @@ -109,8 +109,7 @@ def to_numpy(table: Table, cols: List[str] = None) -> np.ndarray: j_arrays = [] for col_def in col_defs: - data_col = _JDataAccessHelpers.getColumn(table.j_table, col_def.name) - j_arrays.append(data_col.getDirect()) + j_arrays.append(_JColumnVectors.of(table.j_table, col_def.name).copyToArray()) return _columns_to_2d_numpy_array(col_defs[0], j_arrays) except DHError: raise diff --git a/py/server/deephaven/pandas.py b/py/server/deephaven/pandas.py index e30527d50a1..d946de5e391 100644 --- a/py/server/deephaven/pandas.py +++ b/py/server/deephaven/pandas.py @@ -18,7 +18,7 @@ from deephaven.table import Table _NULL_BOOLEAN_AS_BYTE = jpy.get_type("io.deephaven.util.BooleanUtils").NULL_BOOLEAN_AS_BYTE -_JDataAccessHelpers = jpy.get_type("io.deephaven.engine.table.impl.DataAccessHelpers") +_JColumnVectors = jpy.get_type("io.deephaven.engine.table.vectors.ColumnVectors") _is_dtype_backend_supported = pd.__version__ >= "2.0.0" @@ -38,8 +38,7 @@ def _column_to_series(table: Table, col_def: Column, conv_null: bool) -> pd.Seri DHError """ try: - data_col = _JDataAccessHelpers.getColumn(table.j_table, col_def.name) - j_array = data_col.getDirect() + j_array = _JColumnVectors.of(table.j_table, col_def.name).copyToArray() return _j_array_to_series(col_def.data_type, j_array, conv_null) except DHError: raise diff --git a/server/test-utils/src/main/java/io/deephaven/server/test/FlightMessageRoundTripTest.java b/server/test-utils/src/main/java/io/deephaven/server/test/FlightMessageRoundTripTest.java index 81e765fe2bd..95646536910 100644 --- a/server/test-utils/src/main/java/io/deephaven/server/test/FlightMessageRoundTripTest.java +++ b/server/test-utils/src/main/java/io/deephaven/server/test/FlightMessageRoundTripTest.java @@ -29,9 +29,9 @@ import io.deephaven.engine.liveness.LivenessScopeStack; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Table; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; -import io.deephaven.engine.table.impl.DataAccessHelpers; import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.NoLanguageDeephavenSession; import io.deephaven.engine.util.ScriptSession; @@ -66,6 +66,8 @@ import io.deephaven.util.QueryConstants; import io.deephaven.util.SafeCloseable; import io.deephaven.util.mutable.MutableInt; +import io.deephaven.vector.DoubleVector; +import io.deephaven.vector.IntVector; import io.grpc.*; import io.grpc.CallOptions; import io.grpc.stub.ClientCalls; @@ -810,16 +812,18 @@ public void testDoExchangeSnapshot() throws Exception { totalRowCount += rowCount; // check the values against the source table - org.apache.arrow.vector.IntVector iv = - (org.apache.arrow.vector.IntVector) root.getVector(0); + final org.apache.arrow.vector.IntVector iv = (org.apache.arrow.vector.IntVector) root.getVector(0); + final IntVector sourceInts = + ColumnVectors.ofInt(table, table.getDefinition().getColumns().get(0).getName()); for (int i = 0; i < rowCount; ++i) { - assertEquals("int match:", DataAccessHelpers.getColumn(table, 0).get(offset + i), iv.get(i)); + assertEquals("int match:", sourceInts.get(offset + i), iv.get(i)); } - org.apache.arrow.vector.Float8Vector dv = + final org.apache.arrow.vector.Float8Vector dv = (org.apache.arrow.vector.Float8Vector) root.getVector(1); + final DoubleVector sourceDoubles = + ColumnVectors.ofDouble(table, table.getDefinition().getColumns().get(1).getName()); for (int i = 0; i < rowCount; ++i) { - assertEquals("double match: ", DataAccessHelpers.getColumn(table, 1).get(offset + i), - dv.get(i)); + assertEquals("double match: ", sourceDoubles.get(offset + i), dv.get(i), 0.000001); } } assertEquals(table.size(), totalRowCount); From 98fdfe9831ee724b4882717a83b46169380b36b6 Mon Sep 17 00:00:00 2001 From: Ryan Caudy Date: Mon, 3 Jun 2024 10:48:09 -0400 Subject: [PATCH 2/4] Fix failing unit tests, use QueryLibrary properly in rolling operator tests, and enable a pattern for "long-lived" chunk allocations that should not be tracked in the ChunkPoolReleaseTracking, applied to RowSet chunk views. --- .../util/pools/ChunkPoolReleaseTracking.java | 31 +- .../rowset/impl/RowSequenceAsChunkImpl.java | 13 +- .../table/impl/QueryTableAggregationTest.java | 1 + .../engine/table/impl/QueryTableJoinTest.java | 5 +- .../engine/table/impl/QueryTableTest.java | 17 +- .../engine/table/impl/TestAggBy.java | 5 +- .../engine/table/impl/TestTotalsTable.java | 21 +- .../impl/select/FilterKernelArraySample.java | 2 +- .../table/impl/select/FilterKernelSample.java | 2 +- .../impl/select/FormulaKernelSample.java | 2 +- .../table/impl/select/FormulaSample.java | 2 +- .../table/impl/updateby/TestCumProd.java | 4 +- .../engine/table/impl/updateby/TestDelta.java | 16 +- .../table/impl/updateby/TestRollingAvg.java | 104 ++-- .../table/impl/updateby/TestRollingCount.java | 52 +- .../impl/updateby/TestRollingFormula.java | 130 +++-- .../impl/updateby/TestRollingMinMax.java | 190 ++++---- .../impl/updateby/TestRollingProduct.java | 94 ++-- .../table/impl/updateby/TestRollingStd.java | 144 +++--- .../table/impl/updateby/TestRollingWAvg.java | 455 +++++++++--------- .../deephaven/engine/util/TestTableTools.java | 6 +- .../main/java/io/deephaven/csv/CsvTools.java | 14 +- .../java/io/deephaven/csv/TestCsvTools.java | 1 - 23 files changed, 669 insertions(+), 642 deletions(-) diff --git a/engine/chunk/src/main/java/io/deephaven/chunk/util/pools/ChunkPoolReleaseTracking.java b/engine/chunk/src/main/java/io/deephaven/chunk/util/pools/ChunkPoolReleaseTracking.java index 915c6fb4dfe..b6ae949254b 100644 --- a/engine/chunk/src/main/java/io/deephaven/chunk/util/pools/ChunkPoolReleaseTracking.java +++ b/engine/chunk/src/main/java/io/deephaven/chunk/util/pools/ChunkPoolReleaseTracking.java @@ -6,6 +6,8 @@ import io.deephaven.util.datastructures.ReleaseTracker; import org.jetbrains.annotations.NotNull; +import java.util.function.Supplier; + /** * Support for release tracking, in order to detect chunk release errors. */ @@ -13,6 +15,9 @@ public final class ChunkPoolReleaseTracking { private static volatile ReleaseTracker releaseTracker; + private static final ThreadLocal>> threadLocalReleaseTrackerSupplier = + ThreadLocal.withInitial(() -> () -> releaseTracker); + public static void enableStrict() { enable(ReleaseTracker.strictReleaseTrackerFactory, true); } @@ -46,8 +51,28 @@ public static void disable() { releaseTracker = null; } + public static CHUNK_TYPE untracked(@NotNull final Supplier acquire) { + final Supplier> original = threadLocalReleaseTrackerSupplier.get(); + try { + threadLocalReleaseTrackerSupplier.set(() -> null); + return acquire.get(); + } finally { + threadLocalReleaseTrackerSupplier.set(original); + } + } + + public static void untracked(@NotNull final Runnable release) { + final Supplier> original = threadLocalReleaseTrackerSupplier.get(); + try { + threadLocalReleaseTrackerSupplier.set(() -> null); + release.run(); + } finally { + threadLocalReleaseTrackerSupplier.set(original); + } + } + static CHUNK_TYPE onTake(@NotNull final CHUNK_TYPE chunk) { - final ReleaseTracker localReleaseTracker = releaseTracker; + final ReleaseTracker localReleaseTracker = threadLocalReleaseTrackerSupplier.get().get(); if (localReleaseTracker != null) { localReleaseTracker.reportAcquire(chunk); } @@ -55,7 +80,7 @@ static CHUNK_TYPE onTake(@NotNull final CHUNK } static CHUNK_TYPE onGive(@NotNull final CHUNK_TYPE chunk) { - final ReleaseTracker localReleaseTracker = releaseTracker; + final ReleaseTracker localReleaseTracker = threadLocalReleaseTrackerSupplier.get().get(); if (localReleaseTracker != null) { localReleaseTracker.reportRelease(chunk); } @@ -63,7 +88,7 @@ static CHUNK_TYPE onGive(@NotNull final CHUNK } public static void check() { - final ReleaseTracker localReleaseTracker = releaseTracker; + final ReleaseTracker localReleaseTracker = threadLocalReleaseTrackerSupplier.get().get(); if (localReleaseTracker != null) { localReleaseTracker.check(); } diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/RowSequenceAsChunkImpl.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/RowSequenceAsChunkImpl.java index 8a11fd73444..904ac3a9329 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/RowSequenceAsChunkImpl.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/RowSequenceAsChunkImpl.java @@ -3,6 +3,7 @@ // package io.deephaven.engine.rowset.impl; +import io.deephaven.chunk.util.pools.ChunkPoolReleaseTracking; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeys; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeyRanges; @@ -20,7 +21,7 @@ public abstract class RowSequenceAsChunkImpl implements RowSequence { private void makeKeyIndicesChunk() { final int isize = intSize(); - keyIndicesChunk = WritableLongChunk.makeWritableChunk(isize); + keyIndicesChunk = ChunkPoolReleaseTracking.untracked(() -> WritableLongChunk.makeWritableChunk(isize)); } protected long runsUpperBound() { @@ -42,7 +43,7 @@ private int sizeForRangesChunk() { private void makeKeyRangesChunk(final int size) { final WritableLongChunk chunk = - WritableLongChunk.makeWritableChunk(size); + ChunkPoolReleaseTracking.untracked(() -> WritableLongChunk.makeWritableChunk(size)); keyRangesChunk = chunk; } @@ -57,7 +58,7 @@ public final LongChunk asRowKeyChunk() { keyIndicesChunk.setSize(keyIndicesChunk.capacity()); fillRowKeyChunk(keyIndicesChunk); } else { - keyIndicesChunk.close(); + ChunkPoolReleaseTracking.untracked(keyIndicesChunk::close); keyIndicesChunk = null; } } @@ -82,7 +83,7 @@ public final LongChunk asRowKeyRangesChunk() { if (keyRangesChunk.capacity() >= size) { fillRowKeyRangesChunk(keyRangesChunk); } else { - keyRangesChunk.close(); + ChunkPoolReleaseTracking.untracked(keyRangesChunk::close); keyRangesChunk = null; } } @@ -114,11 +115,11 @@ public void close() { */ protected final void closeRowSequenceAsChunkImpl() { if (keyIndicesChunk != null) { - keyIndicesChunk.close(); + ChunkPoolReleaseTracking.untracked(keyIndicesChunk::close); keyIndicesChunk = null; } if (keyRangesChunk != null) { - keyRangesChunk.close(); + ChunkPoolReleaseTracking.untracked(keyRangesChunk::close); keyRangesChunk = null; } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java index c93b689e4f9..cb5cc75c66e 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableAggregationTest.java @@ -485,6 +485,7 @@ public void testStaticBy() { TestCase.assertEquals(int.class, grouped.getColumnSource("j").getType()); table = newTable(intCol("V", 100)); + grouped = table.updateView("j=i").groupBy("j"); TestCase.assertEquals(1, grouped.size()); TestCase.assertEquals(2, grouped.numColumns()); TestCase.assertEquals(int.class, diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java index 4ae42ce7518..87d10524cb4 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableJoinTest.java @@ -33,6 +33,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; +import static io.deephaven.datastructures.util.CollectionUtil.ZERO_LENGTH_STRING_ARRAY; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.printTableUpdates; import static io.deephaven.engine.util.TableTools.*; import static io.deephaven.engine.testutil.TstUtils.*; @@ -621,9 +622,9 @@ public void testAjEmptyRight() { col("LSentinel", "a", "b", "c", "d")); final QueryTable right = TstUtils.testRefreshingTable(i().toTracking(), - col("Group", CollectionUtil.ZERO_LENGTH_STRING_ARRAY), + col("Group", ZERO_LENGTH_STRING_ARRAY), intCol("RInt"), - col("RSentinel")); + col("RSentinel", ZERO_LENGTH_STRING_ARRAY)); System.out.println("Left:"); TableTools.show(left); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java index d48731af680..0431990a69b 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java @@ -1302,13 +1302,18 @@ public void testReverse2() { } - private void checkReverse(QueryTable table, Table reversed, String timestamp) { + private void checkReverse(QueryTable table, Table reversed, String columnName) { assertEquals(table.size(), reversed.size()); - for (long ii = 0; ii < table.size(); ++ii) { - final long jj = table.size() - ii - 1; - assertEquals( - ColumnVectors.ofObject(table, timestamp, Object.class).get(ii), - ColumnVectors.ofObject(reversed, timestamp, Object.class).get(jj)); + final ColumnSource tableSource = table.getColumnSource(columnName); + final ColumnSource reversedSource = reversed.getColumnSource(columnName); + try (final RowSet.Iterator tableRows = table.getRowSet().iterator(); + final RowSet.Iterator reverseRows = reversed.getRowSet().reverseIterator()) { + while (tableRows.hasNext()) { + assertTrue(reverseRows.hasNext()); + final long tableRow = tableRows.nextLong(); + final long reverseRow = reverseRows.nextLong(); + assertEquals(tableSource.get(tableRow), reversedSource.get(reverseRow)); + } } } diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java index 2cfa95250eb..41c03989f6c 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestAggBy.java @@ -29,6 +29,7 @@ import io.deephaven.vector.CharVector; import io.deephaven.vector.DoubleVector; import io.deephaven.vector.IntVector; +import io.deephaven.vector.LongVector; import junit.framework.TestCase; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -82,10 +83,10 @@ public void testBy() { show(doubleCounted); assertEquals(2, doubleCounted.size()); - IntVector counts = ColumnVectors.ofInt(doubleCounted, "Count1"); + LongVector counts = ColumnVectors.ofLong(doubleCounted, "Count1"); assertEquals(6L, counts.get(0)); assertEquals(4L, counts.get(1)); - counts = ColumnVectors.ofInt(doubleCounted, "Count2"); + counts = ColumnVectors.ofLong(doubleCounted, "Count2"); assertEquals(6L, counts.get(0)); assertEquals(4L, counts.get(1)); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java index 7e5915c1112..76a2f113134 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestTotalsTable.java @@ -12,7 +12,6 @@ import io.deephaven.engine.testutil.EvalNugget; import io.deephaven.engine.testutil.EvalNuggetInterface; import io.deephaven.engine.util.TotalsTableBuilder; -import io.deephaven.util.QueryConstants; import java.util.Arrays; import java.util.LinkedHashSet; @@ -27,17 +26,6 @@ public class TestTotalsTable extends RefreshingTableTestCase { private static final double EPSILON = 0.000000001; - private long shortSum(short[] values) { - long sum = 0; - for (short value : values) { - if (value == QueryConstants.NULL_SHORT) { - continue; - } - sum += value; - } - return sum; - } - public void testTotalsTable() { final int size = 1000; final Random random = new Random(0); @@ -66,7 +54,7 @@ public void testTotalsTable() { "floatCol", "byteCol", "shortCol")), resultColumns); assertEquals(sum(ColumnVectors.ofInt(queryTable, "intCol")), - totals.getColumnSource("intCol").getInt(totals.getRowSet().firstRowKey())); + totals.getColumnSource("intCol").getLong(totals.getRowSet().firstRowKey())); assertEquals(sum(ColumnVectors.ofDouble(queryTable, "doubleCol")), totals.getColumnSource("doubleCol").getDouble(totals.getRowSet().firstRowKey())); assertEquals(sum(ColumnVectors.ofDouble(queryTable, "doubleNullCol")), @@ -74,7 +62,7 @@ public void testTotalsTable() { assertEquals(sum(ColumnVectors.ofFloat(queryTable, "floatCol")), totals.getColumnSource("floatCol").getFloat(totals.getRowSet().firstRowKey()), 0.02); assertEquals(sum(ColumnVectors.ofShort(queryTable, "shortCol")), - totals.getColumnSource("shortCol").getShort(totals.getRowSet().firstRowKey())); + totals.getColumnSource("shortCol").getLong(totals.getRowSet().firstRowKey())); builder.setDefaultOperation("skip"); builder.setOperation("byteCol", "min"); @@ -89,9 +77,8 @@ public void testTotalsTable() { totals2.getColumnSource("byteCol").getByte(totals2.getRowSet().firstRowKey())); assertEquals(queryTable.getColumnSource("Sym").get(queryTable.getRowSet().firstRowKey()), totals2.getColumnSource("Sym").get(totals2.getRowSet().firstRowKey())); - assertEquals(queryTable.getColumnSource("intCol2").getInt(queryTable.getRowSet().get(queryTable.size() - 1)), - totals2.getColumnSource("intCol2") - .getInt(queryTable.getRowSet().get(totals2.getRowSet().firstRowKey()))); + assertEquals(queryTable.getColumnSource("intCol2").getInt(queryTable.getRowSet().lastRowKey()), + totals2.getColumnSource("intCol2").getInt(totals2.getRowSet().get(totals2.getRowSet().firstRowKey()))); builder.setOperation("byteCol", "max"); builder.setOperation("doubleCol", "var"); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelArraySample.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelArraySample.java index 04e1c984b5b..24432e01084 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelArraySample.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelArraySample.java @@ -34,9 +34,9 @@ import io.deephaven.engine.rowset.WritableRowSet; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Context; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import static io.deephaven.engine.table.impl.select.ConditionFilter.FilterKernel; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.time.DateTimeUtils; import io.deephaven.util.datastructures.LongSizedDataStructure; import io.deephaven.util.type.ArrayTypeUtils; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelSample.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelSample.java index 530854aebb6..1b57b3f40f2 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelSample.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FilterKernelSample.java @@ -34,9 +34,9 @@ import io.deephaven.engine.rowset.WritableRowSet; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Context; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import static io.deephaven.engine.table.impl.select.ConditionFilter.FilterKernel; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.time.DateTimeUtils; import io.deephaven.util.datastructures.LongSizedDataStructure; import io.deephaven.util.type.ArrayTypeUtils; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaKernelSample.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaKernelSample.java index d6a5c6abcc1..28acdde3e30 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaKernelSample.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaKernelSample.java @@ -34,9 +34,9 @@ import io.deephaven.engine.rowset.WritableRowSet; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Context; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import static io.deephaven.engine.table.impl.select.ConditionFilter.FilterKernel; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.time.DateTimeUtils; import io.deephaven.util.datastructures.LongSizedDataStructure; import io.deephaven.util.type.ArrayTypeUtils; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaSample.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaSample.java index 51d41ae0926..7a027cde2ff 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaSample.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/select/FormulaSample.java @@ -34,9 +34,9 @@ import io.deephaven.engine.rowset.WritableRowSet; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Context; -import io.deephaven.engine.table.DataColumn; import io.deephaven.engine.table.Table; import static io.deephaven.engine.table.impl.select.ConditionFilter.FilterKernel; +import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.time.DateTimeUtils; import io.deephaven.util.datastructures.LongSizedDataStructure; import io.deephaven.util.type.ArrayTypeUtils; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java index 09fbbc68a22..2187d9f49b5 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestCumProd.java @@ -124,8 +124,8 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { assertWithCumProd( - ColumnVectors.of(source, col).getDirect(), - ColumnVectors.of(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), actual.getDefinition().getColumn(col).getDataType()); }); return source; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java index 2a87694ce8e..9395a4bb73d 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestDelta.java @@ -182,8 +182,8 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { assertWithDelta( - ColumnVectors.of(source, col).getDirect(), - ColumnVectors.of(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), DeltaControl.DEFAULT); }); return source; @@ -197,8 +197,8 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { assertWithDelta( - ColumnVectors.of(source, col).getDirect(), - ColumnVectors.of(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), DeltaControl.NULL_DOMINATES); }); return source; @@ -212,8 +212,8 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { assertWithDelta( - ColumnVectors.of(source, col).getDirect(), - ColumnVectors.of(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), DeltaControl.VALUE_DOMINATES); }); return source; @@ -227,8 +227,8 @@ private void doTestStaticBucketed(boolean grouped) { preOp.partitionedTransform(postOp, (source, actual) -> { Arrays.stream(columns).forEach(col -> { assertWithDelta( - ColumnVectors.of(source, col).getDirect(), - ColumnVectors.of(actual, col).getDirect(), + ColumnVectors.of(source, col).toArray(), + ColumnVectors.of(actual, col).toArray(), DeltaControl.ZERO_DOMINATES); }); return source; diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java index f24587e8ed9..05b93595eab 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingAvg.java @@ -8,7 +8,6 @@ import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.base.verify.Assert; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.vectors.ColumnVectors; @@ -22,6 +21,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -34,7 +35,6 @@ import java.util.List; import java.util.Objects; import java.util.Random; -import java.util.function.Function; import static io.deephaven.engine.testutil.GenerateTableUpdates.generateAppends; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.simulateShiftAwareStep; @@ -95,64 +95,69 @@ private String[] getCastingFormulas(String[] columns) { // region Object Helper functions - final Function, BigDecimal> avgBigInt = bigIntegerObjectVector -> { - MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { - if (bigIntegerObjectVector == null || bigIntegerObjectVector.size() == 0) { - return null; - } + public static BigDecimal avgBigInt(ObjectVector bigIntegerObjectVector) { + MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + + if (bigIntegerObjectVector == null || bigIntegerObjectVector.isEmpty()) { + return null; + } - BigDecimal sum = new BigDecimal(0); - long count = 0; + BigDecimal sum = new BigDecimal(0); + long count = 0; - final long n = bigIntegerObjectVector.size(); + final long n = bigIntegerObjectVector.size(); - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - final BigDecimal decVal = new BigDecimal(val); - sum = sum.add(decVal, mathContextDefault); - count++; + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + final BigDecimal decVal = new BigDecimal(val); + sum = sum.add(decVal, mathContextDefault); + count++; + } } + if (count == 0) { + return null; + } + return sum.divide(new BigDecimal(count), mathContextDefault); } - if (count == 0) { - return null; - } - return sum.divide(new BigDecimal(count), mathContextDefault); - }; - final Function, BigDecimal> avgBigDec = bigDecimalObjectVector -> { - MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + public static BigDecimal avgBigDec(ObjectVector bigDecimalObjectVector) { + MathContext mathContextDefault = UpdateByControl.mathContextDefault(); - if (bigDecimalObjectVector == null || bigDecimalObjectVector.size() == 0) { - return null; - } + if (bigDecimalObjectVector == null || bigDecimalObjectVector.isEmpty()) { + return null; + } - BigDecimal sum = new BigDecimal(0); - long count = 0; + BigDecimal sum = new BigDecimal(0); + long count = 0; - final long n = bigDecimalObjectVector.size(); + final long n = bigDecimalObjectVector.size(); - for (long i = 0; i < n; i++) { - BigDecimal val = bigDecimalObjectVector.get(i); - if (!isNull(val)) { - sum = sum.add(val, mathContextDefault); - count++; + for (long i = 0; i < n; i++) { + BigDecimal val = bigDecimalObjectVector.get(i); + if (!isNull(val)) { + sum = sum.add(val, mathContextDefault); + count++; + } } + if (count == 0) { + return null; + } + return sum.divide(new BigDecimal(count), mathContextDefault); } - if (count == 0) { - return null; - } - return sum.divide(new BigDecimal(count), mathContextDefault); - }; + } private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("avgBigInt", avgBigInt); - QueryScope.addParam("avgBigDec", avgBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingAvg(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=avgBigInt(bigIntCol)", "bigDecimalCol=avgBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -181,13 +186,12 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("avgBigInt", avgBigInt); - QueryScope.addParam("avgBigDec", avgBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingAvg("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=avgBigInt(bigIntCol)", "bigDecimalCol=avgBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -215,14 +219,13 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati } private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("avgBigInt", avgBigInt); - QueryScope.addParam("avgBigDec", avgBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingAvg(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=avgBigInt(bigIntCol)", "bigDecimalCol=avgBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -251,14 +254,13 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("avgBigInt", avgBigInt); - QueryScope.addParam("avgBigDec", avgBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingAvg("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=avgBigInt.apply(bigIntCol)", "bigDecimalCol=avgBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=avgBigInt(bigIntCol)", "bigDecimalCol=avgBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java index 3198ee9d049..d80c33edeb9 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingCount.java @@ -7,9 +7,7 @@ import io.deephaven.api.updateby.UpdateByControl; import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.base.verify.Assert; -import io.deephaven.chunk.attributes.Any; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.vectors.ColumnVectors; @@ -23,6 +21,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -87,29 +87,35 @@ private String[] getCastingFormulas(String[] columns) { // region Object Helper functions - final Function, Long> countObject = objectVector -> { + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { - if (objectVector == null || objectVector.size() == 0) { - return 0L; - } + public static long countObject(ObjectVector objectVector) { + + if (objectVector == null || objectVector.isEmpty()) { + return 0L; + } - final long n = objectVector.size(); - long nullCount = 0; + final long n = objectVector.size(); + long nullCount = 0; - for (long i = 0; i < n; i++) { - if (objectVector.get(i) == null) { - nullCount++; + for (long i = 0; i < n; i++) { + if (objectVector.get(i) == null) { + nullCount++; + } } + return n - nullCount; } - return n - nullCount; - }; + } private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("countObject", countObject); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingCount(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); + .update("bigIntCol=countObject(bigIntCol)", "bigDecimalCol=countObject(bigDecimalCol)"); long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); @@ -134,14 +140,14 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("countObject", countObject); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingCount("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=countObject.apply(bigIntCol)", - "bigDecimalCol=countObject.apply(bigDecimalCol)"); + .update("bigIntCol=countObject(bigIntCol)", + "bigDecimalCol=countObject(bigDecimalCol)"); long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); @@ -165,14 +171,14 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati } private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("countObject", countObject); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingCount(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=countObject.apply(bigIntCol)", - "bigDecimalCol=countObject.apply(bigDecimalCol)"); + .update("bigIntCol=countObject(bigIntCol)", + "bigDecimalCol=countObject(bigDecimalCol)"); long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); @@ -197,14 +203,14 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("countObject", countObject); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingCount("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=countObject.apply(bigIntCol)", "bigDecimalCol=countObject.apply(bigDecimalCol)"); + .update("bigIntCol=countObject(bigIntCol)", "bigDecimalCol=countObject(bigDecimalCol)"); long[] biActual = ColumnVectors.ofLong(actual, "bigIntCol").toArray(); long[] biExpected = ColumnVectors.ofLong(expected, "bigIntCol").toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingFormula.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingFormula.java index 29d491c0641..685f19dde43 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingFormula.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingFormula.java @@ -6,7 +6,6 @@ import io.deephaven.api.updateby.UpdateByControl; import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.PartitionedTable; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; @@ -18,6 +17,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -28,7 +29,6 @@ import java.util.Arrays; import java.util.List; import java.util.Random; -import java.util.function.Function; import static io.deephaven.engine.testutil.GenerateTableUpdates.generateAppends; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.simulateShiftAwareStep; @@ -69,39 +69,45 @@ public class TestRollingFormula extends BaseUpdateByTest { final int DYNAMIC_UPDATE_SIZE = 10; final int DYNAMIC_UPDATE_STEPS = 20; - final Function, BigDecimal> sumBigDecimal = bigDecimalObjectVector -> { - if (bigDecimalObjectVector == null) { - return null; - } + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { + + public static BigDecimal sumBigDecimal(ObjectVector bigDecimalObjectVector) { + if (bigDecimalObjectVector == null) { + return null; + } - BigDecimal sum = BigDecimal.ZERO; - final long n = bigDecimalObjectVector.size(); + BigDecimal sum = BigDecimal.ZERO; + final long n = bigDecimalObjectVector.size(); - for (long i = 0; i < n; i++) { - BigDecimal val = bigDecimalObjectVector.get(i); - if (!isNull(val)) { - sum = sum.add(val); + for (long i = 0; i < n; i++) { + BigDecimal val = bigDecimalObjectVector.get(i); + if (!isNull(val)) { + sum = sum.add(val); + } } + return sum; } - return sum; - }; - final Function, BigInteger> sumBigInteger = bigIntegerObjectVector -> { - if (bigIntegerObjectVector == null) { - return null; - } + public static BigInteger sumBigInteger(ObjectVector bigIntegerObjectVector) { + if (bigIntegerObjectVector == null) { + return null; + } - BigInteger sum = BigInteger.ZERO; - final long n = bigIntegerObjectVector.size(); + BigInteger sum = BigInteger.ZERO; + final long n = bigIntegerObjectVector.size(); - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - sum = sum.add(val); + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + sum = sum.add(val); + } } + return sum; } - return sum; - }; + } // region Static Zero Key Tests @@ -280,17 +286,16 @@ private void doTestStaticZeroKey(final int prevTicks, final int postTicks) { // BigDecimal / BigInteger custom sum function vs. RollingSum //////////////////////////////////////////////////////////////////////////////////////////////////// - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); actual = t.updateBy(List.of( - UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", "x", "bigDecimalCol"), - UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigInteger.apply(x)", "x", "bigIntCol"))); + UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"), + UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigInteger(x)", "x", "bigIntCol"))); // RollingSum returns null when the window is empty, replace that with zeros. expected = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks, "bigDecimalCol", "bigIntCol")) - .update("bigDecimalCol=(Object)(bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol)", - "bigIntCol=(Object)(bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol)"); + .update("bigDecimalCol=bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol", + "bigIntCol=bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol"); TstUtils.assertTableEquals(expected, actual, TableDiff.DiffItems.DoublesExact); @@ -404,19 +409,18 @@ private void doTestStaticZeroKeyTimed(final Duration prevTime, final Duration po // BigDecimal / BigInteger custom sum function vs. RollingSum //////////////////////////////////////////////////////////////////////////////////////////////////// - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); actual = t.updateBy(List.of( - UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigDecimal.apply(x)", "x", + UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigDecimal(x)", "x", "bigDecimalCol"), - UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigInteger.apply(x)", "x", + UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigInteger(x)", "x", "bigIntCol"))); // RollingSum returns null when the window is empty, replace that with zeros. expected = t.updateBy(UpdateByOperation.RollingSum("ts", prevTime, postTime, "bigDecimalCol", "bigIntCol")) - .update("bigDecimalCol=(Object)(bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol)", - "bigIntCol=(Object)(bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol)"); + .update("bigDecimalCol=bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol", + "bigIntCol=bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol"); TstUtils.assertTableEquals(expected, actual, TableDiff.DiffItems.DoublesExact); @@ -620,18 +624,17 @@ private void doTestStaticBucketed(boolean grouped, int prevTicks, int postTicks) // BigDecimal / BigInteger custom sum function vs. RollingSum //////////////////////////////////////////////////////////////////////////////////////////////////// - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); actual = t.updateBy(List.of( - UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", "x", "bigDecimalCol"), - UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigInteger.apply(x)", "x", "bigIntCol")), + UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"), + UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigInteger(x)", "x", "bigIntCol")), "Sym"); // RollingSum returns null when the window is empty, replace that with zeros. expected = t.updateBy(UpdateByOperation.RollingSum(prevTicks, postTicks, "bigDecimalCol", "bigIntCol"), "Sym") - .update("bigDecimalCol=(Object)(bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol)", - "bigIntCol=(Object)(bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol)"); + .update("bigDecimalCol=bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol", + "bigIntCol=bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol"); TstUtils.assertTableEquals(expected, actual, TableDiff.DiffItems.DoublesExact); @@ -746,20 +749,19 @@ private void doTestStaticBucketedTimed(boolean grouped, Duration prevTime, Durat // BigDecimal / BigInteger custom sum function vs. RollingSum //////////////////////////////////////////////////////////////////////////////////////////////////// - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); actual = t.updateBy(List.of( - UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigDecimal.apply(x)", "x", + UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigDecimal(x)", "x", "bigDecimalCol"), - UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigInteger.apply(x)", "x", "bigIntCol")), + UpdateByOperation.RollingFormula("ts", prevTime, postTime, "sumBigInteger(x)", "x", "bigIntCol")), "Sym"); // RollingSum returns null when the window is empty, replace that with zeros. expected = t .updateBy(UpdateByOperation.RollingSum("ts", prevTime, postTime, "bigDecimalCol", "bigIntCol"), "Sym") - .update("bigDecimalCol=(Object)(bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol)", - "bigIntCol=(Object)(bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol)"); + .update("bigDecimalCol=bigDecimalCol == null ? java.math.BigDecimal.ZERO : bigDecimalCol", + "bigIntCol=bigIntCol == null ? java.math.BigInteger.ZERO : bigIntCol"); TstUtils.assertTableEquals(expected, actual, TableDiff.DiffItems.DoublesExact); @@ -937,8 +939,7 @@ private void doTestAppendOnly(boolean bucketed, int prevTicks, int postTicks) { final QueryTable t = result.t; t.setAttribute(Table.APPEND_ONLY_TABLE_ATTRIBUTE, Boolean.TRUE); - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final EvalNugget[] nuggets = new EvalNugget[] { EvalNugget.from(() -> bucketed @@ -952,9 +953,9 @@ private void doTestAppendOnly(boolean bucketed, int prevTicks, int postTicks) { : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "avg(x * x + x)", "x", primitiveColumns))), EvalNugget.from(() -> bucketed - ? t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", + ? t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"), "Sym") - : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", + : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"))), }; @@ -975,8 +976,7 @@ private void doTestAppendOnlyTimed(boolean bucketed, Duration prevTime, Duration final QueryTable t = result.t; t.setAttribute(Table.APPEND_ONLY_TABLE_ATTRIBUTE, Boolean.TRUE); - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final EvalNugget[] nuggets = new EvalNugget[] { EvalNugget.from(() -> bucketed @@ -991,9 +991,9 @@ private void doTestAppendOnlyTimed(boolean bucketed, Duration prevTime, Duration primitiveColumns))), EvalNugget.from(() -> bucketed ? t.updateBy(UpdateByOperation.RollingFormula("ts", prevTime, postTime, - "sumBigDecimal.apply(x)", "x", "bigDecimalCol"), "Sym") + "sumBigDecimal(x)", "x", "bigDecimalCol"), "Sym") : t.updateBy(UpdateByOperation.RollingFormula("ts", prevTime, postTime, - "sumBigDecimal.apply(x)", "x", "bigDecimalCol"))), + "sumBigDecimal(x)", "x", "bigDecimalCol"))), }; final Random billy = new Random(0xB177B177); @@ -1126,8 +1126,7 @@ private void doTestTicking(final boolean bucketed, final long prevTicks, final l new TestDataGenerator[] {new CharGenerator('A', 'z', 0.1)}); final QueryTable t = result.t; - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final EvalNugget[] nuggets = new EvalNugget[] { EvalNugget.from(() -> bucketed @@ -1141,9 +1140,9 @@ private void doTestTicking(final boolean bucketed, final long prevTicks, final l : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "avg(x * x + x)", "x", primitiveColumns))), EvalNugget.from(() -> bucketed - ? t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", + ? t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"), "Sym") - : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal.apply(x)", + : t.updateBy(UpdateByOperation.RollingFormula(prevTicks, postTicks, "sumBigDecimal(x)", "x", "bigDecimalCol"))), }; @@ -1164,8 +1163,7 @@ private void doTestTickingTimed(final boolean bucketed, final Duration prevTime, final QueryTable t = result.t; - QueryScope.addParam("sumBigDecimal", sumBigDecimal); - QueryScope.addParam("sumBigInteger", sumBigInteger); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final EvalNugget[] nuggets = new EvalNugget[] { EvalNugget.from(() -> bucketed @@ -1180,9 +1178,9 @@ private void doTestTickingTimed(final boolean bucketed, final Duration prevTime, primitiveColumns))), EvalNugget.from(() -> bucketed ? t.updateBy(UpdateByOperation.RollingFormula("ts", prevTime, postTime, - "sumBigDecimal.apply(x)", "x", "bigDecimalCol"), "Sym") + "sumBigDecimal(x)", "x", "bigDecimalCol"), "Sym") : t.updateBy(UpdateByOperation.RollingFormula("ts", prevTime, postTime, - "sumBigDecimal.apply(x)", "x", "bigDecimalCol"))), + "sumBigDecimal(x)", "x", "bigDecimalCol"))), }; final Random billy = new Random(0xB177B177); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java index e3d0b3cd7c3..d5598242124 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingMinMax.java @@ -8,7 +8,6 @@ import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.base.verify.Assert; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.vectors.ColumnVectors; @@ -23,6 +22,8 @@ import io.deephaven.engine.util.TableTools; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -34,7 +35,6 @@ import java.util.List; import java.util.Objects; import java.util.Random; -import java.util.function.Function; import static io.deephaven.engine.testutil.GenerateTableUpdates.generateAppends; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.simulateShiftAwareStep; @@ -103,113 +103,116 @@ private String[] getDowncastingFormulas(String[] columns) { // region Object Helper functions - final Function, BigInteger> minBigInt = bigIntegerObjectVector -> { - if (bigIntegerObjectVector == null) { - return null; - } + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { + + public static BigInteger minBigInt(ObjectVector bigIntegerObjectVector) { + if (bigIntegerObjectVector == null) { + return null; + } - BigInteger min = BigInteger.valueOf(Long.MAX_VALUE); - long count = 0; - final long n = bigIntegerObjectVector.size(); + BigInteger min = BigInteger.valueOf(Long.MAX_VALUE); + long count = 0; + final long n = bigIntegerObjectVector.size(); - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - if (val.compareTo(min) < 0) { - min = val; + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + if (val.compareTo(min) < 0) { + min = val; + } + count++; } - count++; } + if (count == 0) { + return null; + } + return min; } - if (count == 0) { - return null; - } - return min; - }; - final Function, BigInteger> maxBigInt = bigIntegerObjectVector -> { - if (bigIntegerObjectVector == null) { - return null; - } + public static BigInteger maxBigInt(ObjectVector bigIntegerObjectVector) { + if (bigIntegerObjectVector == null) { + return null; + } - BigInteger max = BigInteger.valueOf(Long.MIN_VALUE); - long count = 0; - final long n = bigIntegerObjectVector.size(); + BigInteger max = BigInteger.valueOf(Long.MIN_VALUE); + long count = 0; + final long n = bigIntegerObjectVector.size(); - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - if (val.compareTo(max) > 0) { - max = val; + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + if (val.compareTo(max) > 0) { + max = val; + } + count++; } - count++; } + if (count == 0) { + return null; + } + return max; } - if (count == 0) { - return null; - } - return max; - }; - final Function, BigDecimal> minBigDec = bigDecimalObjectVector -> { - if (bigDecimalObjectVector == null) { - return null; - } + public static BigDecimal minBigDec(ObjectVector bigDecimalObjectVector) { + if (bigDecimalObjectVector == null) { + return null; + } - BigDecimal min = new BigDecimal(Double.MAX_VALUE); - long count = 0; - final long n = bigDecimalObjectVector.size(); + BigDecimal min = new BigDecimal(Double.MAX_VALUE); + long count = 0; + final long n = bigDecimalObjectVector.size(); - for (long i = 0; i < n; i++) { - BigDecimal val = bigDecimalObjectVector.get(i); - if (!isNull(val)) { - if (val.compareTo(min) < 0) { - min = val; + for (long i = 0; i < n; i++) { + BigDecimal val = bigDecimalObjectVector.get(i); + if (!isNull(val)) { + if (val.compareTo(min) < 0) { + min = val; + } + count++; } - count++; } + if (count == 0) { + return null; + } + return min; } - if (count == 0) { - return null; - } - return min; - }; - final Function, BigDecimal> maxBigDec = bigDecimalObjectVector -> { - if (bigDecimalObjectVector == null) { - return null; - } + public static BigDecimal maxBigDec(ObjectVector bigDecimalObjectVector) { + if (bigDecimalObjectVector == null) { + return null; + } - BigDecimal max = new BigDecimal(Double.MIN_VALUE); - long count = 0; - final long n = bigDecimalObjectVector.size(); + BigDecimal max = new BigDecimal(Double.MIN_VALUE); + long count = 0; + final long n = bigDecimalObjectVector.size(); - for (long i = 0; i < n; i++) { - BigDecimal val = bigDecimalObjectVector.get(i); - if (!isNull(val)) { - if (val.compareTo(max) > 0) { - max = val; + for (long i = 0; i < n; i++) { + BigDecimal val = bigDecimalObjectVector.get(i); + if (!isNull(val)) { + if (val.compareTo(max) > 0) { + max = val; + } + count++; } - count++; } + if (count == 0) { + return null; + } + return max; } - if (count == 0) { - return null; - } - return max; - }; + } private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("minBigInt", minBigInt); - QueryScope.addParam("maxBigInt", maxBigInt); - QueryScope.addParam("minBigDec", minBigDec); - QueryScope.addParam("maxBigDec", maxBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); // TEST MIN VALUES Table actual = t.updateBy(UpdateByOperation.RollingMin(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=minBigInt(bigIntCol)", "bigDecimalCol=minBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -239,7 +242,7 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic actual = t.updateBy(UpdateByOperation.RollingMax(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=maxBigInt(bigIntCol)", "bigDecimalCol=maxBigDec(bigDecimalCol)"); biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -268,17 +271,14 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("minBigInt", minBigInt); - QueryScope.addParam("maxBigInt", maxBigInt); - QueryScope.addParam("minBigDec", minBigDec); - QueryScope.addParam("maxBigDec", maxBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); // TEST MIN VALUES Table actual = t.updateBy(UpdateByOperation.RollingMin("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=minBigInt(bigIntCol)", "bigDecimalCol=minBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -308,7 +308,7 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati actual = t.updateBy(UpdateByOperation.RollingMax("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=maxBigInt(bigIntCol)", "bigDecimalCol=maxBigDec(bigDecimalCol)"); biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -336,10 +336,7 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati } private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("minBigInt", minBigInt); - QueryScope.addParam("maxBigInt", maxBigInt); - QueryScope.addParam("minBigDec", minBigDec); - QueryScope.addParam("maxBigDec", maxBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); // TEST MIN VALUES @@ -347,7 +344,7 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi t.updateBy(UpdateByOperation.RollingMin(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=minBigInt(bigIntCol)", "bigDecimalCol=minBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -377,7 +374,7 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi actual = t.updateBy(UpdateByOperation.RollingMax(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=maxBigInt(bigIntCol)", "bigDecimalCol=maxBigDec(bigDecimalCol)"); biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -406,10 +403,7 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("minBigInt", minBigInt); - QueryScope.addParam("maxBigInt", maxBigInt); - QueryScope.addParam("minBigDec", minBigDec); - QueryScope.addParam("maxBigDec", maxBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); // TEST MIN VALUES @@ -417,7 +411,7 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat t.updateBy(UpdateByOperation.RollingMin("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=minBigInt.apply(bigIntCol)", "bigDecimalCol=minBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=minBigInt(bigIntCol)", "bigDecimalCol=minBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -449,7 +443,7 @@ private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Durat "Sym"); expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=maxBigInt.apply(bigIntCol)", "bigDecimalCol=maxBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=maxBigInt(bigIntCol)", "bigDecimalCol=maxBigDec(bigDecimalCol)"); biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java index d81866adbb8..609035daa38 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingProduct.java @@ -9,7 +9,6 @@ import io.deephaven.base.verify.Assert; import io.deephaven.datastructures.util.CollectionUtil; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.impl.indexer.DataIndexer; @@ -19,6 +18,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -157,58 +158,62 @@ static CreateResult createSmallTestTable(int tableSize, // region Object Helper functions - final Function, BigInteger> prodBigInt = bigIntegerObjectVector -> { + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { - if (bigIntegerObjectVector == null || bigIntegerObjectVector.size() == 0) { - return null; - } + public static BigInteger prodBigInt(ObjectVector bigIntegerObjectVector) { + if (bigIntegerObjectVector == null || bigIntegerObjectVector.isEmpty()) { + return null; + } - BigInteger product = BigInteger.ONE; + BigInteger product = BigInteger.ONE; - final long n = bigIntegerObjectVector.size(); - long nullCount = 0; + final long n = bigIntegerObjectVector.size(); + long nullCount = 0; - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - product = product.multiply(val); - } else { - nullCount++; + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + product = product.multiply(val); + } else { + nullCount++; + } } + return nullCount == n ? null : product; } - return nullCount == n ? null : product; - }; - final Function, BigDecimal> prodBigDec = bigDecimalObjectVector -> { - MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + public static BigDecimal prodBigDec(ObjectVector bigDecimalObjectVector) { + MathContext mathContextDefault = UpdateByControl.mathContextDefault(); - if (bigDecimalObjectVector == null || bigDecimalObjectVector.size() == 0) { - return null; - } + if (bigDecimalObjectVector == null || bigDecimalObjectVector.isEmpty()) { + return null; + } - BigDecimal product = BigDecimal.ONE; + BigDecimal product = BigDecimal.ONE; - final long n = bigDecimalObjectVector.size(); - long nullCount = 0; + final long n = bigDecimalObjectVector.size(); + long nullCount = 0; - for (long i = 0; i < n; i++) { - BigDecimal val = bigDecimalObjectVector.get(i); - if (!isNull(val)) { - product = product.multiply(val, mathContextDefault); - } else { - nullCount++; + for (long i = 0; i < n; i++) { + BigDecimal val = bigDecimalObjectVector.get(i); + if (!isNull(val)) { + product = product.multiply(val, mathContextDefault); + } else { + nullCount++; + } } + return nullCount == n ? null : product; } - return nullCount == n ? null : product; - }; + } private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("prodBigInt", prodBigInt); - QueryScope.addParam("prodBigDec", prodBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingProduct(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=prodBigInt(bigIntCol)", "bigDecimalCol=prodBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -242,15 +247,14 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("prodBigInt", prodBigInt); - QueryScope.addParam("prodBigDec", prodBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingProduct("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=prodBigInt.apply(bigIntCol)", - "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=prodBigInt(bigIntCol)", + "bigDecimalCol=prodBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -283,15 +287,14 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati } private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("prodBigInt", prodBigInt); - QueryScope.addParam("prodBigDec", prodBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingProduct(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=prodBigInt.apply(bigIntCol)", - "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=prodBigInt(bigIntCol)", + "bigDecimalCol=prodBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); @@ -325,15 +328,14 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("prodBigInt", prodBigInt); - QueryScope.addParam("prodBigDec", prodBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingProduct("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=prodBigInt.apply(bigIntCol)", "bigDecimalCol=prodBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=prodBigInt(bigIntCol)", "bigDecimalCol=prodBigDec(bigDecimalCol)"); BigInteger[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigInteger.class).toArray(); BigInteger[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigInteger.class).toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java index 2ad5b0bea49..787eb3d1bda 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingStd.java @@ -8,7 +8,6 @@ import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.base.verify.Assert; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.vectors.ColumnVectors; @@ -22,6 +21,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.ObjectVector; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -34,7 +35,6 @@ import java.util.List; import java.util.Objects; import java.util.Random; -import java.util.function.Function; import static io.deephaven.engine.testutil.GenerateTableUpdates.generateAppends; import static io.deephaven.engine.testutil.testcase.RefreshingTableTestCase.simulateShiftAwareStep; @@ -95,90 +95,95 @@ private String[] getCastingFormulas(String[] columns) { // region Object Helper functions - final Function, BigDecimal> stdBigInt = bigIntegerObjectVector -> { - MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { - if (bigIntegerObjectVector == null || bigIntegerObjectVector.size() == 0) { - return null; - } + public static BigDecimal stdBigInt(ObjectVector bigIntegerObjectVector) { + MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + + if (bigIntegerObjectVector == null || bigIntegerObjectVector.isEmpty()) { + return null; + } - BigDecimal sum = new BigDecimal(0); - BigDecimal sumSquares = new BigDecimal(0); - long count = 0; + BigDecimal sum = new BigDecimal(0); + BigDecimal sumSquares = new BigDecimal(0); + long count = 0; - final long n = bigIntegerObjectVector.size(); + final long n = bigIntegerObjectVector.size(); - for (long i = 0; i < n; i++) { - BigInteger val = bigIntegerObjectVector.get(i); - if (!isNull(val)) { - final BigDecimal decVal = new BigDecimal(val); - final BigDecimal decValSquare = decVal.multiply(decVal, mathContextDefault); + for (long i = 0; i < n; i++) { + BigInteger val = bigIntegerObjectVector.get(i); + if (!isNull(val)) { + final BigDecimal decVal = new BigDecimal(val); + final BigDecimal decValSquare = decVal.multiply(decVal, mathContextDefault); - sum = sum.add(decVal, mathContextDefault); - sumSquares = sumSquares.add(decValSquare, mathContextDefault); - count++; + sum = sum.add(decVal, mathContextDefault); + sumSquares = sumSquares.add(decValSquare, mathContextDefault); + count++; + } + } + if (count <= 1) { + return null; } - } - if (count <= 1) { - return null; - } - // complex calc for variance and std - final BigDecimal biCount = BigDecimal.valueOf(count); - final BigDecimal biCountMinusOne = BigDecimal.valueOf(count - 1); + // complex calc for variance and std + final BigDecimal biCount = BigDecimal.valueOf(count); + final BigDecimal biCountMinusOne = BigDecimal.valueOf(count - 1); - final BigDecimal variance = sumSquares.divide(biCountMinusOne, mathContextDefault) - .subtract(sum.multiply(sum, mathContextDefault).divide(biCount, mathContextDefault) - .divide(biCountMinusOne, mathContextDefault)); + final BigDecimal variance = sumSquares.divide(biCountMinusOne, mathContextDefault) + .subtract(sum.multiply(sum, mathContextDefault).divide(biCount, mathContextDefault) + .divide(biCountMinusOne, mathContextDefault)); - return variance.sqrt(mathContextDefault); - }; + return variance.sqrt(mathContextDefault); + } - final Function, BigDecimal> stdBigDec = bigDecimalObjectVector -> { - MathContext mathContextDefault = UpdateByControl.mathContextDefault(); + public static BigDecimal stdBigDec(ObjectVector bigDecimalObjectVector) { + MathContext mathContextDefault = UpdateByControl.mathContextDefault(); - if (bigDecimalObjectVector == null || bigDecimalObjectVector.size() == 0) { - return null; - } + if (bigDecimalObjectVector == null || bigDecimalObjectVector.isEmpty()) { + return null; + } - BigDecimal sum = new BigDecimal(0); - BigDecimal sumSquares = new BigDecimal(0); - long count = 0; + BigDecimal sum = new BigDecimal(0); + BigDecimal sumSquares = new BigDecimal(0); + long count = 0; - final long n = bigDecimalObjectVector.size(); + final long n = bigDecimalObjectVector.size(); - for (long i = 0; i < n; i++) { - BigDecimal decVal = bigDecimalObjectVector.get(i); - if (!isNull(decVal)) { - final BigDecimal decValSquare = decVal.multiply(decVal, mathContextDefault); + for (long i = 0; i < n; i++) { + BigDecimal decVal = bigDecimalObjectVector.get(i); + if (!isNull(decVal)) { + final BigDecimal decValSquare = decVal.multiply(decVal, mathContextDefault); - sum = sum.add(decVal, mathContextDefault); - sumSquares = sumSquares.add(decValSquare, mathContextDefault); - count++; + sum = sum.add(decVal, mathContextDefault); + sumSquares = sumSquares.add(decValSquare, mathContextDefault); + count++; + } + } + if (count <= 1) { + return null; } - } - if (count <= 1) { - return null; - } - // complex calc for variance and std - final BigDecimal biCount = BigDecimal.valueOf(count); - final BigDecimal biCountMinusOne = BigDecimal.valueOf(count - 1); + // complex calc for variance and std + final BigDecimal biCount = BigDecimal.valueOf(count); + final BigDecimal biCountMinusOne = BigDecimal.valueOf(count - 1); - final BigDecimal variance = sumSquares.divide(biCountMinusOne, mathContextDefault) - .subtract(sum.multiply(sum, mathContextDefault).divide(biCount, mathContextDefault) - .divide(biCountMinusOne, mathContextDefault)); + final BigDecimal variance = sumSquares.divide(biCountMinusOne, mathContextDefault) + .subtract(sum.multiply(sum, mathContextDefault).divide(biCount, mathContextDefault) + .divide(biCountMinusOne, mathContextDefault)); - return variance.sqrt(mathContextDefault); - }; + return variance.sqrt(mathContextDefault); + } + } private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("stdBigInt", stdBigInt); - QueryScope.addParam("stdBigDec", stdBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingStd(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=stdBigInt(bigIntCol)", "bigDecimalCol=stdBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -207,13 +212,12 @@ private void doTestStaticZeroKeyBigNumbers(final QueryTable t, final int prevTic private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("stdBigInt", stdBigInt); - QueryScope.addParam("stdBigDec", stdBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingStd("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")); Table expected = t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol")) - .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=stdBigInt(bigIntCol)", "bigDecimalCol=stdBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -241,14 +245,13 @@ private void doTestStaticZeroKeyTimedBigNumbers(final QueryTable t, final Durati } private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTicks, final int postTicks) { - QueryScope.addParam("stdBigInt", stdBigInt); - QueryScope.addParam("stdBigDec", stdBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingStd(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, postTicks, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=stdBigInt(bigIntCol)", "bigDecimalCol=stdBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); @@ -277,14 +280,13 @@ private void doTestStaticBucketedBigNumbers(final QueryTable t, final int prevTi private void doTestStaticBucketedTimedBigNumbers(final QueryTable t, final Duration prevTime, final Duration postTime) { - QueryScope.addParam("stdBigInt", stdBigInt); - QueryScope.addParam("stdBigDec", stdBigDec); + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); Table actual = t.updateBy(UpdateByOperation.RollingStd("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym"); Table expected = t .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol"), "Sym") - .update("bigIntCol=stdBigInt.apply(bigIntCol)", "bigDecimalCol=stdBigDec.apply(bigDecimalCol)"); + .update("bigIntCol=stdBigInt(bigIntCol)", "bigDecimalCol=stdBigDec(bigDecimalCol)"); BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); BigDecimal[] biExpected = ColumnVectors.ofObject(expected, "bigIntCol", BigDecimal.class).toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java index c9d8c77fbeb..d8d9ffa0cb9 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/updateby/TestRollingWAvg.java @@ -8,7 +8,6 @@ import io.deephaven.api.updateby.UpdateByOperation; import io.deephaven.base.verify.Assert; import io.deephaven.engine.context.ExecutionContext; -import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.QueryTable; import io.deephaven.engine.table.vectors.ColumnVectors; @@ -20,6 +19,8 @@ import io.deephaven.engine.util.TableDiff; import io.deephaven.test.types.OutOfBandTest; import io.deephaven.time.DateTimeUtils; +import io.deephaven.util.annotations.TestUseOnly; +import io.deephaven.util.annotations.VisibleForTesting; import io.deephaven.vector.DoubleVector; import io.deephaven.vector.ObjectVector; import io.deephaven.vector.ShortVector; @@ -120,260 +121,262 @@ public interface BiFunction { R apply(T1 val1, T2 val2); } - final BiFunction, DoubleVector, BigDecimal> wavgBigIntDouble = - (bigIntegerObjectVector, doubleVector) -> { - if (bigIntegerObjectVector == null || doubleVector == null) { - return null; - } + @SuppressWarnings("unused") // Functions used via QueryLibrary + @VisibleForTesting + @TestUseOnly + public static class Helpers { - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigIntDouble(ObjectVector bigIntegerObjectVector, + DoubleVector doubleVector) { + if (bigIntegerObjectVector == null || doubleVector == null) { + return null; + } - final long n = bigIntegerObjectVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigInteger val = bigIntegerObjectVector.get(i); - final double weightVal = doubleVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal decVal = new BigDecimal(val); - final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); + final long n = bigIntegerObjectVector.size(); - final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigInteger val = bigIntegerObjectVector.get(i); + final double weightVal = doubleVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal decVal = new BigDecimal(val); + final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); - final BiFunction, ShortVector, BigDecimal> wavgBigIntShort = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigIntShort(ObjectVector valueVector, ShortVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigInteger val = valueVector.get(i); - final short weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal decVal = new BigDecimal(val); - final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); + final long n = valueVector.size(); - final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigInteger val = valueVector.get(i); + final short weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal decVal = new BigDecimal(val); + final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); - final BiFunction, ObjectVector, BigDecimal> wavgBigIntBigInt = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigIntBigInt(ObjectVector valueVector, + ObjectVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigInteger val = valueVector.get(i); - final BigInteger weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal decVal = new BigDecimal(val); - final BigDecimal weightDecVal = new BigDecimal(weightVal); + final long n = valueVector.size(); - final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigInteger val = valueVector.get(i); + final BigInteger weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal decVal = new BigDecimal(val); + final BigDecimal weightDecVal = new BigDecimal(weightVal); - final BiFunction, ObjectVector, BigDecimal> wavgBigIntBigDec = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = decVal.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigIntBigDec(ObjectVector valueVector, + ObjectVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigInteger val = valueVector.get(i); - final BigDecimal weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal decVal = new BigDecimal(val); + final long n = valueVector.size(); - final BigDecimal weightedVal = decVal.multiply(weightVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigInteger val = valueVector.get(i); + final BigDecimal weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal decVal = new BigDecimal(val); - final BiFunction, DoubleVector, BigDecimal> wavgBigDecDouble = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = decVal.multiply(weightVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightVal, mathContextDefault); + count++; } + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigDecDouble(ObjectVector valueVector, DoubleVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigDecimal val = valueVector.get(i); - final double weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); + final long n = valueVector.size(); - final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigDecimal val = valueVector.get(i); + final double weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); - final BiFunction, ShortVector, BigDecimal> wavgBigDecShort = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigDecShort(ObjectVector valueVector, ShortVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigDecimal val = valueVector.get(i); - final short weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); + final long n = valueVector.size(); - final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigDecimal val = valueVector.get(i); + final short weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal weightDecVal = BigDecimal.valueOf(weightVal); - final BiFunction, ObjectVector, BigDecimal> wavgBigDecBigInt = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigDecBigInt(ObjectVector valueVector, + ObjectVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigDecimal val = valueVector.get(i); - final BigInteger weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal weightDecVal = new BigDecimal(weightVal); + final long n = valueVector.size(); - final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightDecVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; - } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + for (long i = 0; i < n; i++) { + final BigDecimal val = valueVector.get(i); + final BigInteger weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal weightDecVal = new BigDecimal(weightVal); - final BiFunction, ObjectVector, BigDecimal> wavgBigDecBigDec = - (valueVector, weightVector) -> { - if (valueVector == null || weightVector == null) { - return null; + final BigDecimal weightedVal = val.multiply(weightDecVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightDecVal, mathContextDefault); + count++; } + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } - BigDecimal weightValueSum = new BigDecimal(0); - BigDecimal weightSum = new BigDecimal(0); - long count = 0; + public static BigDecimal wavgBigDecBigDec(ObjectVector valueVector, + ObjectVector weightVector) { + if (valueVector == null || weightVector == null) { + return null; + } - final long n = valueVector.size(); + BigDecimal weightValueSum = new BigDecimal(0); + BigDecimal weightSum = new BigDecimal(0); + long count = 0; - for (long i = 0; i < n; i++) { - final BigDecimal val = valueVector.get(i); - final BigDecimal weightVal = weightVector.get(i); - if (!isNull(val) && !isNull(weightVal)) { - final BigDecimal weightedVal = val.multiply(weightVal, mathContextDefault); - weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); - weightSum = weightSum.add(weightVal, mathContextDefault); - count++; - } - } - if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { - return null; + final long n = valueVector.size(); + + for (long i = 0; i < n; i++) { + final BigDecimal val = valueVector.get(i); + final BigDecimal weightVal = weightVector.get(i); + if (!isNull(val) && !isNull(weightVal)) { + final BigDecimal weightedVal = val.multiply(weightVal, mathContextDefault); + weightValueSum = weightValueSum.add(weightedVal, mathContextDefault); + weightSum = weightSum.add(weightVal, mathContextDefault); + count++; } - return weightValueSum.divide(weightSum, mathContextDefault); - }; + } + if (count == 0 || weightSum.equals(BigDecimal.ZERO)) { + return null; + } + return weightValueSum.divide(weightSum, mathContextDefault); + } + } private void doTestStaticBigNumbers(final QueryTable t, final int prevTicks, final int fwdTicks, final boolean bucketed, final String weightCol, - final BiFunction bigIntFunction, - final BiFunction bigDecFunction) { - QueryScope.addParam("wavgBigInt", bigIntFunction); - QueryScope.addParam("wavgBigDec", bigDecFunction); + final String bigIntFunction, + final String bigDecFunction) { + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final String[] updateCols = new String[] { - String.format("bigIntCol=wavgBigInt.apply(bigIntCol, %s)", weightCol), - String.format("bigDecimalCol=wavgBigDec.apply(bigDecimalCol, %s)", weightCol), + String.format("bigIntCol=%s(bigIntCol, %s)", bigIntFunction, weightCol), + String.format("bigDecimalCol=%s(bigDecimalCol, %s)", bigDecFunction, weightCol), }; final Table actual; @@ -381,18 +384,15 @@ private void doTestStaticBigNumbers(final QueryTable t, if (bucketed) { actual = t.updateBy( UpdateByOperation.RollingWAvg(prevTicks, fwdTicks, weightCol, "bigIntCol", "bigDecimalCol"), "Sym"); - expected = t - .updateBy(UpdateByOperation.RollingGroup(prevTicks, fwdTicks, "bigIntCol", "bigDecimalCol", - weightCol), "Sym") + expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, fwdTicks, "bigIntCol", "bigDecimalCol", + weightCol), "Sym") .update(updateCols); } else { - actual = - t.updateBy(UpdateByOperation.RollingWAvg(prevTicks, fwdTicks, weightCol, "bigIntCol", - "bigDecimalCol")); - expected = - t.updateBy(UpdateByOperation.RollingGroup(prevTicks, fwdTicks, "bigIntCol", "bigDecimalCol", - weightCol)) - .update(updateCols); + actual = t.updateBy(UpdateByOperation.RollingWAvg(prevTicks, fwdTicks, weightCol, "bigIntCol", + "bigDecimalCol")); + expected = t.updateBy(UpdateByOperation.RollingGroup(prevTicks, fwdTicks, "bigIntCol", "bigDecimalCol", + weightCol)) + .update(updateCols); } BigDecimal[] biActual = ColumnVectors.ofObject(actual, "bigIntCol", BigDecimal.class).toArray(); @@ -423,14 +423,13 @@ private void doTestStaticTimedBigNumbers(final QueryTable t, final Duration postTime, final boolean bucketed, final String weightCol, - final BiFunction bigIntFunction, - final BiFunction bigDecFunction) { - QueryScope.addParam("wavgBigInt", bigIntFunction); - QueryScope.addParam("wavgBigDec", bigDecFunction); + final String bigIntFunction, + final String bigDecFunction) { + ExecutionContext.getContext().getQueryLibrary().importStatic(Helpers.class); final String[] updateCols = new String[] { - String.format("bigIntCol=wavgBigInt.apply(bigIntCol, %s)", weightCol), - String.format("bigDecimalCol=wavgBigDec.apply(bigDecimalCol, %s)", weightCol), + String.format("bigIntCol=%s(bigIntCol, %s)", bigIntFunction, weightCol), + String.format("bigDecimalCol=%s(bigDecimalCol, %s)", bigDecFunction, weightCol), }; final Table actual; @@ -439,10 +438,10 @@ private void doTestStaticTimedBigNumbers(final QueryTable t, actual = t.updateBy( UpdateByOperation.RollingWAvg("ts", prevTime, postTime, weightCol, "bigIntCol", "bigDecimalCol"), "Sym"); - expected = - t.updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol", + expected = t + .updateBy(UpdateByOperation.RollingGroup("ts", prevTime, postTime, "bigIntCol", "bigDecimalCol", weightCol), "Sym") - .update(updateCols); + .update(updateCols); } else { actual = t.updateBy( UpdateByOperation.RollingWAvg("ts", prevTime, postTime, weightCol, "bigIntCol", "bigDecimalCol")); @@ -516,7 +515,7 @@ private void doTestStatic(boolean bucketed, int prevTicks, int fwdTicks) { actual.dropColumns(weightCol), TableDiff.DiffItems.DoublesExact, TableDiff.DiffItems.DoubleFraction); - doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, wavgBigIntDouble, wavgBigDecDouble); + doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, "wavgBigIntDouble", "wavgBigDecDouble"); /////////////////////////////////////////////////////////////////////////// @@ -553,7 +552,7 @@ private void doTestStatic(boolean bucketed, int prevTicks, int fwdTicks) { actual.dropColumns(weightCol), TableDiff.DiffItems.DoublesExact, TableDiff.DiffItems.DoubleFraction); - doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, wavgBigIntShort, wavgBigDecShort); + doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, "wavgBigIntShort", "wavgBigDecShort"); /////////////////////////////////////////////////////////////////////////// @@ -565,7 +564,7 @@ private void doTestStatic(boolean bucketed, int prevTicks, int fwdTicks) { new TestDataGenerator[] { new BigIntegerGenerator(BigInteger.valueOf(-10), BigInteger.valueOf(10), .1)}).t; - doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, wavgBigIntBigInt, wavgBigDecBigInt); + doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, "wavgBigIntBigInt", "wavgBigDecBigInt"); weightCol = "bigDecWeightCol"; t = createTestTable(STATIC_TABLE_SIZE, bucketed, false, false, 0x31313131, @@ -573,7 +572,7 @@ private void doTestStatic(boolean bucketed, int prevTicks, int fwdTicks) { new TestDataGenerator[] { new BigDecimalGenerator(BigInteger.valueOf(1), BigInteger.valueOf(2), 5, .1)}).t; - doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, wavgBigIntBigDec, wavgBigDecBigDec); + doTestStaticBigNumbers(t, prevTicks, fwdTicks, bucketed, weightCol, "wavgBigIntBigDec", "wavgBigDecBigDec"); } private void doTestStaticTimed(boolean bucketed, Duration prevTime, Duration postTime) { @@ -618,7 +617,7 @@ private void doTestStaticTimed(boolean bucketed, Duration prevTime, Duration pos actual.dropColumns(weightCol), TableDiff.DiffItems.DoublesExact, TableDiff.DiffItems.DoubleFraction); - doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, wavgBigIntDouble, wavgBigDecDouble); + doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, "wavgBigIntDouble", "wavgBigDecDouble"); /////////////////////////////////////////////////////////////////////////// @@ -658,7 +657,7 @@ private void doTestStaticTimed(boolean bucketed, Duration prevTime, Duration pos actual.dropColumns(weightCol), TableDiff.DiffItems.DoublesExact, TableDiff.DiffItems.DoubleFraction); - doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, wavgBigIntShort, wavgBigDecShort); + doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, "wavgBigIntShort", "wavgBigDecShort"); /////////////////////////////////////////////////////////////////////////// @@ -671,7 +670,7 @@ private void doTestStaticTimed(boolean bucketed, Duration prevTime, Duration pos DateTimeUtils.parseInstant("2022-03-09T16:30:00.000 NY")), new BigIntegerGenerator(BigInteger.valueOf(-10), BigInteger.valueOf(10), .1)}).t; - doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, wavgBigIntBigInt, wavgBigDecBigInt); + doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, "wavgBigIntBigInt", "wavgBigDecBigInt"); weightCol = "bigDecWeightCol"; t = createTestTable(STATIC_TABLE_SIZE, bucketed, false, false, 0x31313131, @@ -680,7 +679,7 @@ private void doTestStaticTimed(boolean bucketed, Duration prevTime, Duration pos DateTimeUtils.parseInstant("2022-03-09T16:30:00.000 NY")), new BigDecimalGenerator(BigInteger.valueOf(1), BigInteger.valueOf(2), 5, .1)}).t; - doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, wavgBigIntBigDec, wavgBigDecBigDec); + doTestStaticTimedBigNumbers(t, prevTime, postTime, bucketed, weightCol, "wavgBigIntBigDec", "wavgBigDecBigDec"); } @Test diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java b/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java index 851d4112b16..4bae86ac383 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestTableTools.java @@ -273,11 +273,11 @@ public void testRoundDecimalColumns() { roundedColumns.getColumnSource("Double").getLong(roundedColumns.getRowSet().get(2))); // Cast these cause the DB rounds floats to longs assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(0))), - roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(0))); + roundedColumns.getColumnSource("Float").getLong(roundedColumns.getRowSet().get(0))); assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(1))), - roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(1))); + roundedColumns.getColumnSource("Float").getLong(roundedColumns.getRowSet().get(1))); assertEquals(Math.round(table.getColumnSource("Float").getFloat(table.getRowSet().get(2))), - roundedColumns.getColumnSource("Float").getInt(roundedColumns.getRowSet().get(2))); + roundedColumns.getColumnSource("Float").getLong(roundedColumns.getRowSet().get(2))); // Test whether it works when we specify the columns, by comparing to the validated results from before Table specificRoundedColumns = TableTools.roundDecimalColumns(table, "Double", "Float"); diff --git a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java index cff4d938be4..cde34dd3ee5 100644 --- a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java +++ b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java @@ -29,7 +29,11 @@ import io.deephaven.csv.tokenization.Tokenizer.CustomTimeZoneParser; import io.deephaven.csv.util.CsvReaderException; import io.deephaven.datastructures.util.CollectionUtil; -import io.deephaven.engine.rowset.*; +import io.deephaven.engine.rowset.RowSequence; +import io.deephaven.engine.rowset.RowSequenceFactory; +import io.deephaven.engine.rowset.RowSet; +import io.deephaven.engine.rowset.RowSetFactory; +import io.deephaven.engine.rowset.TrackingRowSet; import io.deephaven.engine.table.ChunkSink; import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.Table; @@ -915,14 +919,14 @@ private static void writeCsvContentsSeq( final RowSet.Iterator rowsIter = rows.iterator()) { String separatorStr = String.valueOf(separator); for (long ri = 0; ri < size; ri++) { - for (int j = 0; j < cols.length; j++) { - if (j > 0) { + final long rowKey = rowsIter.nextLong(); + for (int ci = 0; ci < cols.length; ci++) { + if (ci > 0) { out.write(separatorStr); } else { out.write("\n"); } - final long rowKey = rowsIter.nextLong(); - final Object o = cols[j].get(rowKey); + final Object o = cols[ci].get(rowKey); if (o instanceof String) { out.write("" + separatorCsvEscape((String) o, separatorStr)); } else if (o instanceof Instant) { diff --git a/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java b/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java index d6393ed9dc1..aef7108115c 100644 --- a/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java +++ b/extensions/csv/src/test/java/io/deephaven/csv/TestCsvTools.java @@ -8,7 +8,6 @@ import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; import io.deephaven.engine.table.impl.InMemoryTable; -import io.deephaven.engine.table.vectors.ColumnVectors; import io.deephaven.engine.testutil.TstUtils; import io.deephaven.engine.testutil.junit4.EngineCleanup; import io.deephaven.test.types.OutOfBandTest; From 76ff5f4402cc646194bbd53e1de0446b553a48fa Mon Sep 17 00:00:00 2001 From: Ryan Caudy Date: Tue, 4 Jun 2024 09:48:03 -0400 Subject: [PATCH 3/4] Finish deleting DataColumn --- .../io/deephaven/engine/table/DataColumn.java | 226 ---------- .../engine/table/impl/IndexedDataColumn.java | 418 ------------------ .../engine/table/impl/QueryTableTest.java | 31 +- .../main/java/io/deephaven/csv/CsvTools.java | 2 +- 4 files changed, 14 insertions(+), 663 deletions(-) delete mode 100644 engine/api/src/main/java/io/deephaven/engine/table/DataColumn.java delete mode 100644 engine/table/src/main/java/io/deephaven/engine/table/impl/IndexedDataColumn.java diff --git a/engine/api/src/main/java/io/deephaven/engine/table/DataColumn.java b/engine/api/src/main/java/io/deephaven/engine/table/DataColumn.java deleted file mode 100644 index 2144cd79c2f..00000000000 --- a/engine/api/src/main/java/io/deephaven/engine/table/DataColumn.java +++ /dev/null @@ -1,226 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table; - -import io.deephaven.util.datastructures.LongSizedDataStructure; - -/** - * Interface for positional column access to a Deephaven table column. - */ -@SuppressWarnings("unused") -public interface DataColumn extends LongSizedDataStructure { - - String getName(); - - /** - * @return the type of object contained within this column. - */ - Class getType(); - - /** - * Get the array component type, or the type itself. For basic types, this is just the type. For example, if you - * have a column of java.lang.String, this also returns java.lang.String. For array types (java Arrays), or Vector - * (which would be returned by getType), you get the type that is contained within the array. For example, if a - * single row in this column contains a DoubleVector, getComponentType returns double. - * - * @return if type is an array, the type of object within the array. Otherwise type itself. - */ - Class getComponentType(); - - /** - * Get the contents of this data column in array form. Note that this will return an array of the appropriate - * primitive type for columns of non-Boolean primitive types. - * - * @return An appropriately-typed array containing the full contents of this data column - */ - default Object getDirect() { - return getDirect(0, size()); - } - - /** - * Get the contents of a range of this data column in array form. See {@link #getDirect()} for an explanation of - * return types. Note that it's required that {@code endIndexExclusive - startIndexInclusive < Integer.MAX_VALUE}. - * - * @param startIndexInclusive The first position in the data column to include, inclusive - * @param endIndexExclusive One more than the last position in the data column to include - * @return An appropriately-typed array containing the contents of the specified range of this data column - */ - default Object getDirect(final long startIndexInclusive, final long endIndexExclusive) { - final Class type = getType(); - if (type == byte.class || type == Byte.class) { - return getBytes(startIndexInclusive, endIndexExclusive); - } - if (type == char.class || type == Character.class) { - return getChars(startIndexInclusive, endIndexExclusive); - } - if (type == double.class || type == Double.class) { - return getDoubles(startIndexInclusive, endIndexExclusive); - } - if (type == float.class || type == Float.class) { - return getFloats(startIndexInclusive, endIndexExclusive); - } - if (type == int.class || type == Integer.class) { - return getInts(startIndexInclusive, endIndexExclusive); - } - if (type == long.class || type == Long.class) { - return getLongs(startIndexInclusive, endIndexExclusive); - } - if (type == short.class || type == Short.class) { - return getShorts(startIndexInclusive, endIndexExclusive); - } - return get(startIndexInclusive, endIndexExclusive); - } - - default Object getDirect(final long... indexes) { - final Class type = getType(); - if (type == byte.class || type == Byte.class) { - return getBytes(indexes); - } - if (type == char.class || type == Character.class) { - return getChars(indexes); - } - if (type == double.class || type == Double.class) { - return getDoubles(indexes); - } - if (type == float.class || type == Float.class) { - return getFloats(indexes); - } - if (type == int.class || type == Integer.class) { - return getInts(indexes); - } - if (type == long.class || type == Long.class) { - return getLongs(indexes); - } - if (type == short.class || type == Short.class) { - return getShorts(indexes); - } - return get(indexes); - } - - default Object getDirect(final int... indexes) { - final Class type = getType(); - if (type == byte.class || type == Byte.class) { - return getBytes(indexes); - } - if (type == char.class || type == Character.class) { - return getChars(indexes); - } - if (type == double.class || type == Double.class) { - return getDoubles(indexes); - } - if (type == float.class || type == Float.class) { - return getFloats(indexes); - } - if (type == int.class || type == Integer.class) { - return getInts(indexes); - } - if (type == long.class || type == Long.class) { - return getLongs(indexes); - } - if (type == short.class || type == Short.class) { - return getShorts(indexes); - } - return get(indexes); - } - - /** - * Returns the value in the column at the row designated by the row position - * - * @param index - the row position for which the data is being retrieved - * @return the value in the column at the row designated by the row position - */ - TYPE get(long index); - - /** - * Return the column's values for the specified row range. Note that this will be a boxed array, for data columns of - * primitive types. - * - * @param startIndexInclusive The first position in the data column to include, inclusive - * @param endIndexExclusive One more than the last position in the data column to include - * @return Return the column's values for the specified row range - */ - TYPE[] get(long startIndexInclusive, long endIndexExclusive); - - /** - * Return the column's values for the specified rows. Note that this will be a boxed array, for data columns of - * primitive types. - * - * @param indexes The row indexes to fetch - * @return Return the column's values for the specified rows - */ - TYPE[] get(long... indexes); - - /** - * Return the column's values for the specified rows. Note that this will be a boxed array, for data columns of - * primitive types. - * - * @param indexes The row indexes to fetch - * @return Return the column's values for the specified rows - */ - TYPE[] get(int... indexes); - - Boolean getBoolean(long index); - - Boolean[] getBooleans(long startIndexInclusive, long endIndexExclusive); - - Boolean[] getBooleans(long... indexes); - - Boolean[] getBooleans(int... indexes); - - byte getByte(long index); - - byte[] getBytes(long startIndexInclusive, long endIndexExclusive); - - byte[] getBytes(long... indexes); - - byte[] getBytes(int... indexes); - - char getChar(long index); - - char[] getChars(long startIndexInclusive, long endIndexExclusive); - - char[] getChars(long... indexes); - - char[] getChars(int... indexes); - - double getDouble(long index); - - double[] getDoubles(long startIndexInclusive, long endIndexExclusive); - - double[] getDoubles(long... indexes); - - double[] getDoubles(int... indexes); - - float getFloat(long index); - - float[] getFloats(long startIndexInclusive, long endIndexExclusive); - - float[] getFloats(long... indexes); - - float[] getFloats(int... indexes); - - int getInt(long index); - - int[] getInts(long startIndexInclusive, long endIndexExclusive); - - int[] getInts(long... indexes); - - int[] getInts(int... indexes); - - long getLong(long index); - - long[] getLongs(long startIndexInclusive, long endIndexExclusive); - - long[] getLongs(long... indexes); - - long[] getLongs(int... indexes); - - short getShort(long index); - - short[] getShorts(long startIndexInclusive, long endIndexExclusive); - - short[] getShorts(long... indexes); - - short[] getShorts(int... indexes); -} diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/IndexedDataColumn.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/IndexedDataColumn.java deleted file mode 100644 index 8e4324f54d3..00000000000 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/IndexedDataColumn.java +++ /dev/null @@ -1,418 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl; - -import io.deephaven.engine.table.*; -import io.deephaven.chunk.*; -import io.deephaven.engine.rowset.RowSet; -import io.deephaven.engine.rowset.TrackingRowSet; -import io.deephaven.engine.table.iterators.ChunkedColumnIterator; -import io.deephaven.util.QueryConstants; -import io.deephaven.util.annotations.ReferentialIntegrity; -import io.deephaven.util.type.TypeUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.stream.StreamSupport; - -/** - * DataColumn implementation backed by a ColumnSource and a RowSet. - */ -@SuppressWarnings("WeakerAccess") -public class IndexedDataColumn implements DataColumn { - - private final String name; - @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) - @ReferentialIntegrity - private final Object parent; // DO NOT DELETE - This reference preserves strong-reachability of the owning table and - // its listeners. - private final RowSet rowSet; - private final ColumnSource columnSource; - - public IndexedDataColumn(@NotNull final String name, @NotNull final Table table) { - this(name, table, table.getRowSet(), table.getColumnSource(name)); - } - - public IndexedDataColumn(@NotNull final String name, @NotNull final RowSet rowSet, - @NotNull final ColumnSource columnSource) { - this(name, null, rowSet, columnSource); - } - - private IndexedDataColumn(@Nullable final String name, @Nullable final Object parent, @NotNull final RowSet rowSet, - @NotNull final ColumnSource columnSource) { - this.name = name; - this.parent = parent; - this.rowSet = rowSet; - this.columnSource = columnSource; - } - - /** - * This is intended as a unit test helper. It is not recommended for inexpert use. - * - * @param rowSet The RowSet - * @param columnSource The column source - * @return A data column with previous values for the supplied column source, according to the previous version of - * the RowSet - */ - public static IndexedDataColumn makePreviousColumn(@NotNull final TrackingRowSet rowSet, - @NotNull final ColumnSource columnSource) { - return new IndexedDataColumn<>(null, null, rowSet.copyPrev(), new PrevColumnSource<>(columnSource)); - } - - @Override - public String getName() { - return name; - } - - @Override - public Class getType() { - return columnSource.getType(); - } - - @Override - public Class getComponentType() { - return columnSource.getComponentType(); - } - - @Override - public long size() { - return rowSet.size(); - } - - // ------------------------------------------------------------------------------------------------------------------ - // Helpers - // ------------------------------------------------------------------------------------------------------------------ - - private RowSet getSubIndexByPos(final long startPosInclusive, final long endPosExclusive) { - return startPosInclusive == 0 && endPosExclusive == rowSet.size() ? rowSet.copy() - : rowSet.subSetByPositionRange(startPosInclusive, endPosExclusive); - } - - // ------------------------------------------------------------------------------------------------------------------ - // Get method implementations - // ------------------------------------------------------------------------------------------------------------------ - - @Override - public TYPE get(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return null; - } - return columnSource.get(index); - } - - @Override - public TYPE[] get(final long startPosInclusive, final long endPosExclusive) { - final Iterable iterable = - () -> ChunkedColumnIterator.make(columnSource, getSubIndexByPos(startPosInclusive, endPosExclusive)); - // noinspection unchecked - return StreamSupport.stream(iterable.spliterator(), false).toArray(s -> (TYPE[]) Array - .newInstance(io.deephaven.util.type.TypeUtils.getBoxedType(columnSource.getType()), s)); - } - - @Override - public TYPE[] get(final long... positions) { - // noinspection unchecked - return Arrays.stream(positions).map(rowSet::get).mapToObj(columnSource::get).toArray(s -> (TYPE[]) Array - .newInstance(io.deephaven.util.type.TypeUtils.getBoxedType(columnSource.getType()), s)); - } - - @Override - public TYPE[] get(final int... positions) { - // noinspection unchecked - return Arrays.stream(positions).mapToLong(i -> i).map(rowSet::get).mapToObj(columnSource::get) - .toArray(s -> (TYPE[]) Array.newInstance(TypeUtils.getBoxedType(columnSource.getType()), s)); - } - - @Override - public Boolean getBoolean(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return null; - } - return columnSource.getBoolean(index); - } - - @Override - public Boolean[] getBooleans(final long startPosInclusive, final long endPosExclusive) { - return (Boolean[]) get(startPosInclusive, endPosExclusive); - } - - @Override - public Boolean[] getBooleans(final long... positions) { - return (Boolean[]) get(positions); - } - - public Boolean[] getBooleans(final int... positions) { - return (Boolean[]) get(positions); - } - - @Override - public byte getByte(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_BYTE; - } - return columnSource.getByte(index); - } - - @Override - public byte[] getBytes(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getBytes"), null)) { - final byte[] result = new byte[rangeRowSet.intSize("getBytes")]; - columnSource.fillChunk(context, WritableByteChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public byte[] getBytes(final long... positions) { - final byte[] result = new byte[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getByte(positions[pi]); - } - return result; - } - - @Override - public byte[] getBytes(final int... positions) { - final byte[] result = new byte[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getByte(positions[pi]); - } - return result; - } - - @Override - public char getChar(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_CHAR; - } - return columnSource.getChar(index); - } - - @Override - public char[] getChars(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getChars"), null)) { - final char[] result = new char[rangeRowSet.intSize("getChars")]; - columnSource.fillChunk(context, WritableCharChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public char[] getChars(final long... positions) { - final char[] result = new char[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getChar(positions[pi]); - } - return result; - } - - @Override - public char[] getChars(final int... positions) { - final char[] result = new char[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getChar(positions[pi]); - } - return result; - } - - @Override - public double getDouble(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_DOUBLE; - } - return columnSource.getDouble(index); - } - - @Override - public double[] getDoubles(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getDoubles"), null)) { - final double[] result = new double[rangeRowSet.intSize("getDoubles")]; - columnSource.fillChunk(context, WritableDoubleChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public double[] getDoubles(final long... positions) { - final double[] result = new double[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getDouble(positions[pi]); - } - return result; - } - - @Override - public double[] getDoubles(final int... positions) { - final double[] result = new double[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getDouble(positions[pi]); - } - return result; - } - - @Override - public float getFloat(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_FLOAT; - } - return columnSource.getFloat(index); - } - - @Override - public float[] getFloats(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getFloats"), null)) { - final float[] result = new float[rangeRowSet.intSize("getFloats")]; - columnSource.fillChunk(context, WritableFloatChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public float[] getFloats(final long... positions) { - final float[] result = new float[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getFloat(positions[pi]); - } - return result; - } - - @Override - public float[] getFloats(final int... positions) { - final float[] result = new float[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getFloat(positions[pi]); - } - return result; - } - - @Override - public int getInt(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_INT; - } - return columnSource.getInt(index); - } - - @Override - public int[] getInts(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getInts"), null)) { - final int[] result = new int[rangeRowSet.intSize("getInts")]; - columnSource.fillChunk(context, WritableIntChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public int[] getInts(final long... positions) { - final int[] result = new int[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getInt(positions[pi]); - } - return result; - } - - @Override - public int[] getInts(final int... positions) { - final int[] result = new int[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getInt(positions[pi]); - } - return result; - } - - @Override - public long getLong(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_LONG; - } - return columnSource.getLong(index); - } - - @Override - public long[] getLongs(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getLongs"), null)) { - final long[] result = new long[rangeRowSet.intSize("getLongs")]; - columnSource.fillChunk(context, WritableLongChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public long[] getLongs(final long... positions) { - final long[] result = new long[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getLong(positions[pi]); - } - return result; - } - - @Override - public long[] getLongs(final int... positions) { - final long[] result = new long[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getLong(positions[pi]); - } - return result; - } - - @Override - public short getShort(final long pos) { - long index = this.rowSet.get(pos); - if (index == -1) { - return QueryConstants.NULL_SHORT; - } - return columnSource.getShort(index); - } - - @Override - public short[] getShorts(final long startPosInclusive, final long endPosExclusive) { - try (final RowSet rangeRowSet = getSubIndexByPos(startPosInclusive, endPosExclusive); - final ChunkSource.FillContext context = - columnSource.makeFillContext(rangeRowSet.intSize("getShorts"), null)) { - final short[] result = new short[rangeRowSet.intSize("getShorts")]; - columnSource.fillChunk(context, WritableShortChunk.writableChunkWrap(result), rangeRowSet); - return result; - } - } - - @Override - public short[] getShorts(final long... positions) { - final short[] result = new short[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getShort(positions[pi]); - } - return result; - } - - @Override - public short[] getShorts(final int... positions) { - final short[] result = new short[positions.length]; - for (int pi = 0; pi < positions.length; ++pi) { - result[pi] = getShort(positions[pi]); - } - return result; - } -} diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java index 0431990a69b..760adec5301 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/QueryTableTest.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.table.impl; -import com.google.common.primitives.Ints; import io.deephaven.UncheckedDeephavenException; import io.deephaven.api.Selectable; import io.deephaven.api.agg.spec.AggSpec; @@ -2762,11 +2761,10 @@ public void testUngroupableColumnSources() { fail("Expected does not match direct value!"); } - int[] intPrevDirect = - (int[]) IndexedDataColumn.makePreviousColumn(t2.getRowSet(), t2.getColumnSource("Int")).getDirect(); - if (!Arrays.equals(expected, intPrevDirect)) { + int[] intPrev = ColumnVectors.ofInt(t2, "Int", true).toArray(); + if (!Arrays.equals(expected, intPrev)) { System.out.println("Expected: " + Arrays.toString(expected)); - System.out.println("Prev: " + Arrays.toString(intPrevDirect)); + System.out.println("Prev: " + Arrays.toString(intPrev)); fail("Expected does not match previous value!"); } @@ -2774,11 +2772,10 @@ public void testUngroupableColumnSources() { updateGraph.runWithinUnitTestCycle(() -> { }); - intPrevDirect = - (int[]) IndexedDataColumn.makePreviousColumn(t2.getRowSet(), t2.getColumnSource("Int")).getDirect(); - if (!Arrays.equals(expected, intPrevDirect)) { + intPrev = ColumnVectors.ofInt(t2, "Int", true).toArray(); + if (!Arrays.equals(expected, intPrev)) { System.out.println("Expected: " + Arrays.toString(expected)); - System.out.println("Prev: " + Arrays.toString(intPrevDirect)); + System.out.println("Prev: " + Arrays.toString(intPrev)); fail("Expected does not match previous value!"); } } @@ -2847,10 +2844,9 @@ public void testUngroupWithRebase() { assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}, ColumnVectors.ofObject(t1, "Y", String.class).toArray()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2), Ints.asList( - (int[]) IndexedDataColumn.makePreviousColumn(t1.getRowSet(), t1.getColumnSource("X")).getDirect())); - assertEquals(Arrays.asList("a", "b", "c", "d", "e"), Arrays.asList((String[]) IndexedDataColumn - .makePreviousColumn(t1.getRowSet(), t1.getColumnSource("Y")).getDirect())); + assertArrayEquals(new int[] {1, 1, 1, 2, 2}, ColumnVectors.ofInt(t1, "X", true).toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e"}, + ColumnVectors.ofObject(t1, "Y", String.class, true).toArray()); updateGraph.runWithinUnitTestCycle(() -> { }); @@ -2860,11 +2856,10 @@ public void testUngroupWithRebase() { assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}, ColumnVectors.ofObject(t1, "Y", String.class).toArray()); - assertEquals(Arrays.asList(1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3), Ints.asList( - (int[]) IndexedDataColumn.makePreviousColumn(t1.getRowSet(), t1.getColumnSource("X")).getDirect())); - assertEquals(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), - Arrays.asList((String[]) IndexedDataColumn - .makePreviousColumn(t1.getRowSet(), t1.getColumnSource("Y")).getDirect())); + assertArrayEquals(new int[] {1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3}, + ColumnVectors.ofInt(t1, "X", true).toArray()); + assertArrayEquals(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}, + ColumnVectors.ofObject(t1, "Y", String.class, true).toArray()); } finally { QueryTable.setMinimumUngroupBase(minimumUngroupBase); } diff --git a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java index cde34dd3ee5..0b9bdf4c27e 100644 --- a/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java +++ b/extensions/csv/src/main/java/io/deephaven/csv/CsvTools.java @@ -893,7 +893,7 @@ protected static String separatorCsvEscape(String str, String separator) { } /** - * Writes an array of Deephaven DataColumns out as a CSV file. + * Writes Deephaven columns out as a CSV file. * * @param out a Writer to which the header should be written * @param timeZone a time zone constant relative to which date time data should be adjusted From a1e00bb1b71bd6ae1bdb1e054680ba165c0ff4ff Mon Sep 17 00:00:00 2001 From: Ryan Caudy Date: Tue, 4 Jun 2024 19:30:04 -0400 Subject: [PATCH 4/4] Cleanups noted in code review --- .../engine/table/impl/TestPartitionAwareSourceTable.java | 2 +- .../test/java/io/deephaven/engine/table/impl/TestSort.java | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java index 5a94d867a3b..f6b838c0646 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestPartitionAwareSourceTable.java @@ -614,7 +614,7 @@ public void testSelectDistinctDate() { }); final Table result = SUT.selectDistinct(PARTITIONING_COLUMN_DEFINITION.getName()); assertIsSatisfied(); - final @NotNull String columnName = PARTITIONING_COLUMN_DEFINITION.getName(); + final String columnName = PARTITIONING_COLUMN_DEFINITION.getName(); final ObjectVector distinctDatesVector = ColumnVectors.ofObject(result, columnName, String.class); assertEquals(expectedDistinctDates.length, distinctDatesVector.size()); final String[] distinctDates = distinctDatesVector.toArray(); diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java index ede03a45561..7249e99a011 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/TestSort.java @@ -24,7 +24,6 @@ import java.util.function.BiFunction; import io.deephaven.util.mutable.MutableInt; -import io.deephaven.vector.IntVector; import org.jetbrains.annotations.NotNull; import org.junit.experimental.categories.Category; @@ -654,20 +653,18 @@ private void sortTester(int ncols, int size, Comparable[][] columnData, Table so } private void sortTester(int ncols, int size, Comparable[][] columnData, Table source, boolean isRefreshing) { - ((QueryTable) source).setRefreshing(isRefreshing); + source.setRefreshing(isRefreshing); // Now sort the table by the sentinel, which should just give us a simple ordering. assertEquals(source.size(), size); Table result0 = source.sort("Sentinel"); - // show(result0); final MutableInt expected = new MutableInt(1); try (final CloseablePrimitiveIteratorOfInt sentinelIterator = result0.integerColumnIterator("Sentinel")) { sentinelIterator.forEachRemaining((final int actual) -> assertEquals(expected.getAndIncrement(), actual)); } Table result1 = source.sortDescending("Sentinel"); - // show(result1); expected.set(size); try (final CloseablePrimitiveIteratorOfInt sentinelIterator = result1.integerColumnIterator("Sentinel")) { sentinelIterator.forEachRemaining((final int actual) -> assertEquals(expected.getAndAdd(-1), actual)); @@ -683,8 +680,6 @@ private void sortTester(int ncols, int size, Comparable[][] columnData, Table so System.out.println("Sorted by " + Arrays.toString(colNames)); Table resultAscending = source.sort(colNames); Table resultDescending = source.sortDescending(colNames); - // TableTools.show(resultAscending); - // TableTools.show(resultDescending); final MultiColumnSortHelper multiColumnSortHelper = new MultiColumnSortHelper(columnData, ii); try (final CloseablePrimitiveIteratorOfInt sentinelAscending =