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


##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -4769,21 +4779,47 @@ private void convertValuesImpl(
       return;
     }
 
-    for (SqlNode rowConstructor1 : values.getOperandList()) {
-      SqlCall rowConstructor = (SqlCall) rowConstructor1;
+    SqlCall insertOp = callStack.peek();
+    boolean processDefaults = insertOp != null && DefaultChecker.check(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 = processDefaults
+            ? getInitializerFactory(getNamespace(requireNonNull(insertOp, 
"insertOp")).getTable())
+        : null;
+    @Nullable RelOptTable targetTable = processDefaults
+        ? getTargetTable(requireNonNull(insertOp, "insertOp")) : null;
+    int[] mapping = processDefaults
+        ? processColumnsMapping(requireNonNull(targetRowType, "targetRowType"),
+        requireNonNull(targetTable, "targetTable")) : null;
+
+    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);
       final PairList<RexNode, String> exps = PairList.of();
-      Ord.forEach(rowConstructor.getOperandList(), (operand, i) ->
+      Ord.forEach(rowConstructor0.getOperandList(), (operand, i) -> {
+        if (processDefaults && operand.getKind() == SqlKind.DEFAULT
+            && requireNonNull(mapping, "mapping")[i] != -1) {
+          RexNode def = requireNonNull(initializerFactory, 
"initializerFactory")
+              .newColumnDefaultValue(requireNonNull(targetTable, 
"targetTable"), mapping[i], bb);
+
+          exps.add(def, SqlValidatorUtil.alias(operand, i));
+        } else {
           exps.add(tmpBb.convertExpression(operand),
-              SqlValidatorUtil.alias(operand, i)));
-      RelNode in =
-          (null == tmpBb.root)
-              ? LogicalValues.createOneRow(cluster)
-              : tmpBb.root;
+              SqlValidatorUtil.alias(operand, i));
+        }
+      });
+
+      RelNode in = (null == tmpBb.root) ? LogicalValues.createOneRow(cluster) 
: tmpBb.root;
+
       relBuilder.push(in)
-          .project(exps.leftList(), exps.rightList());
+          .project(Pair.left(exps), Pair.right(exps));

Review Comment:
   why did you revert?



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