JiajunBernoulli commented on code in PR #3393:
URL: https://github.com/apache/calcite/pull/3393#discussion_r1341124452


##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -4769,19 +4778,53 @@ private void convertValuesImpl(
       return;
     }
 
-    for (SqlNode rowConstructor1 : values.getOperandList()) {
-      SqlCall rowConstructor = (SqlCall) rowConstructor1;
+    SqlCall insertOp = callStack.peek();
+    // resolve presence of default params
+    boolean processDefaults = (insertOp != null) && containsDefault(values);
+
+    if (targetRowType == null) {
+      RelDataType listType = validator().getValidatedNodeType(values);
+      targetRowType = SqlTypeUtil.promoteToRowType(typeFactory, listType, 
null);
+    }
+
+    assert insertOp instanceof SqlInsert || !processDefaults : "operation: " + 
insertOp;
+
+    @Nullable InitializerExpressionFactory initializerFactory = null;
+    @Nullable RelOptTable targetTable = null;
+    int[] mapping = null;
+
+    if (processDefaults) {
+      targetTable = getTargetTable(requireNonNull(insertOp, "insertOp"));
+      initializerFactory =
+          getInitializerFactory(getNamespace(requireNonNull(insertOp, 
"insertOp"))
+              .getTable());
+      mapping =
+          processColumnsMapping(requireNonNull(targetRowType, 
"targetRowType"), targetTable);
+    }
+
+    for (SqlNode rowConstructor : values.getOperandList()) {
+      SqlCall rowConstructor0 = (SqlCall) rowConstructor;
       Blackboard tmpBb = createBlackboard(bb.scope, null, false);
-      replaceSubQueries(tmpBb, rowConstructor,
-          RelOptUtil.Logic.TRUE_FALSE_UNKNOWN);
+      replaceSubQueries(tmpBb, rowConstructor, 
RelOptUtil.Logic.TRUE_FALSE_UNKNOWN);

Review Comment:
   Try to keep the original code as much as possible, as this will affect the 
Git history.



##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -4769,19 +4778,53 @@ private void convertValuesImpl(
       return;
     }
 
-    for (SqlNode rowConstructor1 : values.getOperandList()) {
-      SqlCall rowConstructor = (SqlCall) rowConstructor1;
+    SqlCall insertOp = callStack.peek();

Review Comment:
   We like final variable.
   



##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -4769,19 +4778,53 @@ private void convertValuesImpl(
       return;
     }
 
-    for (SqlNode rowConstructor1 : values.getOperandList()) {
-      SqlCall rowConstructor = (SqlCall) rowConstructor1;
+    SqlCall insertOp = callStack.peek();
+    // resolve presence of default params
+    boolean processDefaults = (insertOp != null) && containsDefault(values);
+
+    if (targetRowType == null) {
+      RelDataType listType = validator().getValidatedNodeType(values);
+      targetRowType = SqlTypeUtil.promoteToRowType(typeFactory, listType, 
null);
+    }
+
+    assert insertOp instanceof SqlInsert || !processDefaults : "operation: " + 
insertOp;
+
+    @Nullable InitializerExpressionFactory initializerFactory = null;
+    @Nullable RelOptTable targetTable = null;
+    int[] mapping = null;
+
+    if (processDefaults) {
+      targetTable = getTargetTable(requireNonNull(insertOp, "insertOp"));
+      initializerFactory =
+          getInitializerFactory(getNamespace(requireNonNull(insertOp, 
"insertOp"))
+              .getTable());
+      mapping =
+          processColumnsMapping(requireNonNull(targetRowType, 
"targetRowType"), targetTable);
+    }

Review Comment:
   Can we use new a private method that is called by convertValuesImpl? 
   Maybe line that from 4782 to 4803 can be extract.



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