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

[TABLE MODEL] Implement CREATE/SHOW/DROP Function and user-defined scalar function #14223

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

Cpaulyz
Copy link
Contributor

@Cpaulyz Cpaulyz commented Nov 27, 2024

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.

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 2.29358% with 213 lines in your changes missing coverage. Please review.

Project coverage is 39.59%. Comparing base (b34b714) to head (30be7e5).

Files with missing lines Patch % Lines
...n/execution/config/metadata/ShowFunctionsTask.java 0.00% 58 Missing ⚠️
...otdb/commons/udf/utils/UDFDataTypeTransformer.java 0.00% 38 Missing ⚠️
...olumn/udf/UserDefineScalarFunctionTransformer.java 0.00% 36 Missing ⚠️
...pache/iotdb/commons/udf/access/RecordIterator.java 0.00% 22 Missing ⚠️
...execution/relational/ColumnTransformerBuilder.java 0.00% 14 Missing ⚠️
...ne/plan/relational/metadata/TableMetadataImpl.java 0.00% 14 Missing ⚠️
.../apache/iotdb/commons/udf/utils/TableUDFUtils.java 0.00% 10 Missing ⚠️
...yengine/plan/relational/sql/parser/AstBuilder.java 0.00% 9 Missing ⚠️
.../plan/execution/config/TableConfigTaskVisitor.java 0.00% 6 Missing ⚠️
...otdb/commons/udf/service/UDFManagementService.java 20.00% 4 Missing ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14223      +/-   ##
============================================
- Coverage     39.62%   39.59%   -0.04%     
  Complexity       71       71              
============================================
  Files          4242     4245       +3     
  Lines        270437   270647     +210     
  Branches      32792    32813      +21     
============================================
- Hits         107165   107152      -13     
- Misses       163272   163495     +223     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lancelly
Copy link
Contributor

What a spectacular work 🦾! Fabulous design and implementation, LGTM! ⚡️⚡️🔥

Copy link

sonarcloud bot commented Nov 28, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

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) {
Copy link
Contributor

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.

Comment on lines +37 to +55
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;
}
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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

Comment on lines +113 to +119
/**
* 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* 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));
Copy link
Contributor

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()

Comment on lines +263 to +271
} 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);
}
Copy link
Contributor

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);
Copy link
Contributor

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 =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants