>From Manish Thakur <[email protected]>: Manish Thakur has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22027?usp=email )
Change subject: [ASTERIXDB-3944][STO] Fix min/max of double column filters ...................................................................... [ASTERIXDB-3944][STO] Fix min/max of double column filters - user model changes: no - storage format changes: no - interface changes: no Details: The filter's min and max started at Double.MIN_VALUE, the smallest positive double, and Double.MAX_VALUE, so stored ranges were too wide and double columns were never pruned. A NaN made Math.min and Math.max return NaN for both bounds, and the comparators, which used Java's < and >, then skipped that mega leaf node for every predicate, dropping its rows from results. Order doubles the way SQL++ compares them: NaN above +INF, -0.0 equal to 0.0. Ext-ref: MB-74478,MB-74479 Generated-by: Claude Opus 5.5 <[email protected]> Change-Id: I54d725ebb7a8dcae57d4aac6de3594f8188609c8 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.001.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.002.update.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.003.get.http A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.004.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.005.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.003.regexadm A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.004.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.005.adm M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/AbstractColumnFilterComparatorFactory.java M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GEColumnFilterEvaluatorFactory.java M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GTColumnFilterEvaluatorFactory.java M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LEColumnFilterEvaluatorFactory.java M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LTColumnFilterEvaluatorFactory.java M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java A asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/filter/NumericFilterTest.java 17 files changed, 401 insertions(+), 12 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/27/22027/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.001.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.001.ddl.sqlpp new file mode 100644 index 0000000..3e9873a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.001.ddl.sqlpp @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +DROP DATAVERSE test IF EXISTS; +CREATE DATAVERSE test; + +USE test; + +CREATE TYPE t1 AS OPEN { + id : bigint +}; + +CREATE DATASET ds(t1) PRIMARY KEY id WITH { + "storage-format": {"format" : "column"} +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.002.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.002.update.sqlpp new file mode 100644 index 0000000..0fa4343 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.002.update.sqlpp @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +USE test; + +-- Only disk components are range filtered, so 003 flushes these before they are queried +INSERT INTO ds ([ + {"id": 0, "c_double": double(-3.0)}, + {"id": 1, "c_double": double(1.0)}, + {"id": 2, "c_double": double("NaN")}, + {"id": 3, "c_double": double(7.0)}, + {"id": 4, "c_double": double("INF")}, + {"id": 5, "c_double": double(2.5)} +]); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.003.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.003.get.http new file mode 100644 index 0000000..de9d951 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.003.get.http @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/connector?dataverseName=test&datasetName=ds \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.004.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.004.query.sqlpp new file mode 100644 index 0000000..e4de7b26 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.004.query.sqlpp @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +USE test; + +SELECT VALUE c_double +FROM ds +WHERE c_double > double(5) ORDER BY c_double; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.005.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.005.query.sqlpp new file mode 100644 index 0000000..1e1d131 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double-nan/double-nan.005.query.sqlpp @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +USE test; + +SELECT VALUE c_double +FROM ds +WHERE c_double < double("NaN") ORDER BY c_double; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.003.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.003.regexadm new file mode 100644 index 0000000..52c0081 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.003.regexadm @@ -0,0 +1 @@ +\Q{"keys":"id","type":{"type":"org.apache.asterix.om.types.ARecordType","name":"t1","open":true,"fields":[{"id":{"type":"AInt64"}}]},"splits":[\E.*\Q]}\E \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.004.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.004.adm new file mode 100644 index 0000000..6b49692 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.004.adm @@ -0,0 +1,3 @@ +7.0 +INF +NaN \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.005.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.005.adm new file mode 100644 index 0000000..f3d3347 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double-nan/double-nan.005.adm @@ -0,0 +1,5 @@ +-3.0 +1.0 +2.5 +7.0 +INF \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml index cd1fea5..70c78de 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -16974,6 +16974,11 @@ </compilation-unit> </test-case> <test-case FilePath="column"> + <compilation-unit name="filter/double-nan"> + <output-dir compare="Text">filter/double-nan</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="column"> <compilation-unit name="filter/return-array"> <output-dir compare="Text">filter/return-array</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml index 16a836c..e625f4b 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml @@ -135,6 +135,11 @@ </compilation-unit> </test-case> <test-case FilePath="column"> + <compilation-unit name="filter/double-nan"> + <output-dir compare="Text">filter/double-nan</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="column"> <compilation-unit name="filter/return-array"> <output-dir compare="Text">filter/return-array</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/AbstractColumnFilterComparatorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/AbstractColumnFilterComparatorFactory.java index e0d927e..9322211 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/AbstractColumnFilterComparatorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/AbstractColumnFilterComparatorFactory.java @@ -26,6 +26,7 @@ import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessor; import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessorFactory; import org.apache.asterix.column.filter.range.accessor.NoOpColumnRangeFilterValueAccessor; +import org.apache.asterix.dataflow.data.nontagged.comparators.ComparatorUtil; import org.apache.asterix.om.types.ATypeTag; import org.apache.asterix.om.types.hierachy.ATypeHierarchy; import org.apache.hyracks.api.exceptions.HyracksDataException; @@ -92,5 +93,14 @@ this.left = left; this.right = right; } + + /** + * Compares in the order SQL++ predicates compare doubles (NaN above +INF, -0.0 equal to 0.0), so a mega + * leaf node that the predicate could match is never skipped + */ + protected final int compareDoubles() { + return ComparatorUtil.compareDoubles(Double.longBitsToDouble(left.getNormalizedValue()), + Double.longBitsToDouble(right.getNormalizedValue())); + } } } diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GEColumnFilterEvaluatorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GEColumnFilterEvaluatorFactory.java index e61e7db..672605f 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GEColumnFilterEvaluatorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GEColumnFilterEvaluatorFactory.java @@ -38,8 +38,7 @@ @Override public boolean evaluate() { if (left.getTypeTag() == ATypeTag.DOUBLE) { - return Double.longBitsToDouble(left.getNormalizedValue()) >= Double - .longBitsToDouble(right.getNormalizedValue()); + return compareDoubles() >= 0; } return left.getNormalizedValue() >= right.getNormalizedValue(); } diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GTColumnFilterEvaluatorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GTColumnFilterEvaluatorFactory.java index 2115d81..1919a71 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GTColumnFilterEvaluatorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/GTColumnFilterEvaluatorFactory.java @@ -38,8 +38,7 @@ @Override public boolean evaluate() { if (left.getTypeTag() == ATypeTag.DOUBLE) { - return Double.longBitsToDouble(left.getNormalizedValue()) > Double - .longBitsToDouble(right.getNormalizedValue()); + return compareDoubles() > 0; } return left.getNormalizedValue() > right.getNormalizedValue(); } diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LEColumnFilterEvaluatorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LEColumnFilterEvaluatorFactory.java index 99e1a39..4bf2cae 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LEColumnFilterEvaluatorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LEColumnFilterEvaluatorFactory.java @@ -38,8 +38,7 @@ @Override public boolean evaluate() { if (left.getTypeTag() == ATypeTag.DOUBLE) { - return Double.longBitsToDouble(left.getNormalizedValue()) <= Double - .longBitsToDouble(right.getNormalizedValue()); + return compareDoubles() <= 0; } return left.getNormalizedValue() <= right.getNormalizedValue(); } diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LTColumnFilterEvaluatorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LTColumnFilterEvaluatorFactory.java index 429be80..f6a5684 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LTColumnFilterEvaluatorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/compartor/LTColumnFilterEvaluatorFactory.java @@ -38,8 +38,7 @@ @Override public boolean evaluate() { if (left.getTypeTag() == ATypeTag.DOUBLE) { - return Double.longBitsToDouble(left.getNormalizedValue()) < Double - .longBitsToDouble(right.getNormalizedValue()); + return compareDoubles() < 0; } return left.getNormalizedValue() < right.getNormalizedValue(); } diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java index 6fccabe..d51fd8f 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java @@ -18,6 +18,8 @@ */ package org.apache.asterix.column.values.writer.filters; +import org.apache.asterix.dataflow.data.nontagged.comparators.ComparatorUtil; + public class DoubleColumnFilterWriter extends AbstractColumnFilterWriter { private double min; private double max; @@ -28,8 +30,14 @@ @Override public void addDouble(double value) { - min = Math.min(min, value); - max = Math.max(max, value); + // Math.min and Math.max return NaN once any value is NaN, and the range filter would then skip this mega + // leaf node for every predicate. In SQL++ order NaN is above +INF, so it is the max and leaves the min alone. + if (ComparatorUtil.compareDoubles(value, min) < 0) { + min = value; + } + if (ComparatorUtil.compareDoubles(value, max) > 0) { + max = value; + } } @Override @@ -44,7 +52,7 @@ @Override public void reset() { - min = Double.MIN_VALUE; - max = Double.MAX_VALUE; + min = Double.POSITIVE_INFINITY; + max = Double.NEGATIVE_INFINITY; } } diff --git a/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/filter/NumericFilterTest.java b/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/filter/NumericFilterTest.java new file mode 100644 index 0000000..6dc7498 --- /dev/null +++ b/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/filter/NumericFilterTest.java @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.asterix.column.test.filter; + +import org.apache.asterix.column.filter.range.IColumnRangeFilterEvaluatorFactory; +import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessorFactory; +import org.apache.asterix.column.filter.range.accessor.ColumnRangeFilterValueAccessor; +import org.apache.asterix.column.filter.range.accessor.ConstantColumnRangeFilterValueAccessorFactory; +import org.apache.asterix.column.filter.range.compartor.GEColumnFilterEvaluatorFactory; +import org.apache.asterix.column.filter.range.compartor.GTColumnFilterEvaluatorFactory; +import org.apache.asterix.column.filter.range.compartor.LEColumnFilterEvaluatorFactory; +import org.apache.asterix.column.filter.range.compartor.LTColumnFilterEvaluatorFactory; +import org.apache.asterix.column.filter.range.evaluator.ANDColumnFilterEvaluatorFactory; +import org.apache.asterix.column.values.writer.filters.AbstractColumnFilterWriter; +import org.apache.asterix.column.values.writer.filters.DoubleColumnFilterWriter; +import org.apache.asterix.column.values.writer.filters.LongColumnFilterWriter; +import org.apache.asterix.om.base.ADouble; +import org.apache.asterix.om.base.AInt64; +import org.apache.asterix.om.base.IAObject; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.junit.Assert; +import org.junit.Test; + +/** + * A range filter that is too wide never produces a wrong answer, it only stops mega leaf nodes from being skipped, + * so query tests cannot detect it. These tests check the stored bounds and the skip decision directly, against the + * order SQL++ compares doubles in: NaN above +INF, and -0.0 equal to 0.0. The comparator for each predicate is the + * one {@code ColumnRangeFilterBuilder} creates for it. + */ +public class NumericFilterTest { + + @Test + public void testDoubleMinMax() { + assertDoubleBounds(100.0, 200.0, 100.0, 150.0, 200.0); + assertDoubleBounds(-50.0, -10.0, -50.0, -30.0, -10.0); + assertDoubleBounds(-0.5, 0.5, 0.5, -0.5, 0.0); + assertDoubleBounds(7.25, 7.25, 7.25); + } + + @Test + public void testDoubleMinMaxAfterReset() { + DoubleColumnFilterWriter writer = doubleLeaf(100.0, 200.0); + writer.reset(); + writer.addDouble(-50.0); + writer.addDouble(-10.0); + assertDoubleBounds(writer, -50.0, -10.0); + } + + @Test + public void testLongMinMax() { + assertLongBounds(100, 200, 100, 150, 200); + assertLongBounds(-50, -10, -50, -30, -10); + assertLongBounds(7, 7, 7); + } + + @Test + public void testDoubleLeafSkipping() throws HyracksDataException { + DoubleColumnFilterWriter leaf = doubleLeaf(100.0, 150.0, 200.0); + + Assert.assertFalse("x > 500", isRead(gt(new ADouble(500.0), leaf))); + Assert.assertFalse("x >= 500", isRead(ge(new ADouble(500.0), leaf))); + Assert.assertFalse("x < 50", isRead(lt(new ADouble(50.0), leaf))); + Assert.assertFalse("x <= 50", isRead(le(new ADouble(50.0), leaf))); + Assert.assertFalse("x = 300", isRead(eq(new ADouble(300.0), leaf))); + Assert.assertFalse("x = 50", isRead(eq(new ADouble(50.0), leaf))); + + Assert.assertTrue("x > 150", isRead(gt(new ADouble(150.0), leaf))); + Assert.assertTrue("x >= 200", isRead(ge(new ADouble(200.0), leaf))); + Assert.assertTrue("x < 150", isRead(lt(new ADouble(150.0), leaf))); + Assert.assertTrue("x <= 100", isRead(le(new ADouble(100.0), leaf))); + Assert.assertTrue("x = 150", isRead(eq(new ADouble(150.0), leaf))); + } + + @Test + public void testDoubleMinMaxWithNaN() { + assertDoubleBounds(5.0, Double.NaN, 5.0, Double.NaN, 7.0); + assertDoubleBounds(-0.5, Double.NaN, Double.NaN, -0.5); + } + + @Test + public void testDoubleLeafWithNaNSkipping() throws HyracksDataException { + DoubleColumnFilterWriter leaf = doubleLeaf(5.0, Double.NaN, 7.0); + + Assert.assertTrue("x > 100", isRead(gt(new ADouble(100.0), leaf))); + Assert.assertTrue("x > INF", isRead(gt(new ADouble(Double.POSITIVE_INFINITY), leaf))); + Assert.assertTrue("x >= NaN", isRead(ge(new ADouble(Double.NaN), leaf))); + Assert.assertTrue("x = NaN", isRead(eq(new ADouble(Double.NaN), leaf))); + Assert.assertTrue("x < 6", isRead(lt(new ADouble(6.0), leaf))); + + Assert.assertFalse("x < 5", isRead(lt(new ADouble(5.0), leaf))); + Assert.assertFalse("x = 3", isRead(eq(new ADouble(3.0), leaf))); + } + + @Test + public void testDoubleNaNConstantSkipping() throws HyracksDataException { + DoubleColumnFilterWriter leaf = doubleLeaf(100.0, 150.0, 200.0); + + Assert.assertTrue("x < NaN", isRead(lt(new ADouble(Double.NaN), leaf))); + Assert.assertTrue("x <= NaN", isRead(le(new ADouble(Double.NaN), leaf))); + + Assert.assertFalse("x > NaN", isRead(gt(new ADouble(Double.NaN), leaf))); + Assert.assertFalse("x >= NaN", isRead(ge(new ADouble(Double.NaN), leaf))); + Assert.assertFalse("x = NaN", isRead(eq(new ADouble(Double.NaN), leaf))); + } + + @Test + public void testDoubleSignedZeroSkipping() throws HyracksDataException { + DoubleColumnFilterWriter leaf = doubleLeaf(0.0); + + Assert.assertTrue("x = -0.0", isRead(eq(new ADouble(-0.0), leaf))); + Assert.assertTrue("x <= -0.0", isRead(le(new ADouble(-0.0), leaf))); + Assert.assertTrue("x >= -0.0", isRead(ge(new ADouble(-0.0), leaf))); + + Assert.assertFalse("x < -0.0", isRead(lt(new ADouble(-0.0), leaf))); + Assert.assertFalse("x > -0.0", isRead(gt(new ADouble(-0.0), leaf))); + } + + @Test + public void testLongLeafSkipping() throws HyracksDataException { + LongColumnFilterWriter leaf = longLeaf(100, 150, 200); + + Assert.assertFalse("x > 500", isRead(gt(new AInt64(500), leaf))); + Assert.assertFalse("x < 50", isRead(lt(new AInt64(50), leaf))); + Assert.assertFalse("x = 300", isRead(eq(new AInt64(300), leaf))); + + Assert.assertTrue("x > 150", isRead(gt(new AInt64(150), leaf))); + Assert.assertTrue("x < 150", isRead(lt(new AInt64(150), leaf))); + Assert.assertTrue("x = 150", isRead(eq(new AInt64(150), leaf))); + } + + private static DoubleColumnFilterWriter doubleLeaf(double... values) { + DoubleColumnFilterWriter writer = new DoubleColumnFilterWriter(); + for (double value : values) { + writer.addDouble(value); + } + return writer; + } + + private static LongColumnFilterWriter longLeaf(long... values) { + LongColumnFilterWriter writer = new LongColumnFilterWriter(); + for (long value : values) { + writer.addLong(value); + } + return writer; + } + + private static void assertDoubleBounds(double expectedMin, double expectedMax, double... values) { + assertDoubleBounds(doubleLeaf(values), expectedMin, expectedMax); + } + + private static void assertDoubleBounds(DoubleColumnFilterWriter writer, double expectedMin, double expectedMax) { + Assert.assertEquals(expectedMin, Double.longBitsToDouble(writer.getMinNormalizedValue()), 0.0); + Assert.assertEquals(expectedMax, Double.longBitsToDouble(writer.getMaxNormalizedValue()), 0.0); + } + + private static void assertLongBounds(long expectedMin, long expectedMax, long... values) { + LongColumnFilterWriter writer = longLeaf(values); + Assert.assertEquals(expectedMin, writer.getMinNormalizedValue()); + Assert.assertEquals(expectedMax, writer.getMaxNormalizedValue()); + } + + // x < c + private static IColumnRangeFilterEvaluatorFactory lt(IAObject c, AbstractColumnFilterWriter leaf) { + return new GTColumnFilterEvaluatorFactory(constant(c), min(c, leaf)); + } + + // x <= c + private static IColumnRangeFilterEvaluatorFactory le(IAObject c, AbstractColumnFilterWriter leaf) { + return new GEColumnFilterEvaluatorFactory(constant(c), min(c, leaf)); + } + + // x > c + private static IColumnRangeFilterEvaluatorFactory gt(IAObject c, AbstractColumnFilterWriter leaf) { + return new LTColumnFilterEvaluatorFactory(constant(c), max(c, leaf)); + } + + // x >= c + private static IColumnRangeFilterEvaluatorFactory ge(IAObject c, AbstractColumnFilterWriter leaf) { + return new LEColumnFilterEvaluatorFactory(constant(c), max(c, leaf)); + } + + // x = c + private static IColumnRangeFilterEvaluatorFactory eq(IAObject c, AbstractColumnFilterWriter leaf) { + return new ANDColumnFilterEvaluatorFactory(new GEColumnFilterEvaluatorFactory(constant(c), min(c, leaf)), + new LEColumnFilterEvaluatorFactory(constant(c), max(c, leaf))); + } + + private static IColumnRangeFilterValueAccessorFactory constant(IAObject c) { + return ConstantColumnRangeFilterValueAccessorFactory.createFactory(c); + } + + private static IColumnRangeFilterValueAccessorFactory min(IAObject c, AbstractColumnFilterWriter leaf) { + return bound(c.getType().getTypeTag(), true, leaf.getMinNormalizedValue()); + } + + private static IColumnRangeFilterValueAccessorFactory max(IAObject c, AbstractColumnFilterWriter leaf) { + return bound(c.getType().getTypeTag(), false, leaf.getMaxNormalizedValue()); + } + + private static IColumnRangeFilterValueAccessorFactory bound(ATypeTag typeTag, boolean min, long normalized) { + return provider -> { + ColumnRangeFilterValueAccessor accessor = new ColumnRangeFilterValueAccessor(0, typeTag, min); + accessor.setNormalizedValue(normalized); + return accessor; + }; + } + + private static boolean isRead(IColumnRangeFilterEvaluatorFactory filter) throws HyracksDataException { + return filter.create(null).evaluate(); + } +} -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22027?usp=email To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: asterixdb Gerrit-Branch: helios Gerrit-Change-Id: I54d725ebb7a8dcae57d4aac6de3594f8188609c8 Gerrit-Change-Number: 22027 Gerrit-PatchSet: 1 Gerrit-Owner: Manish Thakur <[email protected]>
