branch-4.1: [fix](udf) Reject variadic user-defined functions #67373 - #67524
Open
github-actions[bot] wants to merge 1 commit into
Open
branch-4.1: [fix](udf) Reject variadic user-defined functions #67373#67524github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
User-defined functions exposed variadic DDL metadata without reliable
end-to-end support. Reject variadic declarations during `CREATE
FUNCTION` analysis for scalar, aggregate, table, and alias functions
while retaining variadic signature parsing for `DROP`, `SHOW`, and
historical metadata compatibility.
before:
```sql
CREATE FUNCTION py_add(INT, INT, ...)
RETURNS INT
PROPERTIES (
"type" = "PYTHON_UDF",
"symbol" = "evaluate",
"runtime_version" = "3.12.11",
"volatility" = "immutable"
)
AS $$
def evaluate(a, b, c):
return a + b + c
$$;
SELECT py_add(1, 2, 3);
-- ERROR 1105 (HY000): errCode = 2, detailMessage = Index 2 out of bounds for length 2
```
In `PythonUdfBuilder.java:82`:
```java
public Pair<PythonUdf, PythonUdf> build(String name, List<?> arguments) {
// exprs = (1, 2, 3), size = 3
// argTypes = [INT, INT], size = 2
List<Expression> exprs = arguments.stream().map(Expression.class::cast).collect(Collectors.toList());
List<DataType> argTypes = udf.getSignatures().get(0).argumentsTypes;
List<Expression> processedExprs = Lists.newArrayList();
for (int i = 0; i < exprs.size(); ++i) {
// when i = 2, argTypes.get(2), err occur!
processedExprs.add(TypeCoercionUtils.castIfNotSameType(exprs.get(i), argTypes.get(i)));
}
return Pair.ofSame(udf.withFreshVolatileIdentity().withChildren(processedExprs));
}
```
now:
```sql
CREATE FUNCTION py_add(INT, INT, ...)
RETURNS INT
PROPERTIES (
"type" = "PYTHON_UDF",
"symbol" = "evaluate",
"runtime_version" = "3.12.11",
"volatility" = "immutable"
)
AS $$
def evaluate(a, b, c):
return a + b + c
$$;
-- ERROR 1105 (HY000): errCode = 2, detailMessage = mismatched input ',' expecting ')'(line 1, pos 31)
```
### Release note
Reject variadic declarations for user-defined functions.
### Check List (For Author)
- Test: Unit Test
- ./run-fe-ut.sh --run org.apache.doris.catalog.CreateFunctionTest
- Behavior changed: Yes. Variadic user-defined function declarations are
rejected during analysis.
- Does this need documentation:
apache/doris-website#4103
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-picked from #67373