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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ExplainPlan.java:
##########
@@ -36,10 +36,12 @@ public class ExplainPlan implements QueryPlan {
 
     private final PlanId id;
     private final MultiStepPlan plan;
+    private final ParameterMetadata parameterMetadata;
 
-    ExplainPlan(PlanId id, MultiStepPlan plan) {
+    ExplainPlan(PlanId id, MultiStepPlan plan, ParameterMetadata 
parameterMetadata) {

Review Comment:
   when `parameterMetadata` for explain may be different from one returned by 
the plan it's meant to explain?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/DynamicParameterValue.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Dynamic parameter value.
+ */
+public final class DynamicParameterValue {

Review Comment:
   why do we need this wrapper?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ParameterMetadata.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Metadata for dynamic parameters.
+ */
+public final class ParameterMetadata {
+
+    private final List<ParameterType> parameterTypes;
+
+    /** Constructor. */
+    public ParameterMetadata(List<ParameterType> parameterTypes) {
+        this.parameterTypes = parameterTypes;
+    }
+
+    /** Return metadata for each parameter. */
+    public List<ParameterType> parameterTypes() {
+        return parameterTypes;
+    }
+
+    @Override
+    public String toString() {
+        return S.toString(ParameterMetadata.class, this, "parametersTypes", 
parameterTypes);

Review Comment:
   why do you need additional parameters here?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PrepareServiceImpl.java:
##########
@@ -345,7 +345,7 @@ private static CacheKey createCacheKey(ParsedResult 
parsedResult, PlanningContex
 
         Class[] paramTypes = ctx.parameters().length == 0

Review Comment:
   do we still need this?



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/util/QueryCheckerTest.java:
##########
@@ -247,6 +248,11 @@ void testMetadata() {
                 .check();
     }
 
+    @Test
+    public void testParameterMetadata() {
+

Review Comment:
   empty test? 



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PrepareServiceImpl.java:
##########
@@ -292,30 +303,53 @@ private CompletableFuture<QueryPlan> 
prepareQuery(ParsedResult parsedResult, Pla
             // Validate
             ValidationResult validated = 
planner.validateAndGetTypeMetadata(sqlNode);
 
-            SqlNode validatedNode = validated.sqlNode();
+            // Get parameter metadata.
+            RelDataType parameterRowType = planner.getParameterRowType();
+            ParameterMetadata parameterMetadata = 
createParameterMetadata(parameterRowType);
+
+            return new ValidStatement<>(parsedResult, validated, 
parameterMetadata);
+        }, planningPool);
+
+        return validFut.thenCompose(stmt -> {
+            // Use parameter metadata to compute a cache key.
+            CacheKey key = 
createCacheKeyFromParameterMetadata(stmt.parsedResult, ctx, 
stmt.parameterMetadata);
+
+            CompletableFuture<QueryPlan> planFut = cache.get(key, k -> 
CompletableFuture.supplyAsync(() -> {
+                IgnitePlanner planner = ctx.planner();
 
-            IgniteRel igniteRel = optimize(validatedNode, planner);
+                ValidationResult validated = stmt.value;
+                ParameterMetadata parameterMetadata = stmt.parameterMetadata;
 
-            // cluster keeps a lot of cached stuff that won't be used anymore.
-            // In order let GC collect that, let's reattach tree to an empty 
cluster
-            // before storing tree in plan cache
-            IgniteRel clonedTree = Cloner.clone(igniteRel, 
Commons.emptyCluster());
+                SqlNode validatedNode = validated.sqlNode();
 
-            return new MultiStepPlan(nextPlanId(), SqlQueryType.QUERY, 
clonedTree,
-                    resultSetMetadata(validated.dataType(), 
validated.origins(), validated.aliases()));
-        }, planningPool));
+                IgniteRel igniteRel = optimize(validatedNode, planner);
 
-        return planFut.thenApply(Function.identity());
+                // cluster keeps a lot of cached stuff that won't be used 
anymore.
+                // In order let GC collect that, let's reattach tree to an 
empty cluster
+                // before storing tree in plan cache
+                IgniteRel clonedTree = Cloner.clone(igniteRel, 
Commons.emptyCluster());
+
+                ResultSetMetadata resultSetMetadata = 
resultSetMetadata(validated.dataType(), validated.origins(), 
validated.aliases());
+                return new MultiStepPlan(nextPlanId(), SqlQueryType.QUERY, 
clonedTree, resultSetMetadata, parameterMetadata);
+            }, planningPool));
+
+            return planFut.thenApply(Function.identity());
+        });
     }
 
     private PlanId nextPlanId() {
         return new PlanId(prepareServiceId, planIdGen.getAndIncrement());
     }
 
     private CompletableFuture<QueryPlan> prepareDml(ParsedResult parsedResult, 
PlanningContext ctx) {
-        var key = createCacheKey(parsedResult, ctx);
+        // If a caller passes all the parameters, then get parameter types and 
check to see whether a plan future already exists.
+        CompletableFuture<QueryPlan> f = 
getPlanIfParameterHaveValues(parsedResult,
+                ctx);

Review Comment:
   kinda strange formatting



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