kasakrisz commented on code in PR #6439:
URL: https://github.com/apache/hive/pull/6439#discussion_r3109122193
##########
ql/src/test/queries/clientpositive/sqlmerge.q:
##########
@@ -22,3 +22,15 @@ explain merge into acidTbl_n0 as t using nonAcidOrcTbl_n0 s
ON t.a = s.a
WHEN MATCHED AND s.a > 8 THEN DELETE
WHEN MATCHED THEN UPDATE SET b = 7
WHEN NOT MATCHED THEN INSERT VALUES(s.a, s.b);
+
+-- MERGE rewrite must preserve quoting for qualified identifiers like s.`date`
when column name is function keyword
+drop table if exists src_table;
+drop table if exists tgt_table;
+create table src_table(a int, `date` int) clustered by (a) into 2 buckets
stored as orc
+ TBLPROPERTIES ('transactional'='true');
+create table tgt_table(a int, `date` int) clustered by (a) into 2 buckets
stored as orc
+ TBLPROPERTIES ('transactional'='true');
Review Comment:
Could you please change one of the table names to a quoted function name.
##########
ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java:
##########
@@ -354,8 +354,20 @@ public Object process(Node nd, Stack<Node> stack,
NodeProcessorCtx procCtx, Obje
throws SemanticException {
UnparseTranslator unparseTranslator =
((QuotedIdExpressionContext)procCtx).getUnparseTranslator();
ASTNode identifier = (ASTNode) nd;
- String id = identifier.getText();
- if (FunctionRegistry.getFunctionInfo(id) != null){
+ /*
+ * Quote identifiers during unparse.
+ *
+ * Only skip quoting for function names.
+ * Always quote column names, even if they match function names.
+ * For example, use `alias`.`date` instead of `alias`.date.
+ */
+ ASTNode parent = (ASTNode) identifier.getParent();
+ if (parent != null
+ && (parent.getType() == HiveParser.TOK_FUNCTION
+ || parent.getType() == HiveParser.TOK_FUNCTIONDI
+ || parent.getType() == HiveParser.TOK_FUNCTIONSTAR)
+ && parent.getChildCount() > 0
+ && parent.getChild(0) == identifier) {
Review Comment:
I think this is a good solution.
The alternative would be to
* remove the `IdentifierProcessor`
* add separate processors for `TOK_TABNAME`, `TOK_TABLE_OR_COL`, etc.
The risk of this alternative is that we might miss an AST node.
--
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]