kasakrisz commented on code in PR #6413:
URL: https://github.com/apache/hive/pull/6413#discussion_r3474152209
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/SplitUpdateRewriter.java:
##########
@@ -134,4 +112,45 @@ public ParseUtils.ReparseResult rewrite(Context context,
UpdateStatement updateB
return rr;
}
+
+ protected void appendPartitionColumns(UpdateStatement updateBlock,
MultiInsertSqlGenerator sqlGenerator,
+ List<String> insertValues, Map<Integer, ASTNode> setColExprs,
List<FieldSchema> nonPartCols,
+ int columnOffset, boolean prependComma) {
+ for (FieldSchema partCol : updateBlock.getTargetTable().getPartCols()) {
+ String identifier = HiveUtils.unparseIdentifier(partCol.getName(), conf);
+
insertValues.set(updateBlock.getTargetTable().getColumnIndexByName(partCol.getName()),
+ sqlGenerator.qualify(identifier));
+ }
+ }
+
+ protected void appendUpdateColumn(UpdateStatement updateBlock,
+ MultiInsertSqlGenerator sqlGenerator, List<String> insertValues,
+ Map<Integer, ASTNode> setColExprs, String columnName, int
setColExprIndex, int columnOffset,
+ boolean prependComma) {
+ String identifier = HiveUtils.unparseIdentifier(columnName, conf);
+
+ // The insert value is placed for every column (data and partition).
+ int index = updateBlock.getTargetTable().getColumnIndexByName(columnName);
+ insertValues.set(index, sqlGenerator.qualify(identifier));
+
+ if (prependComma) {
+ sqlGenerator.append(",");
+ }
+ ASTNode setCol = updateBlock.getSetCols().get(columnName);
+ if (setCol != null) {
+ if (setCol.getType() == HiveParser.TOK_TABLE_OR_COL &&
+ setCol.getChildCount() == 1 && setCol.getChild(0).getType() ==
HiveParser.TOK_DEFAULT_VALUE) {
+
sqlGenerator.append(updateBlock.getColNameToDefaultConstraint().get(columnName));
+ } else {
+ sqlGenerator.append(identifier);
+ // This is one of the columns we're setting, record it's position so
we can come back
+ // later and patch it up. 0th is ROW_ID
+ setColExprs.put(setColExprIndex + columnOffset, setCol);
Review Comment:
Simplify: in this method only the result of this expression`setColExprIndex
+ columnOffset` is used but two parameters are passed. Please pass the result
of the expression and remove one of the parameters.
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/SplitUpdateRewriter.java:
##########
@@ -134,4 +112,45 @@ public ParseUtils.ReparseResult rewrite(Context context,
UpdateStatement updateB
return rr;
}
+
+ protected void appendPartitionColumns(UpdateStatement updateBlock,
MultiInsertSqlGenerator sqlGenerator,
+ List<String> insertValues, Map<Integer, ASTNode> setColExprs,
List<FieldSchema> nonPartCols,
+ int columnOffset, boolean prependComma) {
+ for (FieldSchema partCol : updateBlock.getTargetTable().getPartCols()) {
+ String identifier = HiveUtils.unparseIdentifier(partCol.getName(), conf);
+
insertValues.set(updateBlock.getTargetTable().getColumnIndexByName(partCol.getName()),
+ sqlGenerator.qualify(identifier));
+ }
+ }
+
+ protected void appendUpdateColumn(UpdateStatement updateBlock,
+ MultiInsertSqlGenerator sqlGenerator, List<String> insertValues,
+ Map<Integer, ASTNode> setColExprs, String columnName, int
setColExprIndex, int columnOffset,
+ boolean prependComma) {
+ String identifier = HiveUtils.unparseIdentifier(columnName, conf);
+
+ // The insert value is placed for every column (data and partition).
+ int index = updateBlock.getTargetTable().getColumnIndexByName(columnName);
+ insertValues.set(index, sqlGenerator.qualify(identifier));
+
+ if (prependComma) {
+ sqlGenerator.append(",");
+ }
Review Comment:
Please move this back to the loop where this method is called.
We always append non-partition columns and in the next step we add partition
columns. In case of non-partition columns the the comma is not needed but in
case of every follow-up columns it is. And also partition columns need it but
when we add partition columns we continue appending to an existing list so all
columns need a comma. As a result please remove `prependComma` parameter of
this method and the `appendPartitionColumns`
--
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]