Skip to content

Commit

Permalink
Fix for NPE on first update cycle when using (Sorted|Unsorted)ClockFi…
Browse files Browse the repository at this point in the history
…lter on an empty Table (#5474)
  • Loading branch information
cpwright authored and stanbrub committed May 17, 2024
1 parent 4554c4b commit f33000c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected WritableRowSet initializeAndGetInitialIndex(@NotNull final RowSet sele
@Override
@Nullable
protected WritableRowSet updateAndGetAddedIndex() {
if (range.isEmpty()) {
if (range == null || range.isEmpty()) {
return null;
}
final RowSetBuilderRandom addedBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected WritableRowSet initializeAndGetInitialIndex(@NotNull final RowSet sele
@Override
@Nullable
protected WritableRowSet updateAndGetAddedIndex() {
if (rangesByNextTime.isEmpty()) {
if (rangesByNextTime == null || rangesByNextTime.isEmpty()) {
return null;
}
final long nowNanos = clock.currentTimeNanos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import io.deephaven.engine.table.impl.DataAccessHelpers;
import io.deephaven.engine.testutil.junit4.EngineCleanup;

import static io.deephaven.engine.util.TableTools.col;
import static io.deephaven.engine.util.TableTools.intCol;
import static io.deephaven.engine.util.TableTools.merge;
import static io.deephaven.engine.util.TableTools.newTable;
import static io.deephaven.engine.util.TableTools.*;
import static io.deephaven.time.DateTimeUtils.epochNanosToInstant;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import io.deephaven.engine.testutil.StepClock;
import io.deephaven.engine.util.TableTools;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -194,4 +193,38 @@ public void testUnsorted3() {
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());
}

@Test
public void testInitiallyEmptyUnsorted() {
clock.reset();
final UnsortedClockFilter filter = new UnsortedClockFilter("Timestamp", clock, true);

final Table testEmpty = TableTools.newTable(instantCol("Timestamp"), intCol("Int"));

final Table result = testEmpty.where(filter);

final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast();
updateGraph.runWithinUnitTestCycle(() -> {
clock.run();
filter.run();
});
assertEquals(0, result.size());
}

@Test
public void testInitiallyEmptySorted() {
clock.reset();
final UnsortedClockFilter filter = new UnsortedClockFilter("Timestamp", clock, true);

final Table testEmpty = TableTools.newTable(instantCol("Timestamp"), intCol("Int"));

final Table result = testEmpty.where(filter);

final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast();
updateGraph.runWithinUnitTestCycle(() -> {
clock.run();
filter.run();
});
assertEquals(0, result.size());
}
}

0 comments on commit f33000c

Please sign in to comment.