Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port DH-12049: Improve and Refactor TestColumnSources and TestDataGeneration #3269

Merged
merged 8 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import io.deephaven.benchmarking.BenchmarkTableBuilder;
import io.deephaven.benchmarking.BenchmarkTools;

import static io.deephaven.engine.testutil.TstUtils.assertTableEquals;

public class TestTableGeneration extends QueryTableTestBase {

public void testCreateHistorical() {
Expand Down Expand Up @@ -38,7 +40,7 @@ public void testCreateHistorical() {
// Next make sure it's repeatable
bt.reset();

assertEquals("", TableTools.diff(bt.getTable(), historicalTable, 1));
assertTableEquals(bt.getTable(), historicalTable);
}

public void testCreateIntraday() {
Expand All @@ -62,7 +64,7 @@ public void testCreateIntraday() {
// Next make sure it's repeatable
bt.reset();

assertEquals("", TableTools.diff(bt.getTable(), intradayTable, 1));
assertTableEquals(bt.getTable(), intradayTable);
}

public void testCreateSparseInMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.deephaven.plot.util.tables.TableHandle;

import static io.deephaven.engine.testutil.TstUtils.*;
import static io.deephaven.engine.util.TableTools.col;

public class XYErrorBarDataSeriesTableArrayTest extends BaseArrayTestCase {

Expand Down Expand Up @@ -85,7 +86,7 @@ public void testRefreshingTable() {
final ChartImpl chart = figure.newChart();

final QueryTable refreshingTable = TstUtils.testRefreshingTable(i(2, 4, 6).toTracking(),
c("x", 1, 2, 3), c("y", 1, 2, 3), c("yLow", 0, 1, 2), c("yHigh", 11, 22, 33));
col("x", 1, 2, 3), col("y", 1, 2, 3), col("yLow", 0, 1, 2), col("yHigh", 11, 22, 33));

final TableHandle h = new TableHandle(refreshingTable, "x", "y", "yLow", "yHigh");
final XYErrorBarDataSeriesTableArray series = new XYErrorBarDataSeriesTableArray(chart.newAxes(), 1, "Test", h,
Expand All @@ -95,7 +96,7 @@ public void testRefreshingTable() {
assertEquals(series.getX(4), Double.NaN);

UpdateGraphProcessor.DEFAULT.runWithinUnitTestCycle(() -> {
addToTable(refreshingTable, i(7, 9), c("x", 4, 5), c("y", 4, 5), c("yLow", 3, 4), c("yHigh", 5, 6));
addToTable(refreshingTable, i(7, 9), col("x", 4, 5), col("y", 4, 5), col("yLow", 3, 4), col("yHigh", 5, 6));
refreshingTable.notifyListeners(i(7, 9), i(), i());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface TupleSource<TUPLE_TYPE> extends TupleExporter<TUPLE_TYPE>, Chun
*
* @return The column sources
*/
List<ColumnSource> getColumnSources();
List<ColumnSource<?>> getColumnSources();

/**
* Create a tuple for key column values at the supplied row key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractColumnSource<T> implements
protected final Class<?> componentType;

protected volatile Map<T, RowSet> groupToRange;
protected volatile List<ColumnSource> rowSetIndexerKey;
protected volatile List<ColumnSource<?>> rowSetIndexerKey;

protected AbstractColumnSource(@NotNull final Class<T> type) {
this(type, Object.class);
Expand Down Expand Up @@ -105,8 +105,8 @@ public ColumnSource<T> getPrevSource() {
}

@Override
public List<ColumnSource> getColumnSources() {
List<ColumnSource> localRowSetIndexerKey;
public List<ColumnSource<?>> getColumnSources() {
List<ColumnSource<?>> localRowSetIndexerKey;
if ((localRowSetIndexerKey = rowSetIndexerKey) == null) {
synchronized (this) {
if ((localRowSetIndexerKey = rowSetIndexerKey) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ public static ArrayBackedColumnSource<Long> getMemoryColumnSource(@NotNull final
return result;
}

/**
* Produces an DateTimeArraySource with the given data.
*
* @param data an array containing the data to insert into the ColumnSource, represented as long nanoseconds since
* the epoch
* @return an in-memory column source with the requested data
*/
public static ArrayBackedColumnSource<DateTime> getDateTimeMemoryColumnSource(LongChunk<Values> data) {
final ArrayBackedColumnSource<DateTime> result = new DateTimeArraySource();
result.ensureCapacity(data.size());
for (int ii = 0; ii < data.size(); ++ii) {
result.set(ii, data.get(ii));
}
return result;
}

/**
* Produces an DateTimeArraySource with the given data.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.deephaven.engine.table.impl.sources;

import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.AbstractColumnSource;
import io.deephaven.engine.table.impl.MutableColumnSourceGetDefaults;
import io.deephaven.time.DateTime;
import org.jetbrains.annotations.NotNull;

/**
* Reinterpret result for many {@link ColumnSource} implementations that internally represent {@link DateTime} values
* as {@code long} values.
*/
public class UnboxedLongBackedColumnSource<T> extends AbstractColumnSource<Long> implements MutableColumnSourceGetDefaults.ForLong {
private final ColumnSource<T> alternateColumnSource;

public UnboxedLongBackedColumnSource(ColumnSource<T> alternateColumnSource) {
super(long.class);
this.alternateColumnSource = alternateColumnSource;
}

@Override
public long getLong(long index) {
return alternateColumnSource.getLong(index);
}

@Override
public long getPrevLong(long index) {
return alternateColumnSource.getPrevLong(index);
}

@Override
public boolean isImmutable() {
return alternateColumnSource.isImmutable();
}

@Override
public <ALTERNATE_DATA_TYPE> boolean allowsReinterpret(
@NotNull final Class<ALTERNATE_DATA_TYPE> alternateDataType) {
if (alternateDataType == alternateColumnSource.getType()) {
// this is a trivial return conversion
return true;
}
return alternateColumnSource.allowsReinterpret(alternateDataType);
}

@Override
public <ALTERNATE_DATA_TYPE> ColumnSource<ALTERNATE_DATA_TYPE> doReinterpret(
@NotNull final Class<ALTERNATE_DATA_TYPE> alternateDataType) throws IllegalArgumentException {
if (alternateDataType == alternateColumnSource.getType()) {
// this is a trivial return conversion
//noinspection unchecked
return (ColumnSource<ALTERNATE_DATA_TYPE>) alternateColumnSource;
}
return alternateColumnSource.reinterpret(alternateDataType);
}
}

Loading