Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
cpwright committed Nov 4, 2024
1 parent 96013cd commit d8a2f5f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public boolean isStateless() {

@Override
public FunctionalColumn<S, D> copy() {
return new FunctionalColumn<>(sourceName, sourceDataType, destName, destDataType, componentType, function, alwaysEvaluate);
return new FunctionalColumn<>(sourceName, sourceDataType, destName, destDataType, componentType, function,
alwaysEvaluate);
}

@Override
Expand All @@ -263,6 +264,7 @@ public boolean alwaysEvaluate() {

@Override
public SelectColumn alwaysEvaluateCopy() {
return new FunctionalColumn<>(sourceName, sourceDataType, destName, destDataType, componentType, function, true);
return new FunctionalColumn<>(sourceName, sourceDataType, destName, destDataType, componentType, function,
true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public boolean isStateless() {

@Override
public MultiSourceFunctionalColumn<D> copy() {
return new MultiSourceFunctionalColumn<>(sourceNames, destName, destDataType, componentType, function, alwaysEvaluate);
return new MultiSourceFunctionalColumn<>(sourceNames, destName, destDataType, componentType, function,
alwaysEvaluate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ default boolean hasVirtualRowVariables() {

/**
* Should we ignore modified column sets, and always re-evaluate this column?
*
* @return true if this column should be evaluated on every row modification
*/
boolean alwaysEvaluate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.engine.table.impl.select;

/**
* This is a base class for SelectColumn implementations that do not support {@link SelectColumn#alwaysEvaluate()}.
*
* <p>These columns always return false for {@link #alwaysEvaluate()} and {@link #alwaysEvaluateCopy()} calls {@link #copy()}.</p>
* <p>
* These columns always return false for {@link #alwaysEvaluate()} and {@link #alwaysEvaluateCopy()} calls
* {@link #copy()}.
* </p>
*/
public abstract class SelectColumnWithoutAlwaysEvaluate implements SelectColumn {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public boolean isStateless() {
public SourceColumn copy() {
return new SourceColumn(sourceName, destName);
}

@Override
public boolean alwaysEvaluate() {
return alwaysEvaluate;
Expand All @@ -189,4 +189,4 @@ public boolean alwaysEvaluate() {
public SelectColumn alwaysEvaluateCopy() {
return new SourceColumn(sourceName, destName, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public SwitchColumn(String columnName, String expression, FormulaParserConfigura
}

private SwitchColumn(final String columnName,
final String expression,
final FormulaParserConfiguration parserConfiguration,
final boolean alwaysEvaluate) {
final String expression,
final FormulaParserConfiguration parserConfiguration,
final boolean alwaysEvaluate) {
this.expression = Require.neqNull(expression, "expression");
this.columnName = NameValidator.validateColumnName(columnName);
this.parser = parserConfiguration;
Expand Down Expand Up @@ -175,4 +175,4 @@ public boolean alwaysEvaluate() {
public SelectColumn alwaysEvaluateCopy() {
return new SwitchColumn(columnName, expression, parser, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class ConstantColumnLayer extends SelectOrViewColumnLayer {
final ModifiedColumnSet mcsBuilder) {
super(context, sc, ws, null, deps, mcsBuilder);
if (sc.alwaysEvaluate()) {
throw new IllegalArgumentException("SelectColumn may not have alwaysEvaluate set for a constant column: " + sc);
throw new IllegalArgumentException(
"SelectColumn may not have alwaysEvaluate set for a constant column: " + sc);
}
initialize(ws);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1308,42 +1308,51 @@ public void testAlwaysUpdate() {
final MutableInt count2 = new MutableInt(0);
QueryScope.addParam("__COUNT1", count);
QueryScope.addParam("__COUNT2", count2);
final QueryTable base = testRefreshingTable(intCol("Sentinel", 1,2,3,4,5,6,7,8,9),
final QueryTable base = testRefreshingTable(intCol("Sentinel", 1, 2, 3, 4, 5, 6, 7, 8, 9),
stringCol("Thing", "A", "B", "C", "D", "E", "F", "G", "H", "I"));

final SelectColumn sc1 = SelectColumnFactory.getExpression("NormalCount=__COUNT1.getAndIncrement()");
final SelectColumn sc2 = SelectColumnFactory.getExpression("AlwaysCount=__COUNT2.getAndIncrement()").alwaysEvaluateCopy();
final SelectColumn sc2 =
SelectColumnFactory.getExpression("AlwaysCount=__COUNT2.getAndIncrement()").alwaysEvaluateCopy();

final Table withUpdates = base.update(Arrays.asList(sc1, sc2));

final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast();

assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}, ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}, ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8},
ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8},
ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());

updateGraph.runWithinUnitTestCycle(() -> {
addToTable(base, i(9), intCol("Sentinel", 10), stringCol("Thing", "J"));
base.notifyListeners(i(9), i(), i());
});

assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());

updateGraph.runWithinUnitTestCycle(() -> {
addToTable(base, i(0, 2, 4), intCol("Sentinel", 1, 3 ,5), stringCol("Thing", "a", "c", "e"));
base.notifyListeners(i(), i(), i(0,2,4));
addToTable(base, i(0, 2, 4), intCol("Sentinel", 1, 3, 5), stringCol("Thing", "a", "c", "e"));
base.notifyListeners(i(), i(), i(0, 2, 4));
});

assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] { 10, 1, 11, 3, 12, 5, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] {10, 1, 11, 3, 12, 5, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());

updateGraph.runWithinUnitTestCycle(() -> {
removeRows(base, i(5));
base.notifyListeners(i(), i(5), i());
});

assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] { 10, 1, 11, 3, 12, 6, 7, 8, 9}, ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());
assertArrayEquals(new int[] {0, 1, 2, 3, 4, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "NormalCount").toArray());
assertArrayEquals(new int[] {10, 1, 11, 3, 12, 6, 7, 8, 9},
ColumnVectors.ofInt(withUpdates, "AlwaysCount").toArray());
}

@Test
Expand All @@ -1352,48 +1361,57 @@ public void testAlwaysUpdateMCS() {
QueryScope.addParam("a", a);
final AtomicInteger b = new AtomicInteger(200);
QueryScope.addParam("b", b);
final QueryTable base = testRefreshingTable(RowSetFactory.fromKeys(10, 11).toTracking(), intCol("Sentinel", 1, 2), intCol("B",10, 11));
final QueryTable base = testRefreshingTable(RowSetFactory.fromKeys(10, 11).toTracking(),
intCol("Sentinel", 1, 2), intCol("B", 10, 11));

final SelectColumn x = SelectColumnFactory.getExpression("X = a.getAndIncrement()").alwaysEvaluateCopy();

final Table withUpdates = base.update(Arrays.asList(x, SelectColumnFactory.getExpression("Y=1"), SelectColumnFactory.getExpression("Z=B+b.getAndIncrement()")));
final Table withUpdates = base.update(Arrays.asList(x, SelectColumnFactory.getExpression("Y=1"),
SelectColumnFactory.getExpression("Z=B+b.getAndIncrement()")));

final PrintListener pl = new PrintListener("withUpdates", withUpdates, 10);

final SimpleListener simpleListener = new SimpleListener(withUpdates);
withUpdates.addUpdateListener(simpleListener);

assertTableEquals(TableTools.newTable(intCol("Sentinel", 1, 2), intCol("B", 10, 11), intCol("X", 100, 101), intCol("Y", 1, 1), intCol("Z", 210, 212)), withUpdates);
assertTableEquals(TableTools.newTable(intCol("Sentinel", 1, 2), intCol("B", 10, 11), intCol("X", 100, 101),
intCol("Y", 1, 1), intCol("Z", 210, 212)), withUpdates);

final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast();

updateGraph.runWithinUnitTestCycle(() -> {
addToTable(base, i(10), intCol("Sentinel", 3), intCol("B", 10));
base.notifyListeners(new TableUpdateImpl(i(), i(), i(10), RowSetShiftData.EMPTY, base.newModifiedColumnSet("Sentinel")));
base.notifyListeners(
new TableUpdateImpl(i(), i(), i(10), RowSetShiftData.EMPTY, base.newModifiedColumnSet("Sentinel")));
});

assertTableEquals(TableTools.newTable(intCol("Sentinel", 3, 2), intCol("B", 10, 11), intCol("X", 102, 101), intCol("Y", 1, 1), intCol("Z", 210, 212)), withUpdates);
assertTableEquals(TableTools.newTable(intCol("Sentinel", 3, 2), intCol("B", 10, 11), intCol("X", 102, 101),
intCol("Y", 1, 1), intCol("Z", 210, 212)), withUpdates);

assertEquals(1, simpleListener.count);
assertEquals(i(), simpleListener.update.added());
assertEquals(i(), simpleListener.update.removed());
assertEquals(i(10), simpleListener.update.modified());
assertEquals(((QueryTable) withUpdates).newModifiedColumnSet("Sentinel", "X"), simpleListener.update.modifiedColumnSet());
assertEquals(((QueryTable) withUpdates).newModifiedColumnSet("Sentinel", "X"),
simpleListener.update.modifiedColumnSet());

updateGraph.runWithinUnitTestCycle(() -> {
addToTable(base, i(11), intCol("Sentinel", 4), intCol("B", 12));
base.notifyListeners(new TableUpdateImpl(i(), i(), i(11), RowSetShiftData.EMPTY, base.newModifiedColumnSet("Sentinel", "B")));
base.notifyListeners(new TableUpdateImpl(i(), i(), i(11), RowSetShiftData.EMPTY,
base.newModifiedColumnSet("Sentinel", "B")));
});

assertTableEquals(TableTools.newTable(intCol("Sentinel", 3, 4), intCol("B", 10, 12), intCol("X", 102, 103), intCol("Y", 1, 1), intCol("Z", 210, 214)), withUpdates);
assertTableEquals(TableTools.newTable(intCol("Sentinel", 3, 4), intCol("B", 10, 12), intCol("X", 102, 103),
intCol("Y", 1, 1), intCol("Z", 210, 214)), withUpdates);

assertEquals(2, simpleListener.count);
assertEquals(i(), simpleListener.update.added());
assertEquals(i(), simpleListener.update.removed());
assertEquals(i(11), simpleListener.update.modified());
assertEquals(((QueryTable) withUpdates).newModifiedColumnSet("Sentinel", "B", "X", "Z"), simpleListener.update.modifiedColumnSet());
assertEquals(((QueryTable) withUpdates).newModifiedColumnSet("Sentinel", "B", "X", "Z"),
simpleListener.update.modifiedColumnSet());

QueryScope.addParam("a", null);
QueryScope.addParam("b", null);
}
}
}

0 comments on commit d8a2f5f

Please sign in to comment.