You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tl...@apache.org on 2021/04/22 12:09:48 UTC
[ignite] branch sql-calcite updated: IGNITE-14573 Calcite. Fix
composite objects comparator
This is an automated email from the ASF dual-hosted git repository.
tledkov pushed a commit to branch sql-calcite
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/sql-calcite by this push:
new 0903844 IGNITE-14573 Calcite. Fix composite objects comparator
0903844 is described below
commit 090384455e2ac9b614f394e0d97ae3296a80f0d3
Author: zstan <st...@gmail.com>
AuthorDate: Thu Apr 22 15:09:27 2021 +0300
IGNITE-14573 Calcite. Fix composite objects comparator
---
.../calcite/exec/exp/ExpressionFactoryImpl.java | 26 +++++++++++++++++++---
.../query/calcite/CalciteQueryProcessorTest.java | 24 +++++++++++++++-----
.../src/test/sql/update/null_update_merge.test | 8 +++----
.../query/h2/opt/GridH2ValueCacheObject.java | 15 +++++++++----
4 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
index ef10723..d653a0e 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
@@ -32,6 +32,7 @@ import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Primitives;
+import com.sun.xml.internal.ws.spi.db.FieldGetter;
import org.apache.calcite.adapter.enumerable.EnumUtils;
import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
import org.apache.calcite.adapter.enumerable.RexToLixTranslator.InputGetter;
@@ -65,6 +66,7 @@ import org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.Aggregat
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
import org.apache.ignite.internal.processors.query.calcite.util.Commons;
import org.apache.ignite.internal.processors.query.calcite.util.IgniteMethod;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject;
import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap;
import org.apache.ignite.internal.util.typedef.F;
@@ -145,9 +147,27 @@ public class ExpressionFactoryImpl<Row> implements ExpressionFactory<Row> {
if (fieldCollation.direction == RelFieldCollation.Direction.ASCENDING) {
return (o1, o2) -> {
- final Comparable c1 = (Comparable)handler.get(x, o1);
- final Comparable c2 = (Comparable)handler.get(x, o2);
- return RelFieldCollation.compare(c1, c2, nullComparison);
+ Object obj1 = handler.get(x, o1);
+ Object obj2 = handler.get(x, o2);
+
+ boolean o1Comparable = obj1 instanceof Comparable;
+ boolean o2Comparable = obj2 instanceof Comparable;
+
+ if (o1Comparable && o2Comparable) {
+ final Comparable c1 = (Comparable)obj1;
+ final Comparable c2 = (Comparable)obj2;
+ return RelFieldCollation.compare(c1, c2, nullComparison);
+ }
+ else {
+ if (obj1 == obj2)
+ return 0;
+ else if (obj1 == null)
+ return nullComparison;
+ else if (obj2 == null)
+ return -nullComparison;
+ else
+ return GridH2ValueCacheObject.compareHashOrBytes(obj1, obj2, null);
+ }
};
}
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
index dcaa953..a6299e3 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
@@ -1111,24 +1111,36 @@ public class CalciteQueryProcessorTest extends GridCommonAbstractTest {
/** */
private List<List<?>> sql(String sql) throws IgniteInterruptedCheckedException {
+ return sql(sql, false);
+ }
+
+ /** */
+ private List<List<?>> sql(String sql, boolean noCheck) throws IgniteInterruptedCheckedException {
QueryEngine engineSrv = Commons.lookupComponent(grid(0).context(), QueryEngine.class);
assertTrue(client.configuration().isClientMode());
QueryEngine engineCli = Commons.lookupComponent(client.context(), QueryEngine.class);
- List<FieldsQueryCursor<List<?>>> cursorsSrv = engineSrv.query(null, "PUBLIC", sql);
-
List<FieldsQueryCursor<List<?>>> cursorsCli = engineCli.query(null, "PUBLIC", sql);
List<List<?>> allSrv;
- try (QueryCursor srvCursor = cursorsSrv.get(0); QueryCursor cliCursor = cursorsCli.get(0)) {
- allSrv = srvCursor.getAll();
+ if (!noCheck) {
+ List<FieldsQueryCursor<List<?>>> cursorsSrv = engineSrv.query(null, "PUBLIC", sql);
- assertEquals(allSrv.size(), cliCursor.getAll().size());
+ try (QueryCursor srvCursor = cursorsSrv.get(0); QueryCursor cliCursor = cursorsCli.get(0)) {
+ allSrv = srvCursor.getAll();
- checkContextCancelled();
+ assertEquals(allSrv.size(), cliCursor.getAll().size());
+
+ checkContextCancelled();
+ }
+ }
+ else {
+ try (QueryCursor cliCursor = cursorsCli.get(0)) {
+ allSrv = cliCursor.getAll();
+ }
}
return allSrv;
diff --git a/modules/calcite/src/test/sql/update/null_update_merge.test b/modules/calcite/src/test/sql/update/null_update_merge.test
index aa9acd3..54cf5d1 100644
--- a/modules/calcite/src/test/sql/update/null_update_merge.test
+++ b/modules/calcite/src/test/sql/update/null_update_merge.test
@@ -73,7 +73,7 @@ SELECT * FROM test ORDER BY id;
4 NULL
statement ok
-UPDATE test SET a=id WHERE id != 3
+UPDATE test SET a=id WHERE id <> 3
query II
SELECT * FROM test ORDER BY id;
@@ -84,7 +84,7 @@ SELECT * FROM test ORDER BY id;
4 4
statement ok
-UPDATE test SET a=NULL WHERE id != 3
+UPDATE test SET a=NULL WHERE id <> 3
query II
SELECT * FROM test ORDER BY id;
@@ -95,7 +95,7 @@ SELECT * FROM test ORDER BY id;
4 NULL
statement ok
-UPDATE test SET a=3 WHERE id != 2
+UPDATE test SET a=3 WHERE id <> 2
query II
SELECT * FROM test ORDER BY id;
@@ -106,7 +106,7 @@ SELECT * FROM test ORDER BY id;
4 3
statement ok
-UPDATE test SET a=7 WHERE id != 3
+UPDATE test SET a=7 WHERE id <> 3
query II
SELECT * FROM test ORDER BY id;
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
index 5b1dfcd..9f33e4e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.query.h2.opt;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.Comparator;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.binary.BinaryObjectImpl;
import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -162,15 +163,21 @@ public class GridH2ValueCacheObject extends Value {
return o1.getClass().getName().compareTo(o2.getClass().getName());
}
- // Compare hash codes.
- int h1 = hashCode();
- int h2 = v.hashCode();
+ return compareHashOrBytes(o1, o2, (v1, v2) -> Bits.compareNotNullSigned(((Value)v1).getBytesNoCopy(),
+ ((Value)v2).getBytesNoCopy()));
+ }
+
+ /** Compare hash codes. */
+ public static int compareHashOrBytes(Object o1, Object o2, Comparator<Object> comp) {
+ int h1 = o1.hashCode();
+ int h2 = o2.hashCode();
if (h1 == h2) {
if (o1.equals(o2))
return 0;
- return Bits.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy());
+ return comp == null ? Bits.compareNotNullSigned(JdbcUtils.serialize(o1, null),
+ JdbcUtils.serialize(o2, null)) : comp.compare(o1, o2);
}
return h1 > h2 ? 1 : -1;