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


##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java:
##########
@@ -213,4 +217,29 @@ public static Object generateValueByType(int base, 
ColumnType type) {
                 throw new IllegalArgumentException("unsupported type " + type);
         }
     }
+
+    /**
+     * Converts list of {@link InternalSqlRow} to list of list of objects, 
where internal list represent a row with fields.
+     *
+     * @param rows List
+     * @return List of converted rows.
+     */
+    public static List<List<?>> convertSqlRows(List<InternalSqlRow> rows) {

Review Comment:
   ```suggestion
       public static List<List<Object>> convertSqlRows(List<InternalSqlRow> 
rows) {
   ```



##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java:
##########
@@ -213,4 +217,29 @@ public static Object generateValueByType(int base, 
ColumnType type) {
                 throw new IllegalArgumentException("unsupported type " + type);
         }
     }
+
+    /**
+     * Converts list of {@link InternalSqlRow} to list of list of objects, 
where internal list represent a row with fields.
+     *
+     * @param rows List

Review Comment:
   this line looks incomplete 



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/InternalSqlRowImpl.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Realization of {@code InternalSqlRow} allowing to avoid earlier unnecessary 
row deserialization, for example when we need to pass it to

Review Comment:
   ```suggestion
    * Implementation of {@code InternalSqlRow} allowing to avoid earlier 
unnecessary row deserialization, for example when we need to pass it to
   ```



##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/JdbcConverterUtils.java:
##########
@@ -44,4 +46,79 @@ public static Class<?> columnTypeToJdbcClass(ColumnType 
type) {
                 return type.javaClass();
         }
     }
+
+    /**
+     * 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 reader to derive value from.
+     * @param idx An index of a field of interest.
+     * @param decimalScale A scale for decimal field. If the field is of a 
different type, then the specific value does not matter.
+     * @return Derived value. The value can be {@code null}.
+     */
+    public static @Nullable Object deriveValueFromBinaryTuple(ColumnType 
columnType, BinaryTupleReader binaryTuple, int idx,
+            int decimalScale) {
+        switch (columnType) {
+            case INT8:
+                return binaryTuple.byteValue(idx);

Review Comment:
   you either should make sure that value not null or use *Boxed version of the 
getter for every primitive



##########
modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcStatement.java:
##########
@@ -164,9 +167,26 @@ protected void execute0(JdbcStatementType stmtType, String 
sql, Object[] args) t
         JdbcQueryCursorHandler handler = new 
JdbcClientQueryCursorHandler(result.getChannel());
 
         for (JdbcQuerySingleResult jdbcRes : executeResult.results()) {
+            int columnCount = jdbcRes.columnTypes().size();
+            Function<BinaryTupleReader, List<Object>> transformer = (tuple) -> 
{
+                List<ColumnType> columnTypes = jdbcRes.columnTypes();
+                int[] decimalScales = jdbcRes.decimalScales();

Review Comment:
   better to do it outside of a lambda to let GC to collect the response object



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/InternalSqlRowSingleBoolean.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.schema.BinaryTuple;
+
+/**
+ * Realization of {@code InternalSqlRow} allowing to represent a SQL row with 
a single boolean column.
+ */
+public class InternalSqlRowSingleBoolean implements InternalSqlRow {
+    final boolean val;
+    BinaryTuple row;
+
+    /**
+     * Constructor.
+     *
+     * @param bool Value for single column row.
+     */
+    public InternalSqlRowSingleBoolean(boolean bool) {
+        this.val = bool;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Object get(int idx) {
+        assert idx == 0;
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int fieldCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public BinaryTuple asBinaryTuple() {
+        if (row == null) {
+            row = new BinaryTuple(1, new 
BinaryTupleBuilder(1).appendBoolean(val).build());

Review Comment:
   I see you fall into the trap of BinaryTupleBuilder :) 
   
   if not specified explicitly, the buffer of size 
`org.apache.ignite.internal.binarytuple.BinaryTupleBuilder#DEFAULT_BUFFER_SIZE` 
(4k bytes) will be allocated 



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/InternalSqlRowSingleBoolean.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.schema.BinaryTuple;
+
+/**
+ * Realization of {@code InternalSqlRow} allowing to represent a SQL row with 
a single boolean column.
+ */
+public class InternalSqlRowSingleBoolean implements InternalSqlRow {
+    final boolean val;
+    BinaryTuple row;

Review Comment:
   private final ? 



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/InternalSqlRowImpl.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Realization of {@code InternalSqlRow} allowing to avoid earlier unnecessary 
row deserialization, for example when we need to pass it to
+ * wire.
+ *
+ * @param <RowT> Type of the sql row.
+ */
+public class InternalSqlRowImpl<RowT> implements InternalSqlRow {
+    private final RowT row;
+    private final RowHandler<RowT> rowHandler;
+
+    /**
+     * Constructor.
+     *
+     * @param row Sql row.
+     * @param rowHandler Handler to deserialize given row.
+     */
+    public InternalSqlRowImpl(RowT row, RowHandler<RowT> rowHandler) {
+        this.row = row;
+        this.rowHandler = rowHandler;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nullable
+    public Object get(int idx) {

Review Comment:
   ```suggestion
       public @Nullable Object get(int idx) {
   ```



-- 
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