You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/06/15 20:46:19 UTC
[GitHub] [hive] nrg4878 commented on a diff in pull request #3360: HIVE-26314: Support alter function in Hive DDL statement
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: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org