-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[TABLE MODEL] Implement CREATE/SHOW/DROP Function and user-defined scalar function #14223
base: master
Are you sure you want to change the base?
Conversation
What a spectacular work 🦾! Fabulous design and implementation, LGTM! ⚡️⚡️🔥 |
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
|
||
public class ScalarFunctionConfig extends UDFConfigurations { | ||
|
||
public ScalarFunctionConfig setOutputDataType(Type outputDataType) { |
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.
all public methods are visible to users, so we need to add java doc to explain the functionality.
public List<Type> getChildExpressionDataTypes() { | ||
return childExpressionDataTypes; | ||
} | ||
|
||
public int getChildExpressionsSize() { | ||
return childExpressionDataTypes.size(); | ||
} | ||
|
||
public Type getDataType(int index) { | ||
return childExpressionDataTypes.get(index); | ||
} | ||
|
||
public boolean hasSystemAttribute(String attributeKey) { | ||
return systemAttributes.containsKey(attributeKey); | ||
} | ||
|
||
public Map<String, String> getSystemAttributes() { | ||
return systemAttributes; | ||
} |
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.
all public methods are visible to users, so we need to add java doc to explain the functionality.
void validate(FunctionParameters parameters) throws Exception; | ||
|
||
/** | ||
* This method is mainly used to initialize {@link ScalarFunction}. In this method, the user can |
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.
* This method is mainly used to initialize {@link ScalarFunction}. In this method, the user can | |
* This method is mainly used to initialize {@link ScalarFunction} and set the output data type. In this method, the user can |
/** | ||
* Returns the object value at the specified column in this row. | ||
* | ||
* @param columnIndex index of the specified column | ||
* @return the object value at the specified column in this row | ||
*/ | ||
Object getObject(int columnIndex); |
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.
/** | |
* Returns the object value at the specified column in this row. | |
* | |
* @param columnIndex index of the specified column | |
* @return the object value at the specified column in this row | |
*/ | |
Object getObject(int columnIndex); |
UDFDataTypeTransformer.transformUDFDataTypeToReadType(config.getOutputDataType()); | ||
return new UserDefineScalarFunctionTransformer( | ||
returnType, scalarFunction, childrenColumnTransformer); | ||
} | ||
} | ||
throw new IllegalArgumentException(String.format("Unknown function: %s", functionName)); |
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.
add current DatanodeId in error msg. You can get that from IoTDBDescriptor.getInstance().getConfig().getDataNodeId()
} else { | ||
if (TableUDFUtils.tryGetScalarFunction(udfInformation.getFunctionName()) != null) { | ||
return BINARY_MAP.get(FUNCTION_TYPE_USER_DEFINED_SCALAR_FUNC); | ||
} else if (TableUDFUtils.tryGetAggregateFunction(udfInformation.getFunctionName()) | ||
!= null) { | ||
return BINARY_MAP.get(FUNCTION_TYPE_USER_DEFINED_AGG_FUNC); | ||
} else if (TableUDFUtils.tryGetTableFunction(udfInformation.getFunctionName()) != null) { | ||
return BINARY_MAP.get(FUNCTION_TYPE_USER_DEFINED_TABLE_FUNC); | ||
} |
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.
Each show functions, we need to reflect a UDF class to judge what type it's....
Why not store that in UDFInformation
@@ -627,7 +630,26 @@ && isIntegerNumber(argumentTypes.get(2)))) { | |||
// ignore | |||
} | |||
|
|||
// TODO scalar UDF function | |||
// User-defined scalar function | |||
ScalarFunction scalarFunction = TableUDFUtils.tryGetScalarFunction(functionName); |
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.
we may add new method instead of calling UDFManagementService.reflect
which will print warn log in that.
@@ -70,4 +75,14 @@ public enum TableBuiltinScalarFunction { | |||
public String getFunctionName() { | |||
return functionName; | |||
} | |||
|
|||
private static final Set<String> NATIVE_FUNCTION_NAMES = |
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.
private static final Set<String> NATIVE_FUNCTION_NAMES = | |
private static final Set<String> BUILT_IN_SCALAR_FUNCTION_NAMES = |
.map(TableBuiltinScalarFunction::getFunctionName) | ||
.collect(Collectors.toList())); | ||
|
||
public static Set<String> getNativeFunctionNames() { |
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.
public static Set<String> getNativeFunctionNames() { | |
public static Set<String> getBuiltInScalarFunctionNames() { |
public class TableUDFUtils { | ||
public static ScalarFunction tryGetScalarFunction(String functionName) { | ||
try { | ||
return UDFManagementService.getInstance().reflect(functionName, ScalarFunction.class); |
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.
may also need to add a method in UDFManagementService
, like tryReflect
to avoid print warn logs
Description
https://timechor.feishu.cn/docx/GXnNdt3XIok3CQxBvwWcZxrnntd
This pull request introduces several new user-defined functions (UDFs) and corresponding integration tests for the IoTDB project. The changes include the addition of new scalar functions, updates to existing classes, and the creation of new test cases to ensure the functionality and robustness of the UDF management system.
New Scalar Functions:
ScalarFunctionExample
: Implements a scalar function that checks if any input value is null and returns a boolean result.Integration Tests:
IoTDBSQLFunctionManagementIT
: Adds multiple test cases to verify the creation, display, and deletion of scalar functions, including handling of invalid function names and URIs.