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

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new c662f45bbe IGNITE-21768 Java thin: Fix column serialization order in 
ClientKeyValueView (#3509)
c662f45bbe is described below

commit c662f45bbe5c89626f1d6739afbf1198c286e1bb
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Thu Mar 28 17:03:52 2024 +0200

    IGNITE-21768 Java thin: Fix column serialization order in 
ClientKeyValueView (#3509)
    
    Fix "key columns come first" leftovers in `ClientKeyValueView`.
---
 .../handler/requests/table/ClientHandlerTuple.java |  10 +-
 .../internal/client/table/ClientKeyValueView.java  |  12 +-
 .../client/ItCustomKeyColumnOrderClientTest.java   | 164 +++++++++++++++++++++
 .../client/ItCustomKeyColumnOrderEmbeddedTest.java |  30 ++++
 4 files changed, 212 insertions(+), 4 deletions(-)

diff --git 
a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientHandlerTuple.java
 
b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientHandlerTuple.java
index 60dacf746e..e9f39a43b0 100644
--- 
a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientHandlerTuple.java
+++ 
b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientHandlerTuple.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.client.handler.requests.table;
 
 import java.util.BitSet;
+import java.util.List;
 import org.apache.ignite.internal.binarytuple.BinaryTupleReader;
 import org.apache.ignite.internal.client.table.MutableTupleBinaryTupleAdapter;
 import org.apache.ignite.internal.schema.Column;
@@ -110,7 +111,7 @@ class ClientHandlerTuple extends 
MutableTupleBinaryTupleAdapter implements Schem
     /** {@inheritDoc} */
     @Override
     protected ColumnType schemaColumnType(int binaryTupleIndex) {
-        NativeTypeSpec spec = schema.column(binaryTupleIndex).type().spec();
+        NativeTypeSpec spec = column(binaryTupleIndex).type().spec();
 
         return ClientTableCommon.getColumnType(spec);
     }
@@ -118,6 +119,11 @@ class ClientHandlerTuple extends 
MutableTupleBinaryTupleAdapter implements Schem
     /** {@inheritDoc} */
     @Override
     protected int schemaDecimalScale(int binaryTupleIndex) {
-        return 
ClientTableCommon.getDecimalScale(schema.column(binaryTupleIndex).type());
+        return 
ClientTableCommon.getDecimalScale(column(binaryTupleIndex).type());
+    }
+
+    private Column column(int binaryTupleIndex) {
+        List<Column> columns = keyOnly ? schema.keyColumns() : 
schema.columns();
+        return columns.get(binaryTupleIndex);
     }
 }
diff --git 
a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientKeyValueView.java
 
b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientKeyValueView.java
index b04c9c2a9a..521220a73c 100644
--- 
a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientKeyValueView.java
+++ 
b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientKeyValueView.java
@@ -483,8 +483,16 @@ public class ClientKeyValueView<K, V> extends 
AbstractClientView<Entry<K, V>> im
         ClientMarshallerWriter writer = new ClientMarshallerWriter(builder, 
noValueSet);
 
         try {
-            s.getMarshaller(keySer.mapper(), TuplePart.KEY, 
false).writeObject(key, writer);
-            s.getMarshaller(valSer.mapper(), TuplePart.VAL, 
false).writeObject(val, writer);
+            Marshaller keyMarsh = s.getMarshaller(keySer.mapper(), 
TuplePart.KEY, false);
+            Marshaller valMarsh = s.getMarshaller(valSer.mapper(), 
TuplePart.VAL, false);
+
+            for (var column : s.columns()) {
+                if (column.key()) {
+                    keyMarsh.writeField(key, writer, column.keyIndex());
+                } else {
+                    valMarsh.writeField(val, writer, column.valIndex());
+                }
+            }
         } catch (MarshallerException e) {
             throw new IgniteException(INTERNAL_ERR, e.getMessage(), e);
         }
diff --git 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderClientTest.java
 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderClientTest.java
new file mode 100644
index 0000000000..4b343a6825
--- /dev/null
+++ 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderClientTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.internal.runner.app.client;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.Tuple;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests custom key column order table operations with thin client.
+ */
+@SuppressWarnings("resource")
+public class ItCustomKeyColumnOrderClientTest extends ItAbstractThinClientTest 
{
+    private static final String TABLE_NAME2 = "TBL2";
+
+    @BeforeAll
+    void createTable() {
+        String query = "CREATE TABLE " + TABLE_NAME2
+                + " (val1 VARCHAR, key1 INT, val2 BIGINT, key2 VARCHAR, 
PRIMARY KEY (key1, key2)) "
+                + "colocate by (key2, key1)";
+
+        client().sql().execute(null, query);
+    }
+
+    protected Ignite ignite() {
+        return client();
+    }
+
+    private Table table() {
+        return ignite().tables().table(TABLE_NAME2);
+    }
+
+    @Test
+    void testRecordBinaryView() {
+        var recView = table().recordView();
+
+        Tuple key = Tuple.create().set("key1", 1).set("key2", "key2");
+        Tuple val = Tuple.create().set("key1", 1).set("key2", 
"key2").set("val1", "val1").set("val2", 2L);
+        recView.insert(null, val);
+
+        Tuple res = recView.get(null, key);
+        assertEquals(val, res);
+    }
+
+    @Test
+    void testRecordView() {
+        var recView = table().recordView(Pojo.class);
+
+        Pojo key = new Pojo(1, "key2");
+        Pojo val = new Pojo(1, "key2", "val1", 2L);
+        recView.insert(null, val);
+
+        Pojo res = recView.get(null, key);
+        assertEquals(val.key1, res.key1);
+        assertEquals(val.key2, res.key2);
+        assertEquals(val.val1, res.val1);
+        assertEquals(val.val2, res.val2);
+    }
+
+    @Test
+    void testKeyValueBinaryView() {
+        var kvView = table().keyValueView();
+
+        Tuple key = Tuple.create().set("key1", 1).set("key2", "key2");
+        Tuple val = Tuple.create().set("val1", "val1").set("val2", 2L);
+        kvView.put(null, key, val);
+
+        Tuple res = kvView.get(null, key);
+        assertEquals(val, res);
+    }
+
+    @Test
+    void testKeyValueView() {
+        var kvView = table().keyValueView(PojoKey.class, PojoVal.class);
+
+        PojoKey key = new PojoKey(1, "key2");
+        PojoVal val = new PojoVal("val1", 2L);
+        kvView.put(null, key, val);
+
+        PojoVal res = kvView.get(null, key);
+        assertEquals(val.val1, res.val1);
+        assertEquals(val.val2, res.val2);
+    }
+
+    @SuppressWarnings("FieldMayBeFinal")
+    private static class Pojo {
+        private int key1;
+        @Nullable
+        private String key2;
+        @Nullable
+        private String val1;
+        private long val2;
+
+        @SuppressWarnings("unused") // Required by serializer.
+        Pojo() {
+            this(0, null, null, 0L);
+        }
+
+        Pojo(int key1, String key2) {
+            this(key1, key2, null, 0L);
+        }
+
+        Pojo(int key1, @Nullable String key2, @Nullable String val1, long 
val2) {
+            this.key1 = key1;
+            this.key2 = key2;
+            this.val1 = val1;
+            this.val2 = val2;
+        }
+    }
+
+    @SuppressWarnings("FieldMayBeFinal")
+    private static class PojoKey {
+        private int key1;
+        @Nullable
+        private String key2;
+
+        @SuppressWarnings("unused") // Required by serializer.
+        PojoKey() {
+            this(0, null);
+        }
+
+        PojoKey(int key1, @Nullable String key2) {
+            this.key1 = key1;
+            this.key2 = key2;
+        }
+    }
+
+    @SuppressWarnings("FieldMayBeFinal")
+    private static class PojoVal {
+        @Nullable
+        private String val1;
+        private long val2;
+
+        @SuppressWarnings("unused") // Required by serializer.
+        PojoVal() {
+            this(null, 0L);
+        }
+
+        PojoVal(@Nullable String val1, long val2) {
+            this.val1 = val1;
+            this.val2 = val2;
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderEmbeddedTest.java
 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderEmbeddedTest.java
new file mode 100644
index 0000000000..3f7bc29139
--- /dev/null
+++ 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItCustomKeyColumnOrderEmbeddedTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.internal.runner.app.client;
+
+import org.apache.ignite.Ignite;
+
+/**
+ * Tests custom key column order table operations with embedded API.
+ */
+public class ItCustomKeyColumnOrderEmbeddedTest extends 
ItCustomKeyColumnOrderClientTest {
+    @Override
+    protected Ignite ignite() {
+        return server();
+    }
+}

Reply via email to