-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Enhancement] adjust translate function syntax structure to prevent parser performance rollback #54830
Conversation
new FunctionParams(false, visit(context.expression(), Expr.class)), pos); | ||
return SyntaxSugars.parse(functionCallExpr); | ||
} | ||
|
||
@Override | ||
public ParseNode visitAggregationFunctionCall(StarRocksParser.AggregationFunctionCallContext context) { | ||
NodePosition pos = createPos(context); |
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.
The most risky bug in this code is:
Potential incorrect handling of the expression()
method which could lead to runtime exceptions if it doesn't return a list that matches expected parameters for FunctionParams
.
You can modify the code like this:
@Override
public ParseNode visitTranslateFunctionCall(StarRocksParser.TranslateFunctionCallContext context) {
String fullFunctionName = "translate";
NodePosition pos = createPos(context);
List<Expr> expressionList = visit(context.expression(), Expr.class);
if (expressionList == null || expressionList.size() < expectedSize) {
// Handle error or exception appropriately
throw new IllegalArgumentException("Invalid number of arguments for translate function.");
}
FunctionName fnName = FunctionName.createFnName(fullFunctionName);
FunctionCallExpr functionCallExpr = new FunctionCallExpr(fnName,
new FunctionParams(false, expressionList), pos);
return SyntaxSugars.parse(functionCallExpr);
}
1f639cc
to
6b55173
Compare
…arser performance rollback Signed-off-by: stephen <[email protected]>
6b55173
to
8601bf5
Compare
Quality Gate passedIssues Measures |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.4 |
✅ Backports have been created
|
…arser performance rollback (#54830) Signed-off-by: stephen <[email protected]> (cherry picked from commit c1bc8d3)
…arser performance rollback (backport #54830) (#54856) Co-authored-by: stephen <[email protected]>
@Mergifyio backport branch-3.4.0-rc01 |
✅ Backports have been created
|
…arser performance rollback (#54830) Signed-off-by: stephen <[email protected]> (cherry picked from commit c1bc8d3) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocksLex.g4 # test/sql/test_agg/R/test_distinct_agg
@mergify backport branch-3.3 |
✅ Backports have been created
|
…arser performance rollback (#54830) Signed-off-by: stephen <[email protected]> (cherry picked from commit c1bc8d3) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4
…arser performance rollback (backport #54830) (#55514) Signed-off-by: yanz <[email protected]> Co-authored-by: stephen <[email protected]> Co-authored-by: yanz <[email protected]>
Why I'm doing:
parser performance rollback is introduced by this patch #54185
parser performance will rollback when there are many function call in query.
the parser of this case will take about 100ms.
bad case:
normal case:
What I'm doing:
Translate statement conflicts with translate function, so stripping translate function from simple function prevents performance rollback.
adjust translate function syntax structure and remove
getCharPositionInLine
fortranslate
to prevent parser performance rollback.base: 100ms
optimized: 4ms
Fixes #issue
https://github.com/StarRocks/StarRocksTest/issues/8932#issuecomment-2572967332
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: