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: support decode Time from tipb.Expr #2199

Merged
merged 43 commits into from Aug 28, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+10 −36
Diff settings

Always

Just for now

Viewing a subset of changes. View all

improve

  • Loading branch information...
hicqu committed Aug 18, 2017
commit 5f9679d4ed462a28d7b257c9a0cab2c6e162a857
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{f64, i64, u64};
use std::{f64, i64};
use std::borrow::Cow;
use coprocessor::codec::Datum;
use coprocessor::codec::mysql::Decimal;
@@ -46,23 +46,15 @@ impl FnCall {
pub fn plus_int(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
if (l > 0 && r > i64::MAX - l) || (l < 0 && r < i64::MIN - l) {
return Err(Error::Overflow);
}
Ok(l + r)
})
do_arithmetic(lhs, rhs, |l, r| l.checked_add(r).ok_or(Error::Overflow))
}
pub fn plus_uint(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
let (l, r) = (l as u64, r as u64);
if l > u64::MAX - r {
return Err(Error::Overflow);
}
Ok((l + r) as i64)
let res = (l as u64).checked_add(r as u64).ok_or(Error::Overflow);
res.map(|u| u as i64)
})
}
@@ -94,23 +86,15 @@ impl FnCall {
pub fn minus_int(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
if (l > 0 && -r > i64::MAX - l) || (l < 0 && -r < i64::MIN - l) {
return Err(Error::Overflow);
}
Ok(l + r)
})
do_arithmetic(lhs, rhs, |l, r| l.checked_sub(r).ok_or(Error::Overflow))
}
pub fn minus_uint(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
let (l, r) = (l as u64, r as u64);
if l < r {
return Err(Error::Overflow);
}
Ok((l - r) as i64)
let res = (l as u64).checked_sub(r as u64).ok_or(Error::Overflow);
res.map(|u| u as i64)
})
}
@@ -142,25 +126,15 @@ impl FnCall {
pub fn multiply_int(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
let res = l * r;
if l != 0 && res / l != r {
return Err(Error::Overflow);
}
Ok(res)
})
do_arithmetic(lhs, rhs, |l, r| l.checked_mul(r).ok_or(Error::Overflow))
}
pub fn multiply_uint(&self, ctx: &StatementContext, row: &[Datum]) -> Result<Option<i64>> {
let lhs = try!(self.children[0].eval_int(ctx, row));
let rhs = try!(self.children[1].eval_int(ctx, row));
do_arithmetic(lhs, rhs, |l, r| {
let (l, r) = (l as u64, r as u64);
let res = l * r;
if l != 0 && res / l != r {
return Err(Error::Overflow);
}
Ok(res as i64)
let res = (l as u64).checked_mul(r as u64).ok_or(Error::Overflow);
res.map(|u| u as i64)
})
}
}
ProTip! Use n and p to navigate between commits in a pull request.