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
coprocessor/dag/expr: add some un-pushed builtin UDFs(Interval) #3330
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
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
Err(e) => return Err(e), | ||
Ok(None) => target, | ||
Ok(Some(v)) => v, | ||
}; |
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 we use self.children[mid].eval_int(ctx,row)?.unwrap_or(target);
instead?
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.
That would be awesome, thank you! @AndreMouche
@breeswish PTAL |
3c2f1fa
to
0ac71fa
Compare
} | ||
|
||
pub fn interval_real(&self, ctx: &mut EvalContext, row: &[Datum]) -> Result<Option<i64>> { | ||
let target = match self.children[0].eval_real(ctx, row) { |
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.
might be written as:
let target = match self.children[0].eval_real(ctx, row)? {
None => ...
Some(v) => ...
};
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.
Yes, thank you!
Ok(Some(v)) => v, | ||
}; | ||
|
||
let mut left = 1; |
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 our initial left is 1 while in TiDB i starts from 0?
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 code at TiDB side makes a slice that starts from 1 when passing args to binSearch
:
The code here initialize left
as 1 and return left - 1
as result, which should be the same as TiDB code. @breeswish
@@ -202,6 +202,60 @@ impl ScalarFunc { | |||
pub fn in_json(&self, ctx: &mut EvalContext, row: &[Datum]) -> Result<Option<i64>> { | |||
do_in(self, |v| v.eval_json(ctx, row), |l, r| Ok(l.cmp(r))) | |||
} | |||
|
|||
pub fn interval_int(&self, ctx: &mut EvalContext, row: &[Datum]) -> Result<Option<i64>> { | |||
let target = match self.children[0].eval_int(ctx, row) { |
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.
ditto.
0ac71fa
to
cc78a78
Compare
Comments addressed, thank you @breeswish |
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
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. Thank you!
@AndreMouche Please give an approval :) |
/run-integration-tests |
What have you changed? (mandatory)
implemented ScalarFuncSig::IntervalInt and ScalarFuncSig::IntervalReal
What are the type of the changes? (mandatory)
Improvement
How has this PR been tested? (mandatory)
added some UTs
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No
Does this PR affect tidb-ansible update? (mandatory)
No
Refer to a related PR or issue link (optional)
#3275