korlov42 commented on code in PR #2912:
URL: https://github.com/apache/ignite-3/pull/2912#discussion_r1413472180


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -578,19 +586,12 @@ private CompletableFuture<Void> executeFragment(IgniteRel 
treeRoot, ResolvedDepe
             if (!(node instanceof Outbox)) {
                 Function<RowT, RowT> internalTypeConverter = 
TypeUtils.resultTypeConverter(ectx, treeRoot.getRowType());
 
-                AsyncRootNode<RowT, List<Object>> rootNode = new 
AsyncRootNode<>(node, inRow -> {
-                    inRow = internalTypeConverter.apply(inRow);
-
-                    int rowSize = ectx.rowHandler().columnCount(inRow);
-
-                    List<Object> res = new ArrayList<>(rowSize);
-
-                    for (int i = 0; i < rowSize; i++) {
-                        res.add(ectx.rowHandler().get(i, inRow));
-                    }
-
-                    return res;
-                });
+                AsyncRootNode<RowT, InternalSqlRow> rootNode = new 
AsyncRootNode<>(
+                        node,
+                        inRow -> {
+                            inRow = internalTypeConverter.apply(inRow);

Review Comment:
   why do we still need this conversion?



##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/InternalSqlRowForList.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.sql.engine.util;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Period;
+import java.util.BitSet;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.sql.engine.InternalSqlRow;
+import org.jetbrains.annotations.Nullable;
+
+/** InternalSqlRow implementation for test purposes only. */
+public class InternalSqlRowForList implements InternalSqlRow {

Review Comment:
   ```suggestion
   public class ListToInternalSqlRowAdapter implements InternalSqlRow {
   ```



##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/JdbcConverterUtils.java:
##########
@@ -44,4 +45,78 @@ public static Class<?> columnTypeToJdbcClass(ColumnType 
type) {
                 return type.javaClass();
         }
     }
+
+    /**
+     * Derive value from BinaryTuple by given column number, column type and 
scale for decimal type.
+     *
+     * @param columnType Type of column in binaryTuple by index idx.
+     * @param binaryTuple BinaryTuple to extract value.
+     * @param idx Index of column in binaryTuple.
+     * @param decimalScale Scale for decimal column. If the column is of a 
different type, then the specific value does not matter.
+     * @return Derived value. The value can be {@code null}.

Review Comment:
   ```suggestion
        * Derives value from {@link BinaryTuple} by given column index, column 
type, and scale for decimal type.
        *
        * @param columnType An expected type of the field.
        * @param binaryTuple A tuple to derive value from.
        * @param idx An index of a field of interest.
        * @param decimalScale A scale for decimal column. If the column is of a 
different type, then the specific value does not matter.
        * @return Derived value. The value can be {@code null}.
   ```
   



##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/proto/event/JdbcQueryFetchResult.java:
##########
@@ -95,10 +95,11 @@ public void writeBinary(ClientMessagePacker packer) {
 
         packer.packBoolean(last);
 
-        packer.packInt(items.size());
+        packer.packInt(rowTuples.size());
 
-        for (List<Object> item : items) {
-            packer.packObjectArrayAsBinaryTuple(item.toArray());
+        for (BinaryTuple item : rowTuples) {
+            packer.packInt(item.elementCount());

Review Comment:
   why do we need to send this for every row in a page? I think, we can send it 
only once with very first page



##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/InternalSqlRowForList.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.sql.engine.util;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Period;
+import java.util.BitSet;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.sql.engine.InternalSqlRow;
+import org.jetbrains.annotations.Nullable;
+
+/** InternalSqlRow implementation for test purposes only. */
+public class InternalSqlRowForList implements InternalSqlRow {
+    List<Object> source;
+
+    public InternalSqlRowForList(List<Object> source) {
+        this.source = source;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public @Nullable Object get(int idx) {
+        return source.get(idx);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int fieldCount() {
+        return source.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public BinaryTuple asBinaryTuple() {
+        BinaryTupleBuilder binaryTupleBuilder = new 
BinaryTupleBuilder(source.size());
+
+        source.forEach(o -> appendObject(binaryTupleBuilder, o));
+
+        return new BinaryTuple(source.size(), binaryTupleBuilder.build());
+    }
+
+    private void appendObject(BinaryTupleBuilder builder, Object obj) {

Review Comment:
   ```suggestion
       private static void appendObject(BinaryTupleBuilder builder, @Nullable 
Object obj) {
   ```



##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/QueryCheckerImpl.java:
##########
@@ -322,7 +323,15 @@ public void check() {
             assertEquals(metadataMatchers.size(), columnMetadata.size(), 
"Column metadata doesn't match");
         }
 
-        List<List<?>> res = Commons.cast(getAllFromCursor(cur));
+        List<InternalSqlRow> rows = Commons.cast(getAllFromCursor(cur));
+        List<List<?>> res = new ArrayList<>(rows.size());
+        rows.forEach(r -> {

Review Comment:
   I believe forEach loop is more suitable here



##########
modules/api/src/main/java/org/apache/ignite/sql/ColumnType.java:
##########
@@ -26,86 +26,101 @@
 import java.time.LocalTime;
 import java.time.Period;
 import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.UUID;
 
 /**
  * Predefined column types.
  */
 public enum ColumnType {
+    /** Null. */
+    NULL(Void.class, false, false, false, 0),
+
     /** Boolean. */
-    BOOLEAN(Boolean.class, false, false, false),
+    BOOLEAN(Boolean.class, false, false, false, 1),
 
     /** 8-bit signed integer. */
-    INT8(Byte.class, false, false, false),
+    INT8(Byte.class, false, false, false, 2),
 
     /** 16-bit signed integer. */
-    INT16(Short.class, false, false, false),
+    INT16(Short.class, false, false, false, 3),
 
     /** 32-bit signed integer. */
-    INT32(Integer.class, false, false, false),
+    INT32(Integer.class, false, false, false, 4),
 
     /** 64-bit signed integer. */
-    INT64(Long.class, false, false, false),
+    INT64(Long.class, false, false, false, 5),
 
     /** 32-bit single-precision floating-point number. */
-    FLOAT(Float.class, false, false, false),
+    FLOAT(Float.class, false, false, false, 6),
 
     /**
      * 64-bit double-precision floating-point number.
      *
      * <p>SQL`16 part 2 section 6.1 syntax rule 31, implementation-defined 
precision
      */
-    DOUBLE(Double.class, false, false, false),
+    DOUBLE(Double.class, false, false, false, 7),
 
     /** Arbitrary-precision signed decimal number. */
-    DECIMAL(BigDecimal.class, true, true, false),
+    DECIMAL(BigDecimal.class, true, true, false, 8),
 
     /** Timezone-free date. */
-    DATE(LocalDate.class, false, false, false),
+    DATE(LocalDate.class, false, false, false, 9),
 
     /** Timezone-free time with precision. */
-    TIME(LocalTime.class, true, false, false),
+    TIME(LocalTime.class, true, false, false, 10),
 
     /** Timezone-free datetime. */
-    DATETIME(LocalDateTime.class, true, false, false),
+    DATETIME(LocalDateTime.class, true, false, false, 11),
 
     /** Point on the time-line. Number of ticks since {@code 
1970-01-01T00:00:00Z}. Tick unit depends on precision. */
-    TIMESTAMP(Instant.class, true, false, false),
+    TIMESTAMP(Instant.class, true, false, false, 12),
 
     /** 128-bit UUID. */
-    UUID(UUID.class, false, false, false),
+    UUID(UUID.class, false, false, false, 13),
 
     /** Bit mask. */
-    BITMASK(BitSet.class, false, false, true),
+    BITMASK(BitSet.class, false, false, true, 14),
 
     /** String. */
-    STRING(String.class, false, false, true),
+    STRING(String.class, false, false, true, 15),
 
     /** Binary data. */
-    BYTE_ARRAY(byte[].class, false, false, true),
+    BYTE_ARRAY(byte[].class, false, false, true, 16),
 
     /** Date interval. */
-    PERIOD(Period.class, true, false, false),
+    PERIOD(Period.class, true, false, false, 17),
 
     /** Time interval. */
-    DURATION(Duration.class, true, false, false),
+    DURATION(Duration.class, true, false, false, 18),
 
     /** Number. */
-    NUMBER(BigInteger.class, true, false, false),
-
-    /** Null. */
-    NULL(Void.class, false, false, false);
+    NUMBER(BigInteger.class, true, false, false, 19);
 
     private final Class<?> javaClass;
     private final boolean precisionAllowed;
     private final boolean scaleAllowed;
     private final boolean lengthAllowed;
 
-    ColumnType(Class<?> clazz, boolean precisionDefined, boolean scaleDefined, 
boolean lengthDefined) {
+    private final int id;
+
+    private static final Map<Integer, ColumnType> ENUM_ID_MAP = new 
HashMap<>();
+
+    static {
+        for (ColumnType columnType : values()) {
+            ColumnType prevValue = ENUM_ID_MAP.put(columnType.id, columnType);
+            assert prevValue == null : "Duplicate id of ColumnType " + 
prevValue.id;
+        }
+
+    }
+
+    ColumnType(Class<?> clazz, boolean precisionDefined, boolean scaleDefined, 
boolean lengthDefined, int id) {

Review Comment:
   nitpicking: usually, an `id` is the first parameter in constructor



##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/JdbcConverterUtils.java:
##########
@@ -44,4 +45,78 @@ public static Class<?> columnTypeToJdbcClass(ColumnType 
type) {
                 return type.javaClass();
         }
     }
+
+    /**
+     * Derive value from BinaryTuple by given column number, column type and 
scale for decimal type.
+     *
+     * @param columnType Type of column in binaryTuple by index idx.
+     * @param binaryTuple BinaryTuple to extract value.
+     * @param idx Index of column in binaryTuple.
+     * @param decimalScale Scale for decimal column. If the column is of a 
different type, then the specific value does not matter.
+     * @return Derived value. The value can be {@code null}.
+     */
+    public static Object deriveValueFromBinaryTuple(ColumnType columnType, 
BinaryTuple binaryTuple, int idx, int decimalScale) {

Review Comment:
   ```suggestion
       public static @Nullable Object deriveValueFromBinaryTuple(ColumnType 
columnType, BinaryTuple binaryTuple, int idx, int decimalScale) {
   ```
   
   please check this everywhere in this patch: If certain parameter or return 
value may be null, then it should be marked as `@Nullable`



##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/InternalSqlRowForList.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.sql.engine.util;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Period;
+import java.util.BitSet;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.sql.engine.InternalSqlRow;
+import org.jetbrains.annotations.Nullable;
+
+/** InternalSqlRow implementation for test purposes only. */
+public class InternalSqlRowForList implements InternalSqlRow {
+    List<Object> source;

Review Comment:
   ```suggestion
       private final List<Object> source;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to