[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 <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Peeyush Gupta <peeyush.gupta@couchbase.com>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
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 0000000..f69df6e
--- /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 0000000..0080dcf
--- /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 0000000..f460366
--- /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 0000000..e5e3bb7
--- /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 7b82038..dc424d3 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]", "r": true }, "t10": { "c": "[double('NaN')] < [0]", "r": false }, "t11": { "c": "[double('NaN')] > [-0]", "r": true }, "t12": { "c": "[double('NaN')] < [-0]", "r": false }, "t13": { "c": "[double('NaN')] > [double('-0')]", "r": true }, "t14": { "c": "[double('NaN')] < [double('-0')]", "r": false }, "t15": { "c": "[double('-INF')] < [double('INF')]", "r": true }, "t16": { "c": "[double('INF')] > [double('NaN')]", "r": false }, "t17": { "c": "[double('-INF')] < [double('NaN')]", "r": true } }
\ 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]", "r": true }, "t10": { "c": "[double('NaN')] < [0]", "r": false }, "t11": { "c": "[double('NaN')] > [-0]", "r": true }, "t12": { "c": "[double('NaN')] < [-0]", "r": false }, "t13": { "c": "[double('NaN')] > [double('-0')]", "r": true }, "t14": { "c": "[double('NaN')] < [double('-0')]", "r": false }, "t15": { "c": "[double('-INF')] < [double('INF')]", "r": true }, "t16": { "c": "[double('INF')] > [double('NaN')]", "r": false }, "t17": { "c": "[double('-INF')] < [double('NaN')]", "r": 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.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 0000000..f32a580
--- /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 0000000..6a6d86c
--- /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 0000000..767521e
--- /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 0000000..02e4a84
--- /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 6abac01..b6dbf7f 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 4db23b2..0eb30f8 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 @@
// 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 @@
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 @@
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 @@
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);
+ }
}