From 3d211fc40eae324c71e1b84ee2aa9ff116833435 Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Mon, 24 Jun 2024 12:42:52 -0600 Subject: [PATCH] Make ZonedDateTimeRangeFilter compare ZoneDateTimes --- .../engine/table/impl/select/RangeFilter.java | 18 +-- .../impl/select/ZonedDateTimeRangeFilter.java | 109 ------------------ 2 files changed, 1 insertion(+), 126 deletions(-) delete mode 100644 engine/table/src/main/java/io/deephaven/engine/table/impl/select/ZonedDateTimeRangeFilter.java diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/RangeFilter.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/select/RangeFilter.java index b09424506be..1b20fef7222 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/RangeFilter.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/select/RangeFilter.java @@ -235,8 +235,7 @@ public void init( } else if (colClass == LocalDateTime.class) { filter = makeComparableRangeFilter(columnName, condition, (LocalDateTime) realValue.getValue()); } else if (colClass == ZonedDateTime.class) { - filter = makeZonedDateTimeRangeFilter(columnName, condition, - DateTimeUtils.epochNanos((ZonedDateTime) realValue.getValue())); + filter = makeComparableRangeFilter(columnName, condition, (ZonedDateTime) realValue.getValue()); } else if (BigDecimal.class.isAssignableFrom(colClass)) { filter = makeComparableRangeFilter(columnName, condition, (BigDecimal) realValue.getValue()); } else if (BigInteger.class.isAssignableFrom(colClass)) { @@ -279,21 +278,6 @@ private static LongRangeFilter makeInstantRangeFilter(String columnName, Conditi } } - private static LongRangeFilter makeZonedDateTimeRangeFilter(String columnName, Condition condition, long value) { - switch (condition) { - case LESS_THAN: - return new ZonedDateTimeRangeFilter(columnName, value, Long.MIN_VALUE, true, false); - case LESS_THAN_OR_EQUAL: - return new ZonedDateTimeRangeFilter(columnName, value, Long.MIN_VALUE, true, true); - case GREATER_THAN: - return new ZonedDateTimeRangeFilter(columnName, value, Long.MAX_VALUE, false, true); - case GREATER_THAN_OR_EQUAL: - return new ZonedDateTimeRangeFilter(columnName, value, Long.MAX_VALUE, true, true); - default: - throw new IllegalArgumentException("RangeFilter does not support condition " + condition); - } - } - private static SingleSidedComparableRangeFilter makeComparableRangeFilter(String columnName, Condition condition, Comparable comparable) { switch (condition) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/ZonedDateTimeRangeFilter.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/select/ZonedDateTimeRangeFilter.java deleted file mode 100644 index ac44e7b8504..00000000000 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/ZonedDateTimeRangeFilter.java +++ /dev/null @@ -1,109 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl.select; - -import io.deephaven.base.verify.Assert; -import io.deephaven.engine.table.ColumnDefinition; -import io.deephaven.engine.table.TableDefinition; -import io.deephaven.engine.table.impl.chunkfilter.ChunkFilter; -import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeys; -import io.deephaven.engine.table.ColumnSource; -import io.deephaven.engine.table.impl.sources.ReinterpretUtils; -import io.deephaven.chunk.*; -import io.deephaven.chunk.attributes.Values; -import io.deephaven.engine.rowset.WritableRowSet; -import io.deephaven.engine.rowset.RowSet; -import io.deephaven.time.DateTimeUtils; -import org.jetbrains.annotations.NotNull; - -import java.time.ZonedDateTime; - -public class ZonedDateTimeRangeFilter extends LongRangeFilter { - - public ZonedDateTimeRangeFilter(String columnName, ZonedDateTime val1, ZonedDateTime val2) { - super(columnName, DateTimeUtils.epochNanos(val1), DateTimeUtils.epochNanos(val2), true, true); - } - - public ZonedDateTimeRangeFilter( - String columnName, ZonedDateTime val1, ZonedDateTime val2, boolean lowerInclusive, boolean upperInclusive) { - super(columnName, DateTimeUtils.epochNanos(val1), DateTimeUtils.epochNanos(val2), - lowerInclusive, upperInclusive); - } - - public ZonedDateTimeRangeFilter( - String columnName, long val1, long val2, boolean lowerInclusive, boolean upperInclusive) { - super(columnName, val1, val2, lowerInclusive, upperInclusive); - } - - @Override - public void init(@NotNull final TableDefinition tableDefinition) { - if (chunkFilter != null) { - return; - } - - final ColumnDefinition def = tableDefinition.getColumn(columnName); - if (def == null) { - throw new RuntimeException("Column \"" + columnName + "\" doesn't exist in this table, available columns: " - + tableDefinition.getColumnNames()); - } - - final Class colClass = def.getDataType(); - Assert.eq(colClass, "colClass", ZonedDateTime.class); - - longFilter = super.initChunkFilter(); - chunkFilter = new ZonedDateTimeLongChunkFilterAdapter(); - } - - @Override - public ZonedDateTimeRangeFilter copy() { - final ZonedDateTimeRangeFilter copy = - new ZonedDateTimeRangeFilter(columnName, lower, upper, lowerInclusive, upperInclusive); - copy.chunkFilter = chunkFilter; - copy.longFilter = longFilter; - return copy; - } - - @Override - public String toString() { - return "ZonedDateTimeRangeFilter(" + columnName + " in " - + (lowerInclusive ? "[" : "(") - + DateTimeUtils.epochNanosToInstant(lower) + "," + DateTimeUtils.epochNanosToInstant(upper) - + (upperInclusive ? "]" : ")") + ")"; - } - - @NotNull - @Override - WritableRowSet binarySearch( - @NotNull final RowSet selection, - @NotNull final ColumnSource columnSource, - final boolean usePrev, - final boolean reverse) { - if (selection.isEmpty()) { - return selection.copy(); - } - - // noinspection unchecked - final ColumnSource zdtColumnSource = - ReinterpretUtils.zonedDateTimeToLongSource((ColumnSource) columnSource); - return super.binarySearch(selection, zdtColumnSource, usePrev, reverse); - } - - private class ZonedDateTimeLongChunkFilterAdapter implements ChunkFilter { - @Override - public void filter(Chunk values, LongChunk keys, - WritableLongChunk results) { - try (final WritableLongChunk writableLongChunk = - WritableLongChunk.makeWritableChunk(values.size())) { - - final ObjectChunk objectValues = values.asObjectChunk(); - for (int ii = 0; ii < values.size(); ++ii) { - final ZonedDateTime zdt = objectValues.get(ii); - writableLongChunk.set(ii, DateTimeUtils.epochNanos(zdt)); - } - writableLongChunk.setSize(values.size()); - longFilter.filter(writableLongChunk, keys, results); - } - } - } -}