提交 7179b825 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix alias with schema check in Parser.parseCreateFunctionAlias()

上级 057a1da4
......@@ -5114,19 +5114,12 @@ public class Parser {
private CreateFunctionAlias parseCreateFunctionAlias(boolean force) {
boolean ifNotExists = readIfNotExists();
final boolean newAliasSameNameAsBuiltin = Function.getFunction(database, currentToken) != null;
String aliasName;
if (database.isAllowBuiltinAliasOverride() && newAliasSameNameAsBuiltin) {
aliasName = currentToken;
schemaName = session.getCurrentSchemaName();
read();
} else {
aliasName = readIdentifierWithSchema();
}
String aliasName = readIdentifierWithSchema();
final boolean newAliasSameNameAsBuiltin = Function.getFunction(database, aliasName) != null;
if (database.isAllowBuiltinAliasOverride() && newAliasSameNameAsBuiltin) {
// fine
} else if (isKeyword(aliasName) ||
Function.getFunction(database, aliasName) != null ||
newAliasSameNameAsBuiltin ||
getAggregateType(aliasName) != null) {
throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1,
aliasName);
......
......@@ -49,3 +49,54 @@ SELECT ALIAS_NAME, JAVA_CLASS, JAVA_METHOD, DATA_TYPE, COLUMN_COUNT, RETURNS_RES
DROP ALIAS MY_SQRT;
> ok
CREATE SCHEMA TEST_SCHEMA;
> ok
CREATE ALIAS TRUNC FOR "java.lang.Math.floor(double)";
> exception
CREATE ALIAS PUBLIC.TRUNC FOR "java.lang.Math.floor(double)";
> exception
CREATE ALIAS TEST_SCHEMA.TRUNC FOR "java.lang.Math.round(double)";
> exception
SET BUILTIN_ALIAS_OVERRIDE=1;
> ok
CREATE ALIAS TRUNC FOR "java.lang.Math.floor(double)";
> ok
DROP ALIAS TRUNC;
> ok
CREATE ALIAS PUBLIC.TRUNC FOR "java.lang.Math.floor(double)";
> ok
CREATE ALIAS TEST_SCHEMA.TRUNC FOR "java.lang.Math.round(double)";
> ok
SELECT PUBLIC.TRUNC(1.5);
>> 1.0
SELECT PUBLIC.TRUNC(-1.5);
>> -2.0
SELECT TEST_SCHEMA.TRUNC(1.5);
>> 2
SELECT TEST_SCHEMA.TRUNC(-1.5);
>> -1
DROP ALIAS PUBLIC.TRUNC;
> ok
DROP ALIAS TEST_SCHEMA.TRUNC;
> ok
SET BUILTIN_ALIAS_OVERRIDE=0;
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论