Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 committed Jan 9, 2025
1 parent 0a53743 commit d2a0fdf
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,13 @@ passwordOption
;

functionArguments
: functionArgument (COMMA functionArgument)*
: DOTDOTDOT
| dataTypeList
| dataTypeList COMMA DOTDOTDOT
;

functionArgument
: DOTDOTDOT
| dataType
dataTypeList
: dataType (COMMA dataType)*
;

supportedSetStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import org.apache.doris.nereids.DorisParser.CreateViewContext;
import org.apache.doris.nereids.DorisParser.CreateWorkloadGroupContext;
import org.apache.doris.nereids.DorisParser.CteContext;
import org.apache.doris.nereids.DorisParser.DataTypeListContext;
import org.apache.doris.nereids.DorisParser.DataTypeWithNullableContext;
import org.apache.doris.nereids.DorisParser.DecimalLiteralContext;
import org.apache.doris.nereids.DorisParser.DeleteContext;
Expand Down Expand Up @@ -158,8 +159,8 @@
import org.apache.doris.nereids.DorisParser.ExportContext;
import org.apache.doris.nereids.DorisParser.FixedPartitionDefContext;
import org.apache.doris.nereids.DorisParser.FromClauseContext;
import org.apache.doris.nereids.DorisParser.FunctionArgumentContext;
import org.apache.doris.nereids.DorisParser.FunctionArgumentsContext;
import org.apache.doris.nereids.DorisParser.FunctionIdentifierContext;
import org.apache.doris.nereids.DorisParser.GroupingElementContext;
import org.apache.doris.nereids.DorisParser.GroupingSetContext;
import org.apache.doris.nereids.DorisParser.HavingClauseContext;
Expand Down Expand Up @@ -4140,9 +4141,7 @@ public Command visitCreateUserDefineFunction(CreateUserDefineFunctionContext ctx
boolean ifNotExists = ctx.EXISTS() != null;
boolean isAggFunction = ctx.AGGREGATE() != null;
boolean isTableFunction = ctx.TABLES() != null;
String functionName = ctx.functionIdentifier().functionNameIdentifier().getText();
String dbName = ctx.functionIdentifier().dbName != null ? ctx.functionIdentifier().dbName.getText() : null;
FunctionName function = new FunctionName(dbName, functionName);
FunctionName function = visitFunctionIdentifier(ctx.functionIdentifier());
FunctionArgTypesInfo functionArgTypesInfo;
if (ctx.functionArguments() != null) {
functionArgTypesInfo = visitFunctionArguments(ctx.functionArguments());
Expand All @@ -4167,9 +4166,7 @@ public Command visitCreateUserDefineFunction(CreateUserDefineFunctionContext ctx
public Command visitCreateAliasFunction(CreateAliasFunctionContext ctx) {
SetType statementScope = visitStatementScope(ctx.statementScope());
boolean ifNotExists = ctx.EXISTS() != null;
String functionName = ctx.functionIdentifier().functionNameIdentifier().getText();
String dbName = ctx.functionIdentifier().dbName != null ? ctx.functionIdentifier().dbName.getText() : null;
FunctionName function = new FunctionName(dbName, functionName);
FunctionName function = visitFunctionIdentifier(ctx.functionIdentifier());
FunctionArgTypesInfo functionArgTypesInfo;
if (ctx.functionArguments() != null) {
functionArgTypesInfo = visitFunctionArguments(ctx.functionArguments());
Expand All @@ -4187,9 +4184,7 @@ public Command visitCreateAliasFunction(CreateAliasFunctionContext ctx) {
public Command visitDropFunction(DropFunctionContext ctx) {
SetType statementScope = visitStatementScope(ctx.statementScope());
boolean ifExists = ctx.EXISTS() != null;
String functionName = ctx.functionIdentifier().functionNameIdentifier().getText();
String dbName = ctx.functionIdentifier().dbName != null ? ctx.functionIdentifier().dbName.getText() : null;
FunctionName function = new FunctionName(dbName, functionName);
FunctionName function = visitFunctionIdentifier(ctx.functionIdentifier());
FunctionArgTypesInfo functionArgTypesInfo;
if (ctx.functionArguments() != null) {
functionArgTypesInfo = visitFunctionArguments(ctx.functionArguments());
Expand All @@ -4201,24 +4196,31 @@ public Command visitDropFunction(DropFunctionContext ctx) {

@Override
public FunctionArgTypesInfo visitFunctionArguments(FunctionArgumentsContext ctx) {
boolean isVariadic = false;
List<DataType> argTypeDefs = new ArrayList<>(4);
for (Object child : ctx.children) {
if (child instanceof FunctionArgumentContext) {
DataType dataType = visitFunctionArgument((FunctionArgumentContext) child);
if (dataType != null) {
argTypeDefs.add(dataType.conversion());
} else {
isVariadic = true;
}
}
boolean isVariadic = ctx.DOTDOTDOT() != null;
List<DataType> argTypeDefs;
if (ctx.dataTypeList() != null) {
argTypeDefs = visitDataTypeList(ctx.dataTypeList());
} else {
argTypeDefs = new ArrayList<>();
}
return new FunctionArgTypesInfo(argTypeDefs, isVariadic);
}

@Override
public DataType visitFunctionArgument(FunctionArgumentContext ctx) {
return ctx.dataType() != null ? typedVisit(ctx.dataType()) : null;
public FunctionName visitFunctionIdentifier(FunctionIdentifierContext ctx) {
String functionName = ctx.functionNameIdentifier().getText();
String dbName = ctx.dbName != null ? ctx.dbName.getText() : null;
return new FunctionName(dbName, functionName);
}

@Override
public List<DataType> visitDataTypeList(DataTypeListContext ctx) {
List<DataType> dataTypeList = new ArrayList<>(ctx.getChildCount());
for (DorisParser.DataTypeContext dataTypeContext : ctx.dataType()) {
DataType dataType = typedVisit(dataTypeContext);
dataTypeList.add(dataType.conversion());
}
return dataTypeList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,42 +110,42 @@
*/
public class CreateFunctionCommand extends Command implements ForwardWithSync {
@Deprecated
public static final String OBJECT_FILE_KEY = "object_file";
public static final String FILE_KEY = "file";
public static final String SYMBOL_KEY = "symbol";
public static final String PREPARE_SYMBOL_KEY = "prepare_fn";
public static final String CLOSE_SYMBOL_KEY = "close_fn";
public static final String MD5_CHECKSUM = "md5";
public static final String INIT_KEY = "init_fn";
public static final String UPDATE_KEY = "update_fn";
public static final String MERGE_KEY = "merge_fn";
public static final String SERIALIZE_KEY = "serialize_fn";
public static final String FINALIZE_KEY = "finalize_fn";
public static final String GET_VALUE_KEY = "get_value_fn";
public static final String REMOVE_KEY = "remove_fn";
public static final String BINARY_TYPE = "type";
public static final String EVAL_METHOD_KEY = "evaluate";
public static final String CREATE_METHOD_NAME = "create";
public static final String DESTROY_METHOD_NAME = "destroy";
public static final String ADD_METHOD_NAME = "add";
public static final String SERIALIZE_METHOD_NAME = "serialize";
public static final String MERGE_METHOD_NAME = "merge";
public static final String GETVALUE_METHOD_NAME = "getValue";
public static final String STATE_CLASS_NAME = "State";
private static final String OBJECT_FILE_KEY = "object_file";
private static final String FILE_KEY = "file";
private static final String SYMBOL_KEY = "symbol";
private static final String PREPARE_SYMBOL_KEY = "prepare_fn";
private static final String CLOSE_SYMBOL_KEY = "close_fn";
private static final String MD5_CHECKSUM = "md5";
private static final String INIT_KEY = "init_fn";
private static final String UPDATE_KEY = "update_fn";
private static final String MERGE_KEY = "merge_fn";
private static final String SERIALIZE_KEY = "serialize_fn";
private static final String FINALIZE_KEY = "finalize_fn";
private static final String GET_VALUE_KEY = "get_value_fn";
private static final String REMOVE_KEY = "remove_fn";
private static final String BINARY_TYPE = "type";
private static final String EVAL_METHOD_KEY = "evaluate";
private static final String CREATE_METHOD_NAME = "create";
private static final String DESTROY_METHOD_NAME = "destroy";
private static final String ADD_METHOD_NAME = "add";
private static final String SERIALIZE_METHOD_NAME = "serialize";
private static final String MERGE_METHOD_NAME = "merge";
private static final String GETVALUE_METHOD_NAME = "getValue";
private static final String STATE_CLASS_NAME = "State";
// add for java udf check return type nullable mode, always_nullable or always_not_nullable
public static final String IS_RETURN_NULL = "always_nullable";
private static final String IS_RETURN_NULL = "always_nullable";
// iff is static load, BE will be cache the udf class load, so only need load once
public static final String IS_STATIC_LOAD = "static_load";
public static final String EXPIRATION_TIME = "expiration_time";
private static final String IS_STATIC_LOAD = "static_load";
private static final String EXPIRATION_TIME = "expiration_time";

// timeout for both connection and read. 10 seconds is long enough.
private static final int HTTP_TIMEOUT_MS = 10000;
private SetType setType = SetType.DEFAULT;
private final SetType setType;
private final boolean ifNotExists;
private final FunctionName functionName;
private final boolean isAggregate;
private final boolean isAlias;
private boolean isTableFunction;
private final boolean isTableFunction;
private final FunctionArgTypesInfo argsDef;
private final DataType returnType;
private DataType intermediateType;
Expand Down Expand Up @@ -238,7 +238,7 @@ private void analyze(ConnectContext ctx) throws Exception {
analyzeCommon(ctx);
// check
if (isAggregate) {
analyzeUda();
analyzeUdaf();
} else if (isAlias) {
analyzeAliasFunction(ctx);
} else if (isTableFunction) {
Expand All @@ -251,7 +251,7 @@ private void analyze(ConnectContext ctx) throws Exception {
analyzeCommon(ctx);
// check
if (isAggregate) {
analyzeUda();
analyzeUdaf();
} else if (isAlias) {
analyzeAliasFunction(ctx);
} else if (isTableFunction) {
Expand All @@ -276,7 +276,7 @@ private void analyzeCommon(ConnectContext ctx) throws AnalysisException {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}
// check argument
argsDef.validate();
argsDef.analyze();

// alias function does not need analyze following params
if (isAlias) {
Expand Down Expand Up @@ -399,7 +399,7 @@ private void analyzeUdtf() throws AnalysisException {
// normal and one is outer as those have different result when result is NULL.
}

private void analyzeUda() throws AnalysisException {
private void analyzeUdaf() throws AnalysisException {
AggregateFunction.AggregateFunctionBuilder builder = AggregateFunction.AggregateFunctionBuilder
.createUdfBuilder();
URI location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class DropFunctionCommand extends Command implements ForwardWithSync {
private final boolean ifExists;
private final FunctionName functionName;
private final FunctionArgTypesInfo argsDef;
// set after analyzed
private FunctionSearchDesc function;

/**
* DropFunctionCommand
Expand All @@ -71,8 +69,8 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}
argsDef.validate();
function = new FunctionSearchDesc(functionName, argsDef.getArgTypes(), argsDef.isVariadic());
argsDef.analyze();
FunctionSearchDesc function = new FunctionSearchDesc(functionName, argsDef.getArgTypes(), argsDef.isVariadic());
if (SetType.GLOBAL.equals(setType)) {
Env.getCurrentEnv().getGlobalFunctionMgr().dropFunction(function, ifExists);
} else {
Expand All @@ -94,7 +92,6 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
LOG.info("clean udf cache in be {}, beId {}", backend.getHost(), backend.getId());
}
AgentTaskExecutor.submit(batchTask);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean isVariadic() {
/**
* validate
*/
public void validate() {
public void analyze() {
argTypes = new Type[argTypeDefs.size()];
int i = 0;
for (DataType dataType : argTypeDefs) {
Expand Down

0 comments on commit d2a0fdf

Please sign in to comment.