[ https://issues.apache.org/jira/browse/HIVE-26314?focusedWorklogId=781834&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-781834 ]
ASF GitHub Bot logged work on HIVE-26314: ----------------------------------------- Author: ASF GitHub Bot Created on: 15/Jun/22 20:46 Start Date: 15/Jun/22 20:46 Worklog Time Spent: 10m Work Description: 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. Issue Time Tracking ------------------- Worklog Id: (was: 781834) Time Spent: 50m (was: 40m) > Support alter function in Hive DDL > ---------------------------------- > > Key: HIVE-26314 > URL: https://issues.apache.org/jira/browse/HIVE-26314 > Project: Hive > Issue Type: Task > Components: Hive > Affects Versions: 4.0.0-alpha-1 > Reporter: Wechar > Assignee: Wechar > Priority: Minor > Labels: pull-request-available > Fix For: 4.0.0-alpha-2 > > Time Spent: 50m > Remaining Estimate: 0h > > Hive SQL does not support {{*ALTER FUNCTION*}} yet, we can refer to the > {{*CREATE [OR REPLACE] FUNCTION*}} of > [Spark|https://spark.apache.org/docs/3.1.2/sql-ref-syntax-ddl-create-function.html] > to implement the alter function . > {code:sql} > CREATE [ TEMPORARY ] FUNCTION [ OR REPLACE ] [IF NOT EXISTS ] > [db_name.]function_name AS class_name > [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ]; > {code} > * *OR REPLACE* > If specified, the resources for the function are reloaded. This is mainly > useful to pick up any changes made to the implementation of the function. > This parameter is mutually exclusive to {{*IF NOT EXISTS*}} and can not be > specified together. -- This message was sent by Atlassian Jira (v8.20.7#820007)