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.
+31 −34
Diff settings

Always

Just for now

Viewing a subset of changes. View all

fMerge branch 'master' into qupeng/expr-time

  • Loading branch information...
hicqu committed Aug 24, 2017
commit bdcefe8dc97eb49596f98182b46a0eb34b32e62e
@@ -98,7 +98,7 @@ impl FnCall {
(false, true) => if lhs >= 0 {
(lhs as u64).checked_sub(rhs as u64).map(|t| t as i64)
} else {
None
return Err(Error::Overflow);
},
(false, false) => lhs.checked_sub(rhs),
};
@@ -131,41 +131,19 @@ impl FnCall {
let rhs = try_opt!(self.children[1].eval_int(ctx, row));
let lus = mysql::has_unsigned_flag(self.children[0].get_tp().get_flag());
let rus = mysql::has_unsigned_flag(self.children[1].get_tp().get_flag());
let (mut a_neg, mut b_neg) = (false, false);
let (mut l, mut r) = (lhs as u64, rhs as u64);
if !lus && lhs < 0 {
a_neg = true;
l = opp_neg!(lhs);
}
if !rus && rhs < 0 {
b_neg = true;
r = opp_neg!(rhs);
}
let res = try!(l.checked_mul(r).ok_or(Error::Overflow));
let us = mysql::has_unsigned_flag(self.tp.get_flag());
if a_neg != b_neg {
if us || (i64::MAX as u64 + 1 < res) {
return Err(Error::Overflow);
}
let mut res = res as i64;
if res >= 0 {
// The number less than i64::MAX as u64 + 1.
res = try!(res.checked_neg().ok_or(Error::Overflow));
}
Ok(Some(res))
let u64_mul_i64 = |u, s| if s >= 0 {
(u as u64).checked_mul(s as u64).map(|t| t as i64)
} else {
Ok(Some(res as i64))
}
}
}
#[inline]
fn check_integer_overflow(us: bool, res: i64, res_us: bool) -> Result<Option<i64>> {
if (us && !res_us && res < 0) || (!us && res_us && res as u64 > i64::MAX as u64) {
return Err(Error::Overflow);
None
};
let res = match (lus, rus) {
(true, true) => (lhs as u64).checked_mul(rhs as u64).map(|t| t as i64),
(false, false) => lhs.checked_mul(rhs),
(true, false) => u64_mul_i64(lhs, rhs),
(false, true) => u64_mul_i64(rhs, lhs),
};
res.ok_or(Error::Overflow).map(Some)
}
Ok(Some(res))
}
#[cfg(test)]
@@ -75,6 +75,12 @@ impl FnCall {
ScalarFuncSig::MultiplyReal |
ScalarFuncSig::MultiplyDecimal |
ScalarFuncSig::MultiplyInt |
ScalarFuncSig::IfNullInt |
ScalarFuncSig::IfNullReal |
ScalarFuncSig::IfNullString |
ScalarFuncSig::IfNullDecimal |
ScalarFuncSig::IfNullTime |
ScalarFuncSig::IfNullDuration |
ScalarFuncSig::LogicalAnd |
ScalarFuncSig::LogicalOr |
ScalarFuncSig::LogicalXor => (2, 2),
@@ -97,6 +103,13 @@ impl FnCall {
ScalarFuncSig::TimeIsNull |
ScalarFuncSig::DurationIsNull => (1, 1),
ScalarFuncSig::IfInt |
ScalarFuncSig::IfReal |
ScalarFuncSig::IfString |
ScalarFuncSig::IfDecimal |
ScalarFuncSig::IfTime |
ScalarFuncSig::IfDuration => (3, 3),
_ => unimplemented!(),
};
if args < min_args || args > max_args {
@@ -246,6 +246,9 @@ impl Expression {
ScalarFuncSig::MinusReal => f.minus_real(ctx, row),
ScalarFuncSig::MultiplyReal => f.multiply_real(ctx, row),
ScalarFuncSig::IfNullReal => f.if_null_real(ctx, row),
ScalarFuncSig::IfReal => f.if_real(ctx, row),
_ => Err(Error::Other("Unknown signature")),
},
}
@@ -264,6 +267,9 @@ impl Expression {
ScalarFuncSig::MinusDecimal => f.minus_decimal(ctx, row),
ScalarFuncSig::MultiplyDecimal => f.multiply_decimal(ctx, row),
ScalarFuncSig::IfNullDecimal => f.if_null_decimal(ctx, row),
ScalarFuncSig::IfDecimal => f.if_decimal(ctx, row),
_ => Err(Error::Other("Unknown signature")),
},
}
You are viewing a condensed version of this merge commit. You can view the full changes here.
ProTip! Use n and p to navigate between commits in a pull request.