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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/KeyValueModifyPlan.java:
##########
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
+import javax.annotation.Nullable;

Review Comment:
   this is wrong annotation



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadataBuilder.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueGet;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueModify;
+import org.apache.ignite.internal.sql.engine.schema.IgniteTable;
+
+/**
+ * Extracts partition awareness metadata from physical plans.
+ */
+public class PartitionAwarenessMetadataBuilder {
+
+    /**
+     * Extracts partition awareness metadata from the given IgniteKeyValueGet 
plan.
+     *
+     * @param kv IgniteKeyValueGet Plan.
+     * @return Metadata.
+     */
+    @Nullable
+    public static PartitionAwarenessMetadata build(IgniteKeyValueGet kv) {
+        RelOptTable optTable = kv.getTable();
+        assert optTable != null;
+
+        return extractMetadata(optTable, kv.keyExpressions());
+    }
+
+    /**
+     * Extracts partition awareness metadata from the given 
IgniteKeyValueModify plan.
+     *
+     * @param kv IgniteKeyValueModify Plan.
+     * @return Metadata.
+     */
+    @Nullable
+    public static PartitionAwarenessMetadata build(IgniteKeyValueModify kv) {
+        RelOptTable optTable = kv.getTable();
+        assert optTable != null;
+
+        return extractMetadata(optTable, kv.expressions());

Review Comment:
   you cannot reuse the same method in full-row case and key-only case. 
Consider the following example: 
   
   ```
   CREATE TABLE t (c1 INT, c2 INT, c3 INT, PRIMARY KEY (c3, c2)) COLOCATE BY 
(c3)
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadata.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Partition awareness metadata.
+ *
+ * @see PartitionAwarenessMetadataBuilder
+ */
+public final class PartitionAwarenessMetadata {
+
+    private final int tableId;
+
+    private final int[] indexes;
+
+    private final int[] hash;
+
+    /**
+     * Constructor.
+     *
+     * @param tableId Table Id.
+     * @param indexes Mapping between positions in colocation key and dynamic 
parameters.
+     * @param hash Array of computed hashes.
+     */
+    public PartitionAwarenessMetadata(int tableId, int[] indexes, int[] hash) {
+        this.tableId = tableId;
+        this.indexes = indexes;
+        this.hash = hash;
+    }
+
+    /** Return table id. */
+    public int tableId() {
+        return tableId;
+    }
+
+    /** Returns the number of colocation key columns. */
+    public int size() {
+        return indexes.length;
+    }
+
+    /**
+     * Returns a mapping between positions in colocation key columns and 
dynamic parameter indices.
+     * If a colocation key column has a value, returns {@code -1}.

Review Comment:
   why `-1`? I think the contract should be quite different. It's either index 
of dynamic param, or index in `hash` array.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadata.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Partition awareness metadata.
+ *
+ * @see PartitionAwarenessMetadataBuilder
+ */
+public final class PartitionAwarenessMetadata {
+
+    private final int tableId;
+
+    private final int[] indexes;
+
+    private final int[] hash;
+
+    /**
+     * Constructor.
+     *
+     * @param tableId Table Id.
+     * @param indexes Mapping between positions in colocation key and dynamic 
parameters.
+     * @param hash Array of computed hashes.
+     */
+    public PartitionAwarenessMetadata(int tableId, int[] indexes, int[] hash) {
+        this.tableId = tableId;
+        this.indexes = indexes;
+        this.hash = hash;
+    }
+
+    /** Return table id. */
+    public int tableId() {
+        return tableId;
+    }
+
+    /** Returns the number of colocation key columns. */
+    public int size() {
+        return indexes.length;
+    }
+
+    /**
+     * Returns a mapping between positions in colocation key columns and 
dynamic parameter indices.
+     * If a colocation key column has a value, returns {@code -1}.
+     *
+     * @return Mapping.
+     */
+    public int[] indexes() {
+        return indexes;
+    }
+
+    /**
+     * Returns an array of precomputed hashes.
+     *
+     * @return Hash array.
+     */
+    public int[] hash() {
+        return hash;
+    }
+
+
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return S.toString(PartitionAwarenessMetadata.class, this,
+                "dynamicParams", Arrays.toString(indexes),

Review Comment:
   ```suggestion
                   "indexes", Arrays.toString(indexes),
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PrepareServiceImpl.java:
##########
@@ -501,8 +508,13 @@ CompletableFuture<QueryPlan> prepareDmlOpt(SqlNode 
sqlNode, PlanningContext ctx,
 
         ExplainablePlan plan;
         if (optimizedRel instanceof IgniteKeyValueModify) {
+            IgniteKeyValueModify kvModify = (IgniteKeyValueModify) 
optimizedRel;

Review Comment:
   why do we need PA metadata for single-shot query plans?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadataBuilder.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;

Review Comment:
   wrong annotation



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadataBuilder.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueGet;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueModify;
+import org.apache.ignite.internal.sql.engine.schema.IgniteTable;
+
+/**
+ * Extracts partition awareness metadata from physical plans.
+ */
+public class PartitionAwarenessMetadataBuilder {

Review Comment:
   Builder -- it's an established pattern. I would avoid using this name in 
other contexts to avoid confusion.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadataBuilder.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.prepare.partitionawareness;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueGet;
+import org.apache.ignite.internal.sql.engine.rel.IgniteKeyValueModify;
+import org.apache.ignite.internal.sql.engine.schema.IgniteTable;
+
+/**
+ * Extracts partition awareness metadata from physical plans.
+ */
+public class PartitionAwarenessMetadataBuilder {
+
+    /**
+     * Extracts partition awareness metadata from the given IgniteKeyValueGet 
plan.
+     *
+     * @param kv IgniteKeyValueGet Plan.
+     * @return Metadata.
+     */
+    @Nullable
+    public static PartitionAwarenessMetadata build(IgniteKeyValueGet kv) {
+        RelOptTable optTable = kv.getTable();
+        assert optTable != null;
+
+        return extractMetadata(optTable, kv.keyExpressions());
+    }
+
+    /**
+     * Extracts partition awareness metadata from the given 
IgniteKeyValueModify plan.
+     *
+     * @param kv IgniteKeyValueModify Plan.
+     * @return Metadata.
+     */
+    @Nullable
+    public static PartitionAwarenessMetadata build(IgniteKeyValueModify kv) {
+        RelOptTable optTable = kv.getTable();
+        assert optTable != null;
+
+        return extractMetadata(optTable, kv.expressions());
+    }
+
+    @Nullable
+    private static PartitionAwarenessMetadata extractMetadata(
+            RelOptTable optTable,
+            List<RexNode> expressions
+    ) {
+        IgniteTable igniteTable = optTable.unwrap(IgniteTable.class);
+        assert igniteTable != null;
+
+        ImmutableIntList colocationKeys = igniteTable.distribution().getKeys();
+
+        // colocation key index to dynamic param index
+        int[] dynamicParams = new int[colocationKeys.size()];
+        Arrays.fill(dynamicParams, -1);

Review Comment:
   why do you fill with `-1`?



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to