Aggarwal-Raghav commented on code in PR #6685:
URL: https://github.com/apache/hive/pull/6685#discussion_r4007683241
##########
ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands.java:
##########
@@ -1114,19 +1114,19 @@ public void testQuotedIdentifier() throws Exception {
"`d?*de e` decimal(5,2)," +
"vc varchar(128)) clustered by (i) into 2 buckets stored as orc
TBLPROPERTIES ('transactional'='true')");
runStatementOnDriver("create table " + src + "(gh int, j decimal(5,2), k
varchar(128))");
- runStatementOnDriver("merge into " + target + " as `d/8` using " + src + "
as `a/b` on i=gh " +
+ runStatementOnDriver("merge into " + target + " as `d/8` using " + src + "
as `a/b` on `d/8`.i=`a/b`.gh " +
"\nwhen matched and i > 5 then delete " +
"\nwhen matched then update set vc='blah' " +
"\nwhen not matched then insert values(1,2.1,'baz')");
- runStatementOnDriver("merge into " + target + " as `d/8` using " + src + "
as `a/b` on i=gh " +
+ runStatementOnDriver("merge into " + target + " as `d/8` using " + src + "
as `a/b` on `d/8`.i=`a/b`.gh " +
Review Comment:
This seems to be a breaking change? For acid tables users will have to
change the query. Maybe we can enforce the check only when its COW?
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java:
##########
@@ -130,7 +130,15 @@ WHEN NOT MATCHED THEN INSERT VALUES (source.a2, source.b2)
.sourceName(sourceName)
.sourceAlias(getSourceAlias(source, sourceName))
.onClauseAsText(onClauseAsText);
-
+
+ OnClauseAnalyzer oca = new OnClauseAnalyzer(onClause, targetTable,
targetAlias,
+ conf, onClauseAsText);
+ oca.analyze();
+ // unresolved columns are not allowed in the on clause to avoid wrong
results
+ if (!oca.unresolvedColumns.isEmpty()) {
Review Comment:
How about restricting the exception to COW?
```patch
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java
index f5e23dd8a9..aa5ac64a84 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java
@@ -28,6 +28,8 @@
import org.apache.hadoop.hive.ql.lib.Node;
import org.apache.hadoop.hive.ql.metadata.HiveUtils;
import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.Context;
+import org.apache.hadoop.hive.ql.metadata.HiveStorageHandler;
import org.apache.hadoop.hive.ql.parse.rewrite.MergeStatement;
import org.apache.hadoop.hive.ql.parse.rewrite.RewriterFactory;
@@ -125,18 +127,25 @@ WHEN NOT MATCHED THEN INSERT VALUES (source.a2,
source.b2)
String sourceName = getSimpleTableName(source);
ASTNode onClause = (ASTNode) tree.getChild(2);
String onClauseAsText = getMatchedText(onClause);
-
+
MergeStatement.MergeStatementBuilder mergeStatementBuilder =
MergeStatement
.withTarget(targetTable, getFullTableNameForSQL(targetNameNode),
targetAlias)
.sourceName(sourceName)
.sourceAlias(getSourceAlias(source, sourceName))
.onClauseAsText(onClauseAsText);
-
+
+ boolean copyOnWriteMode = false;
+ HiveStorageHandler storageHandler = targetTable.getStorageHandler();
+ if (storageHandler != null) {
+ copyOnWriteMode = storageHandler.shouldOverwrite(targetTable,
Context.Operation.MERGE);
+ }
+
OnClauseAnalyzer oca = new OnClauseAnalyzer(onClause, targetTable,
targetAlias,
conf, onClauseAsText);
oca.analyze();
- // unresolved columns are not allowed in the on clause to avoid wrong
results
- if (!oca.unresolvedColumns.isEmpty()) {
+
+ // Only enforce unresolved column check in Copy-on-Write mode to avoid
breaking standard ACID/MoR
+ if (copyOnWriteMode && !oca.unresolvedColumns.isEmpty()) {
throw new SemanticException("UnResolvedColumns exist: " +
String.join(",", oca.unresolvedColumns) +
". We should assign a table name to each column in the ON
clause like tbl.col.");
}
```
--
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]