ramitg254 commented on code in PR #6413:
URL: https://github.com/apache/hive/pull/6413#discussion_r3396671968
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/SplitUpdateRewriter.java:
##########
@@ -65,44 +66,23 @@ public ParseUtils.ReparseResult rewrite(Context context,
UpdateStatement updateB
List<String> deleteValues = sqlGenerator.getDeleteValues(OPERATION);
int columnOffset = deleteValues.size();
- List<String> insertValues = new
ArrayList<>(updateBlock.getTargetTable().getCols().size());
+ Table targetTable = updateBlock.getTargetTable();
+ List<String> insertValues = new
ArrayList<>(targetTable.getAllCols().size());
boolean first = true;
- List<FieldSchema> nonPartCols = updateBlock.getTargetTable().getCols();
+ List<FieldSchema> nonPartCols = targetTable.getCols();
for (int i = 0; i < nonPartCols.size(); i++) {
- if (first) {
- first = false;
- } else {
- sqlGenerator.append(",");
- }
-
- String name = nonPartCols.get(i).getName();
- ASTNode setCol = updateBlock.getSetCols().get(name);
- String identifier = HiveUtils.unparseIdentifier(name, this.conf);
-
- 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(name));
- } 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(i + columnOffset, setCol);
- }
- } else {
- sqlGenerator.append(identifier);
- }
- sqlGenerator.append(" AS ");
- sqlGenerator.append(identifier);
-
- insertValues.add(sqlGenerator.qualify(identifier));
+ appendUpdateColumn(updateBlock, sqlGenerator, insertValues, setColExprs,
+ nonPartCols.get(i).getName(), i, columnOffset, true, !first);
+ first = false;
}
- if (updateBlock.getTargetTable().getPartCols() != null) {
- updateBlock.getTargetTable().getPartCols().forEach(
- fieldSchema ->
insertValues.add(sqlGenerator.qualify(HiveUtils.unparseIdentifier(fieldSchema.getName(),
conf))));
+ List<FieldSchema> partCols = targetTable.getPartCols();
+ for (int i = 0; i < partCols.size(); i++) {
+ boolean appendToSelect = targetTable.hasNonNativePartitionSupport();
+ appendUpdateColumn(updateBlock, sqlGenerator, insertValues, setColExprs,
+ partCols.get(i).getName(), nonPartCols.size() + i, columnOffset,
appendToSelect, appendToSelect);
Review Comment:
It won't even though we are returning and appendToSelect will be false,
there is no use case of first after that loop as well as inside
appendUpdateColumn for part cols
It's only use case is when appendToSelect is true and at that time we should
always set it to false after first iteration
--
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]