This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-21731
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-21731 by this push:
new 6e56f11a69 Minor
6e56f11a69 is described below
commit 6e56f11a69397d4a236154ddd5ba84ecb648515a
Author: amashenkov <[email protected]>
AuthorDate: Tue Apr 30 14:41:11 2024 +0300
Minor
---
.../sql/engine/exec/ScannableTableImpl.java | 2 +-
.../sql/engine/exec/SqlOutputBinaryRow.java | 25 +++++++++++++++++-----
.../sql/engine/exec/TableRowConverter.java | 22 +++++++++++++------
.../sql/engine/exec/TableRowConverterImpl.java | 12 +++++++++--
.../sql/engine/exec/UpdatableTableImpl.java | 16 ++++----------
.../sql/engine/exec/TableRowConverterSelfTest.java | 4 ++--
.../engine/exec/rel/ScannableTableSelfTest.java | 7 +++++-
.../exec/rel/TableScanNodeExecutionTest.java | 7 +++++-
8 files changed, 65 insertions(+), 30 deletions(-)
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ScannableTableImpl.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ScannableTableImpl.java
index 9382951351..765cf5a65a 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ScannableTableImpl.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ScannableTableImpl.java
@@ -222,7 +222,7 @@ public class ScannableTableImpl implements ScannableTable {
) {
TableRowConverter converter = converterFactory.create(requiredColumns);
- BinaryRowEx keyRow = converter.toBinaryRow(ctx, key, true);
+ BinaryRowEx keyRow = converter.toKeyRow(ctx, key);
return internalTable.get(keyRow, tx)
.thenApply(tableRow -> {
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/SqlOutputBinaryRow.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/SqlOutputBinaryRow.java
index ec3bcc6626..5865636d29 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/SqlOutputBinaryRow.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/SqlOutputBinaryRow.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.sql.engine.exec;
import static org.apache.ignite.internal.sql.engine.util.Commons.readValue;
import java.nio.ByteBuffer;
+import java.util.function.ToIntFunction;
import org.apache.ignite.internal.binarytuple.BinaryTupleReader;
import org.apache.ignite.internal.lang.InternalTuple;
import org.apache.ignite.internal.schema.BinaryRowEx;
@@ -68,17 +69,31 @@ public class SqlOutputBinaryRow extends BinaryTupleReader
implements BinaryRowEx
}
/** Creates BinaryRow from the given tuple. */
- public static SqlOutputBinaryRow newRow(
+ static SqlOutputBinaryRow newRow(
SchemaDescriptor descriptor,
- boolean keyOnly,
InternalTuple binaryTuple
+ ) {
+ return newRow0(descriptor, binaryTuple, Column::positionInRow);
+ }
+
+ /** Creates BinaryRow of key columns from the given tuple. */
+ static SqlOutputBinaryRow newKeyRow(
+ SchemaDescriptor descriptor,
+ InternalTuple binaryTuple
+ ) {
+ return newRow0(descriptor, binaryTuple, Column::positionInKey);
+ }
+
+ /** Creates BinaryRow from the given tuple. */
+ private static SqlOutputBinaryRow newRow0(
+ SchemaDescriptor descriptor,
+ InternalTuple binaryTuple,
+ ToIntFunction<Column> columnPosition
) {
HashCalculator hashCalc = new HashCalculator();
for (Column column : descriptor.colocationColumns()) {
- int idx = keyOnly
- ? column.positionInKey()
- : column.positionInRow();
+ int idx = columnPosition.applyAsInt(column);
assert idx >= 0 : column;
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverter.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverter.java
index aa53d73182..053ecb3f84 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverter.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverter.java
@@ -26,17 +26,27 @@ import org.apache.ignite.internal.schema.BinaryRowEx;
public interface TableRowConverter {
/**
- * Converts a relational node row to table row.
+ * Converts a relational node row to table row of all columns.
*
* @param ectx Execution context.
* @param row Relational node row.
- * @param key True if the row is a key only row.
- * @return Table node row.
+ * @return Table row.
*/
- <RowT> BinaryRowEx toBinaryRow(
+ <RowT> BinaryRowEx toFullRow(
ExecutionContext<RowT> ectx,
- RowT row,
- boolean key
+ RowT row
+ );
+
+ /**
+ * Converts a relational node row to table row of key columns only.
+ *
+ * @param ectx Execution context.
+ * @param row Relational node row.
+ * @return Table row of key columns.
+ */
+ <RowT> BinaryRowEx toKeyRow(
+ ExecutionContext<RowT> ectx,
+ RowT row
);
/**
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterImpl.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterImpl.java
index 288e5e4e1c..d27aba44bf 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterImpl.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterImpl.java
@@ -77,10 +77,18 @@ public class TableRowConverterImpl implements
TableRowConverter {
/** {@inheritDoc} */
@Override
- public <RowT> BinaryRowEx toBinaryRow(ExecutionContext<RowT> ectx, RowT
row, boolean key) {
+ public <RowT> BinaryRowEx toFullRow(ExecutionContext<RowT> ectx, RowT row)
{
BinaryTuple binaryTuple = ectx.rowHandler().toBinaryTuple(row);
- return SqlOutputBinaryRow.newRow(schemaDescriptor, key, binaryTuple);
+ return SqlOutputBinaryRow.newRow(schemaDescriptor, binaryTuple);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public <RowT> BinaryRowEx toKeyRow(ExecutionContext<RowT> ectx, RowT row) {
+ BinaryTuple binaryTuple = ectx.rowHandler().toBinaryTuple(row);
+
+ return SqlOutputBinaryRow.newKeyRow(schemaDescriptor, binaryTuple);
}
/** {@inheritDoc} */
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/UpdatableTableImpl.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/UpdatableTableImpl.java
index 52e61db92c..b4ab1bd694 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/UpdatableTableImpl.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/UpdatableTableImpl.java
@@ -113,7 +113,7 @@ public final class UpdatableTableImpl implements
UpdatableTable {
Int2ObjectOpenHashMap<List<BinaryRow>> rowsByPartition = new
Int2ObjectOpenHashMap<>();
for (RowT row : rows) {
- BinaryRowEx binaryRow = convertRow(ectx, row);
+ BinaryRowEx binaryRow = rowConverter.toFullRow(ectx, row);
rowsByPartition.computeIfAbsent(partitionExtractor.fromRow(binaryRow), k -> new
ArrayList<>()).add(binaryRow);
}
@@ -184,7 +184,7 @@ public final class UpdatableTableImpl implements
UpdatableTable {
public <RowT> CompletableFuture<Void> insert(InternalTransaction tx,
ExecutionContext<RowT> ectx, RowT row) {
validateNotNullConstraint(ectx.rowHandler(), row);
- BinaryRowEx tableRow = rowConverter.toBinaryRow(ectx, row, false);
+ BinaryRowEx tableRow = rowConverter.toFullRow(ectx, row);
return table.insert(tableRow, tx)
.thenApply(success -> {
@@ -253,7 +253,7 @@ public final class UpdatableTableImpl implements
UpdatableTable {
int i = 0;
for (RowT row : rows) {
- BinaryRowEx binaryRow = convertRow(ectx, row);
+ BinaryRowEx binaryRow = rowConverter.toFullRow(ectx, row);
rowBatchByPartitionId.computeIfAbsent(partitionExtractor.fromRow(binaryRow),
partitionId -> new RowBatch()).add(binaryRow, i++);
}
@@ -276,7 +276,7 @@ public final class UpdatableTableImpl implements
UpdatableTable {
Int2ObjectOpenHashMap<List<BinaryRow>> keyRowsByPartition = new
Int2ObjectOpenHashMap<>();
for (RowT row : rows) {
- BinaryRowEx binaryRow = convertKeyOnlyRow(ectx, row);
+ BinaryRowEx binaryRow = rowConverter.toKeyRow(ectx, row);
keyRowsByPartition.computeIfAbsent(partitionExtractor.fromRow(binaryRow), k ->
new ArrayList<>()).add(binaryRow);
}
@@ -310,14 +310,6 @@ public final class UpdatableTableImpl implements
UpdatableTable {
return CompletableFuture.allOf(futures);
}
- private <RowT> BinaryRowEx convertRow(ExecutionContext<RowT> ctx, RowT
row) {
- return rowConverter.toBinaryRow(ctx, row, false);
- }
-
- private <RowT> BinaryRowEx convertKeyOnlyRow(ExecutionContext<RowT> ctx,
RowT row) {
- return rowConverter.toBinaryRow(ctx, row, true);
- }
-
private <RowT> CompletableFuture<List<RowT>> handleInsertResults(
ExecutionContext<RowT> ectx,
Collection<RowBatch> batches
diff --git
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterSelfTest.java
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterSelfTest.java
index 4715f4b3f9..42f2470334 100644
---
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterSelfTest.java
+++
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/TableRowConverterSelfTest.java
@@ -138,7 +138,7 @@ public class TableRowConverterSelfTest extends
BaseIgniteAbstractTest {
schema,
null
);
- BinaryRowEx convertedRow = converter.toBinaryRow(executionContext,
wrapper, false);
+ BinaryRowEx convertedRow = converter.toFullRow(executionContext,
wrapper);
BinaryTupleReader reader = new BinaryTupleReader(schema.length(),
convertedRow.tupleSlice());
@@ -188,7 +188,7 @@ public class TableRowConverterSelfTest extends
BaseIgniteAbstractTest {
schema
).create(null);
- BinaryRowEx convertedRow = converter.toBinaryRow(executionContext,
wrapper, true);
+ BinaryRowEx convertedRow = converter.toKeyRow(executionContext,
wrapper);
List<Column> keyColumns = schema.keyColumns();
BinaryTuple reader = new BinaryTuple(keyColumns.size(),
convertedRow.tupleSlice());
diff --git
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/ScannableTableSelfTest.java
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/ScannableTableSelfTest.java
index 96a83d5991..96926232b2 100644
---
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/ScannableTableSelfTest.java
+++
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/ScannableTableSelfTest.java
@@ -817,7 +817,12 @@ public class ScannableTableSelfTest extends
BaseIgniteAbstractTest {
}
@Override
- public <RowT> BinaryRowEx toBinaryRow(ExecutionContext<RowT> ectx,
RowT row, boolean key) {
+ public <RowT> BinaryRowEx toFullRow(ExecutionContext<RowT> ectx, RowT
row) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <RowT> BinaryRowEx toKeyRow(ExecutionContext<RowT> ectx, RowT
row) {
throw new UnsupportedOperationException();
}
diff --git
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/TableScanNodeExecutionTest.java
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/TableScanNodeExecutionTest.java
index 7513b2390f..5c12103b02 100644
---
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/TableScanNodeExecutionTest.java
+++
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/TableScanNodeExecutionTest.java
@@ -182,7 +182,12 @@ public class TableScanNodeExecutionTest extends
AbstractExecutionTest<Object[]>
TableRowConverter rowConverter = new TableRowConverter() {
@Override
- public <RowT> BinaryRowEx toBinaryRow(ExecutionContext<RowT>
ectx, RowT row, boolean key) {
+ public <RowT> BinaryRowEx toFullRow(ExecutionContext<RowT>
ectx, RowT row) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <RowT> BinaryRowEx toKeyRow(ExecutionContext<RowT>
ectx, RowT row) {
throw new UnsupportedOperationException();
}