-
Notifications
You must be signed in to change notification settings - Fork 5.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
expression: handle zero date in date_add()
#20015
expression: handle zero date in date_add()
#20015
Conversation
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
/rebuild |
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
/rebuild |
@ichn-hu Could you please have a look at the code? |
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.
Could you please add some tests for this PR?
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
I found that when the second argument is invalid, TiDB miss an warning:
Because this is not related to the current issue, I will not fix it here. |
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
1 similar comment
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
@XuHuaiyu What would be a possible reward for this issue? |
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
/reward 300 |
Reward success. |
@@ -3416,6 +3416,11 @@ func (b *builtinAddDateStringStringSig) evalTime(row chunk.Row) (types.Time, boo | |||
return types.ZeroTime, true, err |
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.
VecEvalTime should also be modified, you can check the following example in MySQL and TiDB
set @@sql_mode='';
create table t(a datetime);
insert into t values('0000-00-00 00:00:00');
select date_add(a, interval 2020 year) from t;
But it'll be ok to fix this in another PR.
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.
@XuHuaiyu @SunRunAway I think this vectorized function should also be fixed, but it may be too many changes for a single PR. To have a cleaner handling of this issue, a refactor of the code may be necessary. For example, I put the valid check in all the add_date
functions, but I saw that there is little differences among all the implemented functions. If you think it is better to fix it in the same PR, I will do it. But I will prefer to open a new one for it.
@@ -3449,6 +3454,11 @@ func (b *builtinAddDateStringIntSig) evalTime(row chunk.Row) (types.Time, bool, | |||
return types.ZeroTime, true, err | |||
} | |||
|
|||
if invalidDate := date.InvalidZero(); invalidDate { |
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.
Is it better to be incorporated into b.getDateFromString
?
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.
I think it will help to remove the redundant check in the caller function, but it depends on the context to determine whether zeroDate is valid. For example, adddate('0000-00-00', interval 1 day)
is invalid becuase the first zero, while adddate('2000-10-11', 0)
is valid with the second argument as a zero. It should be better leave to the caller function, but my current fix is not elegant.
@@ -3449,6 +3454,11 @@ func (b *builtinAddDateStringIntSig) evalTime(row chunk.Row) (types.Time, bool, | |||
return types.ZeroTime, true, err | |||
} | |||
|
|||
if invalidDate := date.InvalidZero(); invalidDate { |
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.
Should this change be ported into vectorized implementation like builtinAddDateStringIntSig.vecEvalTime
? And add more test cases for vectorized situation?
I think that handle the vec-cases in another PR is acceptable. |
date_add()
/pick-up |
It is not a pickable issue! DetailsTip : If you want this issue to be picked, you need to add a Warning: None |
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.
LGTM
In master branch 49791bc,
But the following case hasn't fixed.
|
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.
Why not add error handle in getDateFromXXXXXX ang vecGetDateFromXXXXXX? For your comment, #20015 (comment), I can't get your point.
The second argument will convert to interval, not datetime. So zero value will not cause error..
It has been a while since I submitted this PR, I will take a look recently. |
@zhangysh1995 any update? |
I think a clarification on the scope of this PR is needed. First I want to fix for the non-vectorization case, then the vectorized case is required. Later because the master is fixed, and the latest review requires a refactor of my fix. I think I need a clear goal now for this PR. If a refactor and the additional feature should be fixed, I would consider close this one and open another. @wshwsh12 @XuHuaiyu What are your comments? |
@zhangysh1995 from @wshwsh12 's comment I think this PR doesn't fix the issue. There are still two unanswered questions:
You can update the PR to fix the specific issue reported in #15234, regardless any further requirement. |
@zhangysh1995: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
需求变动比较大,现在没精力改这个 PR 了,希望重新 assign 。 |
What problem does this PR solve?
Issue Number: close #15234
Problem Summary:
What is changed and how it works?
What's Changed:
NULL
when the first date is invalidHow it Works:
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note