New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HIVE-26314: Support alter function in Hive DDL statement #3360
Conversation
@check-spelling-bot Report🔴 Please reviewSee the files view or the action log for details. Unrecognized words (3)api Previously acknowledged words that are now absentaarry timestamplocal yyyyAvailable dictionaries could cover words not in the dictionarycspell:cpp/cpp.txt (104293) covers 81 of them Consider adding them using:
To stop checking additional dictionaries, add:
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the git@github.com:wecharyu/hive.git repository
If the flagged items do not appear to be textIf items relate to a ...
|
boolean addToMetastoreSuccess = addToMetastore(dbName, functionName, registeredName); | ||
if (!addToMetastoreSuccess) { | ||
// TODO: should this use getUserFromAuthenticator instead of SessionState.get().getUserName()? | ||
Function function = new Function(functionName, dbName, desc.getClassName(), SessionState.get().getUserName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How security is handled for altering the functions?
Malicious users could wreak havoc if they change a function implementation behind the scenes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add OWNER_PRIV
for altering function? Then only the owner of this function can do alter operation.
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wecharyu This grammer syntax seems inconsistent with what we have for views.
"create or replace view " where as for functions it would be
"create function or replace "
also the grammer supports the syntax below
create function or replace if not exists
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrg4878 The reason I use "create function or replace" is that “create or replace" can only be used for one statement, I will get error like below when I use "create or replace function":
org.apache.hadoop.hive.ql.parse.ParseException: line 3:18 mismatched input 'function' expecting KW_VIEW near 'replace' in create view statement
I am not sure if antlr3
does not support this syntax in two statements, if you have any idea please let me know.
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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both syntaxes look good to me, currently this syntax is just similar to Spark.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
What changes were proposed in this pull request?
Hive SQL does not support ALTER FUNCTION yet, we can refer to the CREATE [OR REPLACE] FUNCTION of Spark to implement the alter function .
Why are the changes needed?
To support alter udf.
Does this PR introduce any user-facing change?
Yes, need change the DDL statement document in the Hive WIKI.
How was this patch tested?
We add a qtest
create_or_replace_function.q
, can be test by command:mvn test -Dtest=TestMiniLlapLocalCliDriver -Dqfile=create_or_replace_function.q