This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit fee1bf25dd789cb2fc024e0c1691656bff5056ca Author: Peeyush Gupta <[email protected]> AuthorDate: Thu Jun 6 22:40:06 2024 -0700 [ASTERIXDB-3418][*DB] Predicate 0.0=-0.0 returns false - user model changes: no - storage format changes: no - interface changes: no Details: Predicate 0.0=-0.0 incorrectly return false as we were using Double.compare to compare double values. Change-Id: I3cfa0b9cbf149021fd4fd1759f29e7ddba34956f Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18344 Tested-by: Jenkins <[email protected]> Reviewed-by: Peeyush Gupta <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> --- .../query-ASTERIXDB-3418.1.query.sqlpp | 24 ++++++++++++++++++++++ .../query-ASTERIXDB-3418.2.query.sqlpp | 24 ++++++++++++++++++++++ .../query-ASTERIXDB-3418.3.query.sqlpp | 24 ++++++++++++++++++++++ .../query-ASTERIXDB-3418.4.query.sqlpp | 24 ++++++++++++++++++++++ .../results/comparison/arrays/arrays.020.adm | 2 +- .../query-ASTERIXDB-3418.1.adm | 1 + .../query-ASTERIXDB-3418.2.adm | 1 + .../query-ASTERIXDB-3418.3.adm | 1 + .../query-ASTERIXDB-3418.4.adm | 1 + .../test/resources/runtimets/testsuite_sqlpp.xml | 5 +++++ .../data/nontagged/comparators/ComparatorUtil.java | 20 ++++++++++++------ 11 files changed, 120 insertions(+), 7 deletions(-) diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.query.sqlpp new file mode 100644 index 0000000000..f69df6ef64 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.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. + */ + +/* + * Description: This test case is to verify the fix for ASTERIXDB-3418 + */ + +select value 0.0=-0.0 \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.query.sqlpp new file mode 100644 index 0000000000..0080dcf941 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.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. + */ + +/* + * Description: This test case is to verify the fix for ASTERIXDB-3418 + */ + +select x.a, count(*) from [{"a":0.0, "b":1}, {"a":-0.0, "b":2}] x group by x.a; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.query.sqlpp new file mode 100644 index 0000000000..f4603666ff --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.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. + */ + +/* + * Description: This test case is to verify the fix for ASTERIXDB-3418 + */ + +select distinct(x.a) from [{"a":0.0, "b":1}, {"a":-0.0, "b":2}] x; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.query.sqlpp new file mode 100644 index 0000000000..e5e3bb7ff7 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.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. + */ + +/* + * Description: This test case is to verify the fix for ASTERIXDB-3418 + */ + +select value -0.0<0.0 \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/arrays/arrays.020.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/arrays/arrays.020.adm index 7b820384a8..dc424d3faf 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/arrays/arrays.020.adm +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/arrays/arrays.020.adm @@ -1 +1 @@ -{ "t1": { "c": "[0,1] = [double('0'), float('1')]", "r": true }, "t2": { "c": "[-0, -1] = [float('-0'), -1]", "r": false }, "t3": { "c": "[double('INF')] > [0]", "r": true }, "t4": { "c": "[double('-INF')] < [0]", "r": true }, "t5": { "c": "[double('INF')] > [-0]", "r": true }, "t6": { "c": "[double('-INF')] < [-0]", "r": true }, "t7": { "c": "[double('INF')] > [double('-0')]", "r": true }, "t8": { "c": "[double('-INF')] < [double('-0')]", "r": true }, "t9": { "c": "[double('NaN')] > [0] [...] \ No newline at end of file +{ "t1": { "c": "[0,1] = [double('0'), float('1')]", "r": true }, "t2": { "c": "[-0, -1] = [float('-0'), -1]", "r": true }, "t3": { "c": "[double('INF')] > [0]", "r": true }, "t4": { "c": "[double('-INF')] < [0]", "r": true }, "t5": { "c": "[double('INF')] > [-0]", "r": true }, "t6": { "c": "[double('-INF')] < [-0]", "r": true }, "t7": { "c": "[double('INF')] > [double('-0')]", "r": true }, "t8": { "c": "[double('-INF')] < [double('-0')]", "r": true }, "t9": { "c": "[double('NaN')] > [0]" [...] \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.adm new file mode 100644 index 0000000000..f32a5804e2 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.1.adm @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.adm new file mode 100644 index 0000000000..6a6d86ce89 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.2.adm @@ -0,0 +1 @@ +{ "a": -0.0, "$1": 2 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.adm new file mode 100644 index 0000000000..767521e115 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.3.adm @@ -0,0 +1 @@ +{ "a": -0.0 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.adm new file mode 100644 index 0000000000..02e4a84d62 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3418/query-ASTERIXDB-3418.4.adm @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 6abac01268..b6dbf7faef 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -7295,6 +7295,11 @@ <output-dir compare="Text">query-ASTERIXDB-3334</output-dir> </compilation-unit> </test-case> + <test-case FilePath="misc"> + <compilation-unit name="query-ASTERIXDB-3418"> + <output-dir compare="Text">query-ASTERIXDB-3418</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="multipart-dataverse"> <test-case FilePath="multipart-dataverse"> diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/ComparatorUtil.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/ComparatorUtil.java index 4db23b2778..0eb30f8bc1 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/ComparatorUtil.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/ComparatorUtil.java @@ -84,9 +84,9 @@ public class ComparatorUtil { // start points to the value; checking left and right are compatible and numbers has to be done before calling this static int compareNumbers(ATypeTag lTag, byte[] l, int lStart, ATypeTag rTag, byte[] r, int rStart) { if (lTag == DOUBLE || rTag == DOUBLE) { - return Double.compare(getDoubleValue(lTag, l, lStart), getDoubleValue(rTag, r, rStart)); + return compareDoubles(getDoubleValue(lTag, l, lStart), getDoubleValue(rTag, r, rStart)); } else if (lTag == FLOAT || rTag == FLOAT) { - return Float.compare((float) getDoubleValue(lTag, l, lStart), (float) getDoubleValue(rTag, r, rStart)); + return compareFloats((float) getDoubleValue(lTag, l, lStart), (float) getDoubleValue(rTag, r, rStart)); } else if (lTag == BIGINT || rTag == BIGINT) { return Long.compare(getLongValue(lTag, l, lStart), getLongValue(rTag, r, rStart)); } else if (lTag == INTEGER || lTag == SMALLINT || lTag == TINYINT) { @@ -103,10 +103,10 @@ public class ComparatorUtil { byte[] leftBytes = left.getByteArray(); int start = left.getStartOffset(); if (leftTag == DOUBLE || rightTag == DOUBLE) { - return asResult(Double.compare(getDoubleValue(leftTag, leftBytes, start), getConstantDouble(right))); + return asResult(compareDoubles(getDoubleValue(leftTag, leftBytes, start), getConstantDouble(right))); } else if (leftTag == FLOAT || rightTag == FLOAT) { return asResult( - Float.compare((float) getDoubleValue(leftTag, leftBytes, start), (float) getConstantDouble(right))); + compareFloats((float) getDoubleValue(leftTag, leftBytes, start), (float) getConstantDouble(right))); } else if (leftTag == BIGINT || rightTag == BIGINT) { return asResult(Long.compare(getLongValue(leftTag, leftBytes, start), getConstantLong(right))); } else if (leftTag == INTEGER || leftTag == SMALLINT || leftTag == TINYINT) { @@ -122,10 +122,10 @@ public class ComparatorUtil { ATypeTag leftTag = leftConstant.getType().getTypeTag(); ATypeTag rightTag = rightConstant.getType().getTypeTag(); if (leftTag == DOUBLE || rightTag == DOUBLE) { - return asResult(Double.compare(getConstantDouble(leftConstant), getConstantDouble(rightConstant))); + return asResult(compareDoubles(getConstantDouble(leftConstant), getConstantDouble(rightConstant))); } else if (leftTag == FLOAT || rightTag == FLOAT) { return asResult( - Float.compare((float) getConstantDouble(leftConstant), (float) getConstantDouble(rightConstant))); + compareFloats((float) getConstantDouble(leftConstant), (float) getConstantDouble(rightConstant))); } else if (leftTag == BIGINT || rightTag == BIGINT) { return asResult(Long.compare(getConstantLong(leftConstant), getConstantLong(rightConstant))); } else if (leftTag == INTEGER || leftTag == SMALLINT || leftTag == TINYINT) { @@ -208,4 +208,12 @@ public class ComparatorUtil { throw new UnsupportedOperationException(); } } + + public static int compareDoubles(double d1, double d2) { + return d1 == d2 ? 0 : Double.compare(d1, d2); + } + + public static int compareFloats(float f1, float f2) { + return f1 == f2 ? 0 : Float.compare(f1, f2); + } }
