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.
+43 −12
Diff settings

Always

Just for now

Viewing a subset of changes. View all
@@ -13,6 +13,7 @@
use std::{f64, i64, u64};
use std::borrow::Cow;
use std::ops::{Add, Mul, Sub};
use coprocessor::codec::{mysql, Datum};
use coprocessor::codec::mysql::Decimal;
use super::{Error, FnCall, Result, StatementContext};
@@ -35,7 +36,7 @@ impl FnCall {
) -> Result<Option<Cow<'a, Decimal>>> {
let lhs = try_opt!(self.children[0].eval_decimal(ctx, row));
let rhs = try_opt!(self.children[1].eval_decimal(ctx, row));
let result: Result<Decimal> = (lhs.as_ref() + rhs.as_ref()).into();
let result: Result<Decimal> = lhs.add(&rhs).into();
result.map(|t| Some(Cow::Owned(t)))
}
@@ -78,7 +79,7 @@ impl FnCall {
) -> Result<Option<Cow<'a, Decimal>>> {
let lhs = try_opt!(self.children[0].eval_decimal(ctx, row));
let rhs = try_opt!(self.children[1].eval_decimal(ctx, row));
let result: Result<Decimal> = (lhs.as_ref() - rhs.as_ref()).into();
let result: Result<Decimal> = lhs.sub(&rhs).into();
result.map(Cow::Owned).map(Some)
}
@@ -121,7 +122,7 @@ impl FnCall {
) -> Result<Option<Cow<'a, Decimal>>> {
let lhs = try_opt!(self.children[0].eval_decimal(ctx, row));
let rhs = try_opt!(self.children[1].eval_decimal(ctx, row));
let result: Result<Decimal> = (lhs.as_ref() * rhs.as_ref()).into();
let result: Result<Decimal> = lhs.mul(&rhs).into();
result.map(Cow::Owned).map(Some)
}
@@ -142,11 +143,16 @@ impl FnCall {
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 (i64::MAX as u64) < res {
if us || (i64::MAX as u64 + 1 < res) {
return Err(Error::Overflow);
}
let res = try!((res as i64).checked_neg().ok_or(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))
} else {
Ok(Some(res as i64))
@@ -224,6 +230,12 @@ mod test {
Datum::I64(1),
Datum::I64(12),
),
(
ScalarFuncSig::MultiplyInt,
Datum::I64(i64::MIN),
Datum::I64(1),
Datum::I64(i64::MIN),
),
];
let ctx = StatementContext::default();
for tt in tests {
@@ -321,7 +333,7 @@ mod test {
}
#[test]
fn test_arithmetic_int_overflow() {
fn test_arithmetic_overflow_int() {
let tests = vec![
(
ScalarFuncSig::PlusInt,
@@ -357,6 +369,11 @@ mod test {
Datum::U64(u64::MAX),
Datum::I64(i64::MAX),
),
(
ScalarFuncSig::MultiplyInt,
Datum::I64(i64::MIN),
Datum::U64(1),
),
];
let ctx = StatementContext::default();
for tt in tests {
@@ -379,7 +396,7 @@ mod test {
}
#[test]
fn test_arithmetic_real_overflow() {
fn test_arithmetic_overflow_real() {
let tests = vec![
(
ScalarFuncSig::PlusReal,
View
@@ -287,7 +287,7 @@ mod tests {
thread::sleep(interval);
// Expire the cache, and the address will be refreshed.
{
let s = runner.store_addrs.get_mut(&store_id).unwrap();
let mut s = runner.store_addrs.get_mut(&store_id).unwrap();
let now = Instant::now();
s.last_update = now.sub(Duration::from_secs(STORE_ADDRESS_REFRESH_SECONDS + 1));
}
@@ -285,7 +285,7 @@ impl<'a> Insert<'a> {
self.execute_with_ctx(Context::new())
}
fn execute_with_ctx(self, ctx: Context) -> i64 {
fn execute_with_ctx(mut self, ctx: Context) -> i64 {
let handle = self.values
.get(&self.table.handle_id)
.cloned()
@@ -466,7 +466,7 @@ impl<'a> Delete<'a> {
}
}
fn execute(self, id: i64, row: Vec<Datum>) {
fn execute(mut self, id: i64, row: Vec<Datum>) {
let mut values = HashMap::new();
for (&id, v) in self.table.cols.keys().zip(row) {
values.insert(id, v);
@@ -41,7 +41,7 @@ impl Split {
impl PdMocker for Split {
fn get_members(&self, _: &GetMembersRequest) -> Option<Result<GetMembersResponse>> {
let mut holder = self.inner.lock().unwrap();
let inner = holder.as_mut().unwrap();
let mut inner = holder.as_mut().unwrap();
inner.idx += 1;
info!(
"[Split] get_member: {:?}",
View
@@ -642,6 +642,7 @@ fn test_leader_election_with_config(pre_vote: bool) {
StateRole::Leader,
1,
),
// three logs futher along than 0, but in the same term so rejection
// are returned instead of the votes being ignored.
(
@@ -941,6 +942,7 @@ fn test_log_replicatioin() {
vec![new_message(1, 1, MessageType::MsgPropose, 1)],
2,
),
(
Network::new(vec![None, None, None]),
vec![
@@ -1338,6 +1340,7 @@ fn test_commit() {
(vec![1], vec![empty_entry(1, 1)], 2, 0),
(vec![2], vec![empty_entry(1, 1), empty_entry(2, 2)], 2, 2),
(vec![1], vec![empty_entry(2, 1)], 2, 1),
// odd
(
vec![2, 1, 1],
@@ -1363,6 +1366,7 @@ fn test_commit() {
2,
0,
),
// even
(
vec![2, 1, 1, 1],
@@ -1492,12 +1496,14 @@ fn test_handle_msg_append() {
// Ensure 1
(nm(2, 3, 2, 3, None), 2, 0, true), // previous log mismatch
(nm(2, 3, 3, 3, None), 2, 0, true), // previous log non-exist
// Ensure 2
(nm(2, 1, 1, 1, None), 2, 1, false),
(nm(2, 0, 0, 1, Some(vec![(1, 2)])), 1, 1, false),
(nm(2, 2, 2, 3, Some(vec![(3, 2), (4, 2)])), 4, 3, false),
(nm(2, 2, 2, 4, Some(vec![(3, 2)])), 3, 3, false),
(nm(2, 1, 1, 4, Some(vec![(2, 2)])), 2, 2, false),
// Ensure 3
(nm(1, 1, 1, 3, None), 2, 1, false), // match entry 1, commit up to last new entry 1
(nm(1, 1, 1, 3, Some(vec![(2, 2)])), 2, 2, false), // match entry 1, commit up to last new
@@ -1729,20 +1735,25 @@ fn test_recv_msg_request_vote_for_type(msg_type: MessageType) {
(StateRole::Follower, 0, 1, INVALID_ID, true),
(StateRole::Follower, 0, 2, INVALID_ID, true),
(StateRole::Follower, 0, 3, INVALID_ID, false),
(StateRole::Follower, 1, 0, INVALID_ID, true),
(StateRole::Follower, 1, 1, INVALID_ID, true),
(StateRole::Follower, 1, 2, INVALID_ID, true),
(StateRole::Follower, 1, 3, INVALID_ID, false),
(StateRole::Follower, 2, 0, INVALID_ID, true),
(StateRole::Follower, 2, 1, INVALID_ID, true),
(StateRole::Follower, 2, 2, INVALID_ID, false),
(StateRole::Follower, 2, 3, INVALID_ID, false),
(StateRole::Follower, 3, 0, INVALID_ID, true),
(StateRole::Follower, 3, 1, INVALID_ID, true),
(StateRole::Follower, 3, 2, INVALID_ID, false),
(StateRole::Follower, 3, 3, INVALID_ID, false),
(StateRole::Follower, 3, 2, 2, false),
(StateRole::Follower, 3, 2, 1, true),
(StateRole::Leader, 3, 3, 1, true),
(StateRole::PreCandidate, 3, 3, 1, true),
(StateRole::Candidate, 3, 3, 1, true),
@@ -1811,6 +1822,7 @@ fn test_state_transition() {
INVALID_ID,
),
(StateRole::Follower, StateRole::Leader, false, 0, INVALID_ID),
(
StateRole::PreCandidate,
StateRole::Follower,
@@ -1833,6 +1845,7 @@ fn test_state_transition() {
INVALID_ID,
),
(StateRole::PreCandidate, StateRole::Leader, true, 0, 1),
(
StateRole::Candidate,
StateRole::Follower,
@@ -1855,6 +1868,7 @@ fn test_state_transition() {
INVALID_ID,
),
(StateRole::Candidate, StateRole::Leader, true, 0, 1),
(StateRole::Leader, StateRole::Follower, true, 1, INVALID_ID),
(
StateRole::Leader,
@@ -1873,7 +1887,7 @@ fn test_state_transition() {
(StateRole::Leader, StateRole::Leader, true, 0, 1),
];
for (i, (from, to, wallow, wterm, wlead)) in tests.drain(..).enumerate() {
let sm: &mut Raft<MemStorage> = &mut new_test_raft(1, vec![1], 10, 1, new_storage());
let mut sm: &mut Raft<MemStorage> = &mut new_test_raft(1, vec![1], 10, 1, new_storage());
sm.state = from;
let res = recover_safe!(|| {
ProTip! Use n and p to navigate between commits in a pull request.