Skip to content
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

Use drop and create to replace a function on Hive Metastore #24010

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,11 @@ public void createFunction(Function function)
public void alterFunction(Function function)
throws TException
{
client.alterFunction(prependCatalogToDbName(catalogName, function.getDbName()), function.getFunctionName(), function);
// Hive 3 does not actually replace the content of the function
// https://github.com/apache/hive/blob/rel/release-3.1.2/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java#L9310
// Fall back to use drop & create for doing the replace function operation
dropFunction(function.getDbName(), function.getFunctionName());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative would be to throw an NOT_SUPPORTED TrinoException in io.trino.plugin.hive.metastore.thrift.BridgingHiveMetastore#replaceFunction but this would make the CREATE OR REPLACE a bit cumbersome - it would succeed when the function does not exist and it would fail when the function already exists.

createFunction(function);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1987,9 +1987,12 @@ public void testCreateFunction()
String name = "test_" + randomNameSuffix();
String name2 = "test_" + randomNameSuffix();

assertUpdate("CREATE FUNCTION " + name + "(x integer) RETURNS bigint COMMENT 't42' RETURN x * 42");
assertUpdate("CREATE FUNCTION " + name + "(x integer) RETURNS bigint RETURN x * 10");
assertQuery("SELECT " + name + "(99)", "SELECT 990");

assertUpdate("CREATE OR REPLACE FUNCTION " + name + "(x integer) RETURNS bigint COMMENT 't42' RETURN x * 42");
assertQuery("SELECT " + name + "(99)", "SELECT 4158");

assertQueryFails("SELECT " + name + "(2.9)", ".*Unexpected parameters.*");

assertUpdate("CREATE FUNCTION " + name + "(x double) RETURNS double COMMENT 't88' RETURN x * 8.8");
Expand Down