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

coprocessor/dag/expr: add some un-pushed builtin UDFs(Interval) #3330

Merged
merged 14 commits into from Aug 6, 2018

Conversation

bb7133
Copy link
Contributor

@bb7133 bb7133 commented Jul 18, 2018

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

@sre-bot
Copy link
Contributor

sre-bot commented Jul 18, 2018

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.

Copy link
Member

@AndreMouche AndreMouche left a 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,
};
Copy link
Member

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?

Copy link
Contributor Author

@bb7133 bb7133 Jul 20, 2018

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

@AndreMouche
Copy link
Member

@breeswish PTAL

}

pub fn interval_real(&self, ctx: &mut EvalContext, row: &[Datum]) -> Result<Option<i64>> {
let target = match self.children[0].eval_real(ctx, row) {
Copy link
Member

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) => ...
};

Copy link
Contributor Author

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;
Copy link
Member

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?

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 code at TiDB side makes a slice that starts from 1 when passing args to binSearch:

https://github.com/pingcap/tidb/blob/cef80b3da390b8b35c703546c54cda9a251a18de/expression/builtin_compare.go#L841

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) {
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

@bb7133
Copy link
Contributor Author

bb7133 commented Jul 24, 2018

Comments addressed, thank you @breeswish

@bb7133 bb7133 closed this Jul 24, 2018
@bb7133 bb7133 reopened this Jul 24, 2018
@sre-bot
Copy link
Contributor

sre-bot commented Jul 24, 2018

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.

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@breezewish
Copy link
Member

@AndreMouche Please give an approval :)

@AndreMouche AndreMouche added sig/coprocessor SIG: Coprocessor contribution Type: PR - From contributors labels Aug 3, 2018
@AndreMouche
Copy link
Member

/run-integration-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Type: PR - From contributors sig/coprocessor SIG: Coprocessor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants