kasakrisz commented on code in PR #5267:
URL: https://github.com/apache/hive/pull/5267#discussion_r1620074130


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java:
##########
@@ -350,26 +352,51 @@ private MergeStatement.InsertClause handleInsert(ASTNode 
whenNotMatchedClause, S
       throw new SemanticException(String.format("Column schema must have the 
same length as values (%d vs %d)",
           columnListNode.getChildCount(), valuesNode.getChildCount() - 1));
     }
-    UnparseTranslator defaultValuesTranslator = new UnparseTranslator(conf);
-    defaultValuesTranslator.enable();
-    List<String> targetSchema = processTableColumnNames(columnListNode, 
targetTable.getFullyQualifiedName());
-    collectDefaultValues(valuesNode, targetTable, targetSchema, 
defaultValuesTranslator);
-    defaultValuesTranslator.applyTranslations(ctx.getTokenRewriteStream());
-    String valuesClause = getMatchedText(valuesNode);
-    valuesClause = valuesClause.substring(1, valuesClause.length() - 1); 
//strip '(' and ')'
 
-    String extraPredicate = getWhenClausePredicate(whenNotMatchedClause);
-    return new MergeStatement.InsertClause(
-        getMatchedText(columnListNode), valuesClause, onClausePredicate, 
extraPredicate);
-  }
+    List<String> columnNames;
+    if (columnListNode != null) {

Review Comment:
   refactored this part



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java:
##########
@@ -350,26 +352,51 @@ private MergeStatement.InsertClause handleInsert(ASTNode 
whenNotMatchedClause, S
       throw new SemanticException(String.format("Column schema must have the 
same length as values (%d vs %d)",
           columnListNode.getChildCount(), valuesNode.getChildCount() - 1));
     }
-    UnparseTranslator defaultValuesTranslator = new UnparseTranslator(conf);
-    defaultValuesTranslator.enable();
-    List<String> targetSchema = processTableColumnNames(columnListNode, 
targetTable.getFullyQualifiedName());
-    collectDefaultValues(valuesNode, targetTable, targetSchema, 
defaultValuesTranslator);
-    defaultValuesTranslator.applyTranslations(ctx.getTokenRewriteStream());
-    String valuesClause = getMatchedText(valuesNode);
-    valuesClause = valuesClause.substring(1, valuesClause.length() - 1); 
//strip '(' and ')'
 
-    String extraPredicate = getWhenClausePredicate(whenNotMatchedClause);
-    return new MergeStatement.InsertClause(
-        getMatchedText(columnListNode), valuesClause, onClausePredicate, 
extraPredicate);
-  }
+    List<String> columnNames;
+    if (columnListNode != null) {
+      columnNames = new ArrayList<>(valuesNode.getChildCount());
+      for (int i = 0; i < columnListNode.getChildCount(); ++i) {
+        ASTNode columnNameNode = (ASTNode) columnListNode.getChild(i);
+        String columnName = 
ctx.getTokenRewriteStream().toString(columnNameNode.getTokenStartIndex(),
+            columnNameNode.getTokenStopIndex()).trim();
+        columnNames.add(columnName);
+      }
+    } else {
+      columnNames = null;
+    }
 
-  private void collectDefaultValues(
-          ASTNode valueClause, Table targetTable, List<String> targetSchema, 
UnparseTranslator unparseTranslator)
-          throws SemanticException {
+    List<String> values = new ArrayList<>(valuesNode.getChildCount());
+    UnparseTranslator unparseTranslator = 
HiveUtils.collectUnescapeIdentifierTranslations(valuesNode);
+    unparseTranslator.applyTranslations(ctx.getTokenRewriteStream(), 
MERGE_INSERT_VALUES_PROGRAM);
+    List<String> targetSchema = processTableColumnNames(columnListNode, 
targetTable.getFullyQualifiedName());
     List<String> defaultConstraints = getDefaultConstraints(targetTable, 
targetSchema);
-    for (int j = 0; j < defaultConstraints.size(); j++) {
-      unparseTranslator.addDefaultValueTranslation((ASTNode) 
valueClause.getChild(j + 1), defaultConstraints.get(j));
+    // First child is 'struct' the rest are the value expressions

Review Comment:
   added



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to