You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2022/02/01 09:12:15 UTC

[ignite] branch master updated: IGNITE-16421 : Fix table operations failure when wrap_key and custom value_type are used (#9777)

This is an automated email from the ASF dual-hosted git repository.

amashenkov 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 9ace034  IGNITE-16421 : Fix table operations failure when wrap_key and custom value_type are used (#9777)
9ace034 is described below

commit 9ace0344190958b56268bc9018dbfd17212dd4ae
Author: ygerzhedovich <41...@users.noreply.github.com>
AuthorDate: Tue Feb 1 12:11:32 2022 +0300

    IGNITE-16421 : Fix table operations failure when wrap_key and custom value_type are used (#9777)
---
 .../query/property/QueryBinaryProperty.java        |  6 +++
 .../cache/index/H2DynamicTableSelfTest.java        | 62 ++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
index e3c49e1..1a49d99 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
@@ -25,6 +25,7 @@ import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryObjectExImpl;
+import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
 import org.apache.ignite.internal.processors.query.GridQueryProperty;
 import org.apache.ignite.internal.util.typedef.F;
 
@@ -124,6 +125,11 @@ public class QueryBinaryProperty implements GridQueryProperty {
 
             return obj0.getField(propName);
         }
+        else if (obj instanceof KeyCacheObjectImpl) {
+            KeyCacheObjectImpl obj0 = (KeyCacheObjectImpl)obj;
+
+            return obj0.value(null, false);
+        }
         else
             throw new IgniteCheckedException("Unexpected binary object class [type=" + obj.getClass() + ']');
     }
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
index 316eba4..4e2d51a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
@@ -30,6 +30,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Random;
 import java.util.UUID;
 import java.util.concurrent.Callable;
@@ -45,6 +46,7 @@ import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.DataRegionConfiguration;
 import org.apache.ignite.configuration.DataStorageConfiguration;
@@ -1806,6 +1808,32 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     }
 
     /**
+     * Create table with wrapped key and user value type and insert value by cache API.
+     * Check inserted value.
+     * @throws Exception In case of errors.
+     */
+    @Test
+    public void testWrappedKeyValidation() throws Exception {
+        IgniteCache c1 = ignite(0).getOrCreateCache("WRAP_KEYS");
+        c1.query(new SqlFieldsQuery("CREATE TABLE TestValues (\n" +
+                "  namePK varchar primary key,\n" +
+                "  notUniqueId int\n" +
+                ") WITH \"wrap_key=true," +
+                "value_type=" + TestValue.class.getName() + "\""))
+            .getAll();
+
+        IgniteCache<String, TestValue> values = ignite(0).cache(cacheName("TESTVALUES"));
+
+        TestValue v1 = new TestValue(1);
+
+        values.put("1", v1);
+
+        TestValue rv1 = values.get("1");
+
+        assertEquals(v1, rv1);
+    }
+
+    /**
      * Execute DDL statement on client node.
      *
      * @param sql Statement.
@@ -1952,4 +1980,38 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     private static String cacheName(String tblName) {
         return QueryUtils.createTableCacheName("PUBLIC", tblName);
     }
+
+    /**
+     * Test class for sql queryable test value
+     */
+    private static class TestValue {
+        /**
+         * Not unique id
+         */
+        @QuerySqlField
+        int notUniqueId;
+
+        /** */
+        public TestValue(int notUniqueId) {
+            this.notUniqueId = notUniqueId;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestValue testValue = (TestValue)o;
+
+            return notUniqueId == testValue.notUniqueId;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(notUniqueId);
+        }
+    }
 }