>From <[email protected]>: [email protected] has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19636 )
Change subject: [ASTERIXDB-3596][STO] Fix double comparison in range filters ...................................................................... [ASTERIXDB-3596][STO] Fix double comparison in range filters Details: Ensures all double values are normalized properly before applying range filters. Ext-ref: MB-66208 Change-Id: I702c4e1ef6c46e532cf64a874ec6a81bea3ebaad --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.003.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double/double.003.adm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.002.update.sqlpp M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/values/writer/filters/DoubleColumnFilterWriter.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.001.ddl.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_single_partition_sqlpp.xml 8 files changed, 185 insertions(+), 3 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/36/19636/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.001.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.001.ddl.sqlpp new file mode 100644 index 0000000..de03881 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.001.ddl.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. + */ + +DROP DATAVERSE test IF EXISTS; +CREATE DATAVERSE test; + +USE test; + +CREATE DATASET dsUntyped PRIMARY KEY (id:string) +WITH { + "storage-format": { + "format": "column" + } +}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.002.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.002.update.sqlpp new file mode 100644 index 0000000..0277980 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.002.update.sqlpp @@ -0,0 +1,86 @@ +/* + * 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; + +INSERT INTO dsUntyped ( { 'id': "dsUntyped:0", 'c_double':double(-3.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:1", 'c_double':double(-3.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:2", 'c_double':double(-3.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:3", 'c_double':double(-3.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:4", 'c_double':double(-3.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:5", 'c_double':double(-2.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:6", 'c_double':double(-2.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:7", 'c_double':double(-2.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:8", 'c_double':null} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:9", 'c_double':double(-2.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:10", 'c_double':double(-2.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:11", 'c_double':double(-2.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:12", 'c_double':double(-2.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:13", 'c_double':double(-2.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:14", 'c_double':double(-1.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:15", 'c_double':double(-1.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:16", 'c_double':double('INF')} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:17", 'c_double':double(-1.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:18", 'c_double':double(-1.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:19", 'c_double':double(-1.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:20", 'c_double':double(-1.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:21", 'c_double':double(-1.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:22", 'c_double':double(-1.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:23", 'c_double':double(-0.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:24", 'c_double':double('-INF')} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:25", 'c_double':double(-0.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:26", 'c_double':double(-0.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:27", 'c_double':double(-0.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:28", 'c_double':double(-0.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:29", 'c_double':double(-0.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:30", 'c_double':double(-0.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:31", 'c_double':double(0.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:32", 'c_double':null} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:33", 'c_double':double(0.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:34", 'c_double':double(0.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:35", 'c_double':double(0.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:36", 'c_double':double(0.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:37", 'c_double':double(0.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:38", 'c_double':double(0.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:39", 'c_double':double(0.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:40", 'c_double':double('INF')} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:41", 'c_double':double(1.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:42", 'c_double':double(1.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:43", 'c_double':double(1.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:44", 'c_double':double(1.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:45", 'c_double':double(1.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:46", 'c_double':double(1.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:47", 'c_double':double(1.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:48", 'c_double':double('-INF')} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:49", 'c_double':double(1.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:50", 'c_double':double(2.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:51", 'c_double':double(2.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:52", 'c_double':double(2.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:53", 'c_double':double(2.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:54", 'c_double':double(2.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:55", 'c_double':double(2.625)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:56", 'c_double':null} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:57", 'c_double':double(2.75)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:58", 'c_double':double(2.875)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:59", 'c_double':double(3.0)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:60", 'c_double':double(3.125)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:61", 'c_double':double(3.25)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:62", 'c_double':double(3.375)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:63", 'c_double':double(3.5)} ); +INSERT INTO dsUntyped ( { 'id': "dsUntyped:64", 'c_double':double('INF')} ); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.003.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.003.query.sqlpp new file mode 100644 index 0000000..da3519d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/double/double.003.query.sqlpp @@ -0,0 +1,25 @@ +/* + * 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 dsUntyped +WHERE (c_double) <= double(-3.5) ORDER BY c_double; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double/double.003.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double/double.003.adm new file mode 100644 index 0000000..fc1c3cf --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/double/double.003.adm @@ -0,0 +1 @@ +Lorem Ipsum \ 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 ac237d5..443dbf7 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -16557,6 +16557,11 @@ </compilation-unit> </test-case> <test-case FilePath="column"> + <compilation-unit name="filter/double"> + <output-dir compare="Text">filter/double</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="column"> <compilation-unit name="delete/001"> <output-dir compare="Text">delete/001</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 dc35948..39c0c2d 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 @@ -95,6 +95,11 @@ </compilation-unit> </test-case> <test-case FilePath="column"> + <compilation-unit name="filter/double"> + <output-dir compare="Text">filter/double</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="column"> <compilation-unit name="delete/001"> <output-dir compare="Text">delete/001</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java index f493c94..a451860 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java @@ -23,6 +23,7 @@ import org.apache.asterix.column.filter.FilterAccessorProvider; import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessor; import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessorFactory; +import org.apache.asterix.column.values.writer.filters.DoubleColumnFilterWriter; import org.apache.asterix.om.base.ABoolean; import org.apache.asterix.om.base.ADouble; import org.apache.asterix.om.base.AInt64; @@ -72,7 +73,7 @@ case DOUBLE: double doubleVal = ((ADouble) value).getDoubleValue(); stringValue = Double.toString(doubleVal); - normalizedValue = Double.doubleToLongBits(doubleVal); + normalizedValue = DoubleColumnFilterWriter.normalizeDouble(doubleVal); break; case STRING: stringValue = ((AString) value).getStringValue(); 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..cb4bf3e 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 @@ -34,12 +34,12 @@ @Override public long getMinNormalizedValue() { - return Double.doubleToLongBits(min); + return normalizeDouble(min); } @Override public long getMaxNormalizedValue() { - return Double.doubleToLongBits(max); + return normalizeDouble(max); } @Override @@ -47,4 +47,20 @@ min = Double.MIN_VALUE; max = Double.MAX_VALUE; } + + public static double denormalizeDouble(long x) { + if (x >= 0) + return Double.longBitsToDouble(x); + else + return Double.longBitsToDouble(-(x + 1) | 0x1000000000000000L); + } + + public static long normalizeDouble(Double x) { + long raw = Double.doubleToRawLongBits(x); + if (raw >= 0) + return raw; + else + return -(raw & 0x7FFFFFFFFFFFFFFFL) - 1; + } + } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19636 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: ionic Gerrit-Change-Id: I702c4e1ef6c46e532cf64a874ec6a81bea3ebaad Gerrit-Change-Number: 19636 Gerrit-PatchSet: 1 Gerrit-Owner: [email protected] Gerrit-MessageType: newchange
