-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Simplify date/datetime column predicate in certain cases #50643
Conversation
return new SubstrExtractor((CallOperator) call.getChild(0), value, 8).extractColumn(); | ||
} | ||
} | ||
} |
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:
Mismatch of function name in ReplaceAndSubstrExtractor#check when checking the empty string.
You can modify the code like this:
+ @Override
+ public boolean check() {
+ if (!(call.getChild(0) instanceof CallOperator && isSubstrFn((CallOperator) call.getChild(0)))) {
+ return false;
+ }
+ if (!call.getChild(1).isConstantRef() || !((ConstantOperator) call.getChild(1)).getVarchar().equals("-")) {
+ return false;
+ }
- if (!call.getChild(2).isConstantRef() || !((ConstantOperator) call.getChild(2)).getVarchar().isEmpty()) {
+ if (!call.getChild(2).isConstantRef() || !((ConstantOperator) call.getChild(2)).getVarchar().equals("")) {
return false;
+ }
+ // yyyyMMdd
+ if (value.getVarchar().length() != 8) {
+ return false;
+ }
+ return new SubstrExtractor((CallOperator) call.getChild(0), value, 8).check();
+ }
Explanation:
The original condition for verifying that the third argument to replace
is an empty string used .isEmpty()
method. However, to ensure consistency and correctness with the other comparisons, we should use .equals("")
to explicitly check for an empty string.
327938a
to
43c6cf3
Compare
please test date_format(t, '%Y%m%d') >= '20230400'. If the right constant value is a illegal date string, is the rewriten result same with before? |
But I will use regex to verify the right constant. |
Signed-off-by: kaijian.ding <[email protected]>
Signed-off-by: kaijian.ding <[email protected]>
Signed-off-by: kaijian.ding <[email protected]>
Signed-off-by: kaijian.ding <[email protected]>
I means clients may use |
@packy92 U r right, if right constant is not valid date, the result is not consitent with that before rewrite. I will verify the right constant is valid date |
Signed-off-by: kaijian.ding <[email protected]>
Quality Gate passedIssues Measures |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 88 / 91 (96.70%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@packy92 any more comment? |
@Mergifyio backport branch-3.3 |
✅ Backports have been created
|
#50643) Signed-off-by: kaijian.ding <[email protected]> (cherry picked from commit a8af0fc)
StarRocks#50643) Signed-off-by: kaijian.ding <[email protected]>
…s (backport #50643) (#50960) Co-authored-by: kaijianding <[email protected]>
StarRocks#50643) Signed-off-by: kaijian.ding <[email protected]> Signed-off-by: zhiminr.ren <[email protected]>
Why I'm doing:
Some user use
date/datetime
column as string, in this case sparse index is not used.This pr will do these rewrite
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
Checklist:
Bugfix cherry-pick branch check: