nrg4878 commented on code in PR #3360:
URL: https://github.com/apache/hive/pull/3360#discussion_r898176218
##########
parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g:
##########
@@ -1613,10 +1613,10 @@ resourceType
createFunctionStatement
@init { pushMsg("create function statement", state); }
@after { popMsg(state); }
- : KW_CREATE (temp=KW_TEMPORARY)? KW_FUNCTION functionIdentifier KW_AS
StringLiteral
+ : KW_CREATE (temp=KW_TEMPORARY)? KW_FUNCTION orReplace? ifNotExists?
functionIdentifier KW_AS StringLiteral
Review Comment:
@wecharyu This grammer syntax seems inconsistent with what we have for
views.
"create or replace view <viewname>" where as for functions it would be
"create function or replace <function name>"
also the grammer supports the syntax below
create function or replace if not exists <function name>
Is this supported? "if not exists" should only apply when the function does
not exist. It would not apply for replacing existing one. Would this be
confusing for users?
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/function/create/CreateFunctionAnalyzer.java:
##########
@@ -54,6 +54,14 @@ public CreateFunctionAnalyzer(QueryState queryState) throws
SemanticException {
public void analyzeInternal(ASTNode root) throws SemanticException {
String functionName = root.getChild(0).getText().toLowerCase();
boolean isTemporary =
(root.getFirstChildWithType(HiveParser.TOK_TEMPORARY) != null);
+ boolean replace = (root.getFirstChildWithType(HiveParser.TOK_ORREPLACE) !=
null);
+ boolean ifNotExists =
(root.getFirstChildWithType(HiveParser.TOK_IFNOTEXISTS) != null);
+ if (ifNotExists && replace) {
+ throw new SemanticException("CREATE FUNCTION with both IF NOT EXISTS and
REPLACE is not allowed.");
Review Comment:
I see we are throwing a SemanticException when replace and if not exists are
used. This is what I was eluding to in the earlier comment. Should we prevent
this in the grammer instead of doing this? This probably provides a better
error message though.
--
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]