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

[Feature] support named arguments for table functions #36596

Merged
merged 10 commits into from
Dec 15, 2023

Conversation

fzhedu
Copy link
Contributor

@fzhedu fzhedu commented Dec 7, 2023

support named arguments for table functions, keep the same behavior with Trino:

  1. all parameters should be named arguments, without mixing positional arguments;
  2. can mix default parameters
  3. can reorder named arguments
MySQL > select * from TABLE(generate_series(start=>2, end=>5, step=>2));
+-----------------+
| generate_series |
+-----------------+
|               2 |
|               4 |
+-----------------+

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.2
    • 3.1
    • 3.0
    • 2.5

doc

continue;
}
if (!Type.isImplicitlyCastable(other.argTypes[i], getVarArgsType(), true)) {
if (!Type.isImplicitlyCastable(other.argTypes[i], this.argTypes[i], true)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrong flags

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 8, 2023
Copy link
Contributor

@imay imay left a comment

Choose a reason for hiding this comment

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

Please tell people why and what you are doing in this CL.

Comment on lines +9 to +28
select * from TABLE(generate_series(start=>2, stop=>5));
-- result:
E: (1064, "Getting analyzing error. Detail message: Unknown table function 'generate_series(start=>2,stop=>5)', the function doesn't support named arguments or has invalid arguments.")
Copy link
Contributor

Choose a reason for hiding this comment

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

step is an optional argument, why it is not supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the second should be end, not stop, invalid arguments.

@@ -0,0 +1,12 @@
-- name: test named arguments for table functions

select * from TABLE(generate_series(start=>2, end=>5));
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add tests to cover normal cases.
I see all cases are fail cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@fzhedu fzhedu requested review from packy92 and imay December 11, 2023 09:57
@@ -2158,6 +2158,7 @@ expression
| NOT expression #logicalNot
| left=expression operator=(AND|LOGICAL_AND) right=expression #logicalBinary
| left=expression operator=(OR|LOGICAL_OR) right=expression #logicalBinary
| identifier '=>' expression #namedArgument
Copy link
Contributor

Choose a reason for hiding this comment

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

add it in functioncall is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

or new a special expression ArgumentExpression to resolve all function arguments? adding here will contaminate all expressions

Copy link
Contributor

Choose a reason for hiding this comment

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

is param1 => param2 => value_expr valid?

Copy link
Contributor

Choose a reason for hiding this comment

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

may use a new rule like expression ('=>' expression) ? to decribe the item in table fucntion arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

introduce namedArgumentList to narrow scop needed.
param1 => param2 => value_expr is invalid.

Comment on lines 422 to 434
boolean[] mask = new boolean[other.argTypes.length];
for (int j = startArgIndex; j < other.argTypes.length; ++j) {
boolean found = false;
for (int i = startArgIndex; i < this.argTypes.length; ++i) {
if (!mask[i] && this.argNames[i].equals(other.argNames[j])) {
if (!other.argTypes[j].matchesType(this.argTypes[i]) &&
!Type.isImplicitlyCastable(other.argTypes[j], this.argTypes[i], true)) {
return false;
}
found = true;
mask[i] = true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe you need extract some method, like getArgumentByName ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaned.

Comment on lines +109 to +112
@SerializedName(value = "argNames")
private String[] argNames;

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, why don't support a special class to resolve arguments? may be we need support all function in future? separate to handle the arguments and name isn't a sustainable practice

Copy link
Contributor

Choose a reason for hiding this comment

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

and if we need support postiation arguments and name arguments at sametime, define a unified abstraction is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding named argumetns seems change a few codes, seems no need add new class.

packy92
packy92 previously approved these changes Dec 14, 2023
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

22 New issues
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

[FE Incremental Coverage Report]

fail : 145 / 183 (79.23%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/ast/AstVisitor.java 0 1 00.00% [1256]
🔵 com/starrocks/sql/analyzer/ExpressionAnalyzer.java 0 1 00.00% [1957]
🔵 com/starrocks/analysis/NamedArgument.java 6 16 37.50% [29, 30, 31, 32, 43, 44, 48, 53, 58, 63]
🔵 com/starrocks/catalog/Function.java 83 109 76.15% [184, 543, 554, 555, 557, 558, 559, 560, 562, 563, 567, 568, 569, 571, 572, 576, 579, 580, 590, 728, 729, 730, 764, 765, 766, 767]
🔵 com/starrocks/catalog/FunctionSet.java 2 2 100.00% []
🔵 com/starrocks/analysis/FunctionParams.java 25 25 100.00% []
🔵 com/starrocks/analysis/Expr.java 5 5 100.00% []
🔵 com/starrocks/sql/analyzer/QueryAnalyzer.java 13 13 100.00% []
🔵 com/starrocks/catalog/TableFunction.java 11 11 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@kangkaisen kangkaisen merged commit 33578e5 into StarRocks:main Dec 15, 2023
44 of 45 checks passed
Zhangg7723 pushed a commit to Zhangg7723/starrocks that referenced this pull request Dec 26, 2023
Signed-off-by: Zhuhe Fang <fzhedu@gmail.com>
Signed-off-by: 张敢 <zhanggan@deepexi.com>
@banmoy banmoy mentioned this pull request Feb 13, 2025
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation META-REVIEW
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants