This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new a82a3ecb832 IGNITE-23008 SQL Calcite: Fix binary object dynamic params
processing - Fixes #11606.
a82a3ecb832 is described below
commit a82a3ecb8329e35335159486140ff47a1c346a43
Author: Aleksey Plekhanov <[email protected]>
AuthorDate: Mon Oct 28 17:50:50 2024 +0300
IGNITE-23008 SQL Calcite: Fix binary object dynamic params processing -
Fixes #11606.
Signed-off-by: Aleksey Plekhanov <[email protected]>
---
.../query/calcite/prepare/IgniteSqlValidator.java | 20 ++------
.../query/calcite/type/IgniteTypeFactory.java | 3 +-
.../integration/AbstractBasicIntegrationTest.java | 11 +++-
.../integration/KeepBinaryIntegrationTest.java | 58 ++++++++++++++++++++++
4 files changed, 73 insertions(+), 19 deletions(-)
diff --git
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
index 131031364b8..93cd94d1dec 100644
---
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
+++
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
@@ -55,7 +55,6 @@ import org.apache.calcite.sql.type.SqlOperandTypeChecker;
import org.apache.calcite.sql.type.SqlOperandTypeInference;
import org.apache.calcite.sql.type.SqlTypeFamily;
import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.sql.validate.SelectScope;
import org.apache.calcite.sql.validate.SqlQualified;
import org.apache.calcite.sql.validate.SqlValidator;
@@ -600,23 +599,12 @@ public class IgniteSqlValidator extends SqlValidatorImpl {
RelDataType valType =
typeFactory().toSql(typeFactory().createType(val.getClass()));
- if (SqlTypeUtil.equalSansNullability(valType, inferredType))
- return false;
-
assert !unknownType.equals(valType);
- if (valType.getFamily().equals(inferredType.getFamily())) {
- RelDataType leastRestrictive =
typeFactory().leastRestrictive(F.asList(inferredType, valType));
-
- assert leastRestrictive != null;
-
- if (inferredType == leastRestrictive)
- return false;
- }
- else if (!unknownType.equals(inferredType) &&
SqlTypeUtil.canCastFrom(valType, inferredType, true))
- return false;
-
- setValidatedNodeType(node, valType);
+ if (unknownType.equals(inferredType) ||
valType.getFamily().equals(inferredType.getFamily()))
+ setValidatedNodeType(node, valType);
+ else
+ setValidatedNodeType(node, inferredType);
return true;
}
diff --git
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
index 954b9e64ddf..cdcaca7e3c3 100644
---
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
+++
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
@@ -44,6 +44,7 @@ import org.apache.calcite.sql.type.BasicSqlType;
import org.apache.calcite.sql.type.IntervalSqlType;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.util.typedef.F;
/**
@@ -315,7 +316,7 @@ public class IgniteTypeFactory extends JavaTypeFactoryImpl {
public RelDataType createCustomType(Type type, boolean nullable) {
if (UUID.class == type)
return canonize(new UuidType(nullable));
- else if (Object.class == type)
+ else if (Object.class == type || (type instanceof Class &&
BinaryObject.class.isAssignableFrom((Class<?>)type)))
return canonize(new OtherType(nullable));
return null;
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java
index 62be28c6669..8451d68d277 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java
@@ -74,6 +74,11 @@ public class AbstractBasicIntegrationTest extends
GridCommonAbstractTest {
client = startClientGrid("client");
}
+ /** */
+ protected boolean destroyCachesAfterTest() {
+ return true;
+ }
+
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
// Wait for pending queries before destroying caches. If some error
occurs during query execution, client code
@@ -92,8 +97,10 @@ public class AbstractBasicIntegrationTest extends
GridCommonAbstractTest {
}, INBOX_INITIALIZATION_TIMEOUT * 2);
for (Ignite ign : G.allGrids()) {
- for (String cacheName : ign.cacheNames())
- ign.destroyCache(cacheName);
+ if (destroyCachesAfterTest()) {
+ for (String cacheName : ign.cacheNames())
+ ign.destroyCache(cacheName);
+ }
CalciteQueryProcessor qryProc = queryProcessor(ign);
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/KeepBinaryIntegrationTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/KeepBinaryIntegrationTest.java
index bf62dd6b833..086bcee39ac 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/KeepBinaryIntegrationTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/KeepBinaryIntegrationTest.java
@@ -45,6 +45,11 @@ public class KeepBinaryIntegrationTest extends
AbstractBasicIntegrationTransacti
return cfg;
}
+ /** {@inheritDoc} */
+ @Override protected boolean destroyCachesAfterTest() {
+ return false;
+ }
+
/** */
@Test
public void testKeepBinary() {
@@ -97,6 +102,59 @@ public class KeepBinaryIntegrationTest extends
AbstractBasicIntegrationTransacti
txAction(client, checker);
}
+ /** */
+ @Test
+ public void testDynamicParameters() {
+ IgniteCache<Integer, Person> cache = client.cache(CACHE_NAME);
+
+ Person p0 = new Person(0, "name0", null);
+ Person p1 = new Person(1, "name1", p0);
+
+ put(client, cache, 0, p0);
+ put(client, cache, 1, p1);
+
+ SupplierX<?> checker = () -> {
+ for (boolean keepBinary : new boolean[] {true, false}) {
+ for (String sql : new String[] {
+ "SELECT ?",
+ "SELECT _val FROM Person WHERE _val = ?",
+ "SELECT obj FROM Person WHERE obj = ?"
+ }) {
+ SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(p0);
+
+ List<List<?>> res = keepBinary ?
cache.withKeepBinary().query(qry).getAll() : cache.query(qry).getAll();
+
+ assertEquals(1, res.size());
+
+ if (keepBinary)
+ assertTrue(res.get(0).get(0) instanceof BinaryObject);
+ else
+ assertEquals(p0, res.get(0).get(0));
+ }
+
+ SqlFieldsQuery qry = new SqlFieldsQuery("SELECT
?").setArgs(F.asList(p0));
+
+ List<List<?>> res = keepBinary ?
cache.withKeepBinary().query(qry).getAll() : cache.query(qry).getAll();
+
+ assertEquals(1, res.size());
+
+ if (keepBinary) {
+ assertTrue(res.get(0).get(0) instanceof List);
+ assertTrue(((List<?>)res.get(0).get(0)).get(0) instanceof
BinaryObject);
+ }
+ else
+ assertEquals(F.asList(p0), res.get(0).get(0));
+ }
+
+ return null;
+ };
+
+ if (sqlTxMode == SqlTransactionMode.NONE)
+ checker.get();
+ else
+ txAction(client, checker);
+ }
+
/** */
private static class Person {
/** */