You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ko...@apache.org on 2023/02/08 10:40:09 UTC

[ignite-3] branch main updated: IGNITE-18701 Incorrect binary tuple column mapping (#1620)

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

korlov 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 2c752ac69f IGNITE-18701 Incorrect binary tuple column mapping (#1620)
2c752ac69f is described below

commit 2c752ac69f7d2b06f4e262202208074fb633da01
Author: Vadim Pakhnushev <86...@users.noreply.github.com>
AuthorDate: Wed Feb 8 13:40:04 2023 +0300

    IGNITE-18701 Incorrect binary tuple column mapping (#1620)
---
 .../apache/ignite/internal/index/IndexManager.java |  2 +-
 .../ignite/internal/schema/BinaryConverter.java    | 19 ++------
 .../ignite/internal/schema/BinaryTupleSchema.java  |  2 +-
 .../internal/schema/BinaryTupleSchemaTest.java     | 57 ++++++++++++++++++++++
 4 files changed, 63 insertions(+), 17 deletions(-)

diff --git a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexManager.java b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexManager.java
index d3325479cc..af4eaed71b 100644
--- a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexManager.java
+++ b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexManager.java
@@ -525,7 +525,7 @@ public class IndexManager extends Producer<IndexEvent, IndexEventParameters> imp
             BinaryTupleSchema tupleSchema = BinaryTupleSchema.createSchema(descriptor, indexedColumns);
             BinaryTupleSchema rowSchema = BinaryTupleSchema.createRowSchema(descriptor);
 
-            var binaryRowConverter = new BinaryConverter(descriptor, tupleSchema, false);
+            var binaryRowConverter = new BinaryConverter(descriptor, tupleSchema);
             var tableRowConverter = new TableRowConverter(rowSchema, tupleSchema);
 
             return new VersionedConverter(descriptor.version(), binaryRowConverter::toTuple, tableRowConverter::toTuple);
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryConverter.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryConverter.java
index b5f9629129..0af20fe5eb 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryConverter.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryConverter.java
@@ -48,8 +48,6 @@ public class BinaryConverter {
     /** Tuple schema. */
     private final BinaryTupleSchema tupleSchema;
 
-    private final boolean skipKey;
-
     /** Row wrapper that allows direct access to variable-length values. */
     private class RowHelper extends Row {
         RowHelper(SchemaDescriptor descriptor, BinaryRow row) {
@@ -77,16 +75,13 @@ public class BinaryConverter {
      *
      * @param descriptor Row schema.
      * @param tupleSchema Tuple schema.
-     * @param skipKey Whether to build tuple from value part only.
      */
     public BinaryConverter(
             SchemaDescriptor descriptor,
-            BinaryTupleSchema tupleSchema,
-            boolean skipKey
+            BinaryTupleSchema tupleSchema
     ) {
         this.descriptor = descriptor;
         this.tupleSchema = tupleSchema;
-        this.skipKey = skipKey;
     }
 
     /**
@@ -96,7 +91,7 @@ public class BinaryConverter {
      * @return Row converter.
      */
     public static BinaryConverter forRow(SchemaDescriptor descriptor) {
-        return new BinaryConverter(descriptor, BinaryTupleSchema.createRowSchema(descriptor), false);
+        return new BinaryConverter(descriptor, BinaryTupleSchema.createRowSchema(descriptor));
     }
 
     /**
@@ -106,7 +101,7 @@ public class BinaryConverter {
      * @return Key converter.
      */
     public static BinaryConverter forKey(SchemaDescriptor descriptor) {
-        return new BinaryConverter(descriptor, BinaryTupleSchema.createKeySchema(descriptor), false);
+        return new BinaryConverter(descriptor, BinaryTupleSchema.createKeySchema(descriptor));
     }
 
     /**
@@ -116,7 +111,7 @@ public class BinaryConverter {
      * @return Key converter.
      */
     public static BinaryConverter forValue(SchemaDescriptor descriptor) {
-        return new BinaryConverter(descriptor, BinaryTupleSchema.createValueSchema(descriptor), true);
+        return new BinaryConverter(descriptor, BinaryTupleSchema.createValueSchema(descriptor));
     }
 
     /**
@@ -138,9 +133,6 @@ public class BinaryConverter {
             NativeTypeSpec typeSpec = elt.typeSpec;
 
             int columnIndex = tupleSchema.columnIndex(elementIndex);
-            if (skipKey) {
-                columnIndex += descriptor.keyColumns().length();
-            }
             if (row.hasNullValue(columnIndex, typeSpec)) {
                 hasNulls = true;
             } else if (typeSpec.fixedLength()) {
@@ -158,9 +150,6 @@ public class BinaryConverter {
             NativeTypeSpec typeSpec = elt.typeSpec;
 
             int columnIndex = tupleSchema.columnIndex(elementIndex);
-            if (skipKey) {
-                columnIndex += descriptor.keyColumns().length();
-            }
             if (row.hasNullValue(columnIndex, typeSpec)) {
                 builder.appendNull();
                 continue;
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTupleSchema.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTupleSchema.java
index 5061a00952..da28e8f44d 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTupleSchema.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTupleSchema.java
@@ -107,7 +107,7 @@ public class BinaryTupleSchema {
         /** {@inheritDoc} */
         @Override
         public int columnIndex(int index) {
-            return index - columnBase;
+            return index + columnBase;
         }
 
         /** {@inheritDoc} */
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/BinaryTupleSchemaTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/BinaryTupleSchemaTest.java
new file mode 100644
index 0000000000..37dfabbe96
--- /dev/null
+++ b/modules/schema/src/test/java/org/apache/ignite/internal/schema/BinaryTupleSchemaTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.schema;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Locale;
+import org.junit.jupiter.api.Test;
+
+/** Tests for the {@link BinaryTupleSchema} class. */
+public class BinaryTupleSchemaTest {
+
+    private static final SchemaDescriptor SCHEMA = new SchemaDescriptor(1, new Column[]{
+            new Column("id".toUpperCase(Locale.ROOT), NativeTypes.INT32, false),
+    }, new Column[]{
+            new Column("val".toUpperCase(Locale.ROOT), NativeTypes.INT32, false),
+    });
+
+    @Test
+    public void rowSchema() {
+        BinaryTupleSchema schema = BinaryTupleSchema.createRowSchema(SCHEMA);
+        assertEquals(0, schema.columnIndex(0));
+        assertEquals(1, schema.columnIndex(1));
+        assertTrue(schema.convertible());
+    }
+
+    @Test
+    public void keySchema() {
+        BinaryTupleSchema schema = BinaryTupleSchema.createKeySchema(SCHEMA);
+        assertEquals(0, schema.columnIndex(0));
+        assertTrue(schema.convertible());
+    }
+
+    @Test
+    public void valueSchema() {
+        BinaryTupleSchema schema = BinaryTupleSchema.createValueSchema(SCHEMA);
+        assertEquals(1, schema.columnIndex(0));
+        assertFalse(schema.convertible());
+    }
+}