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.
+18 −3
Diff settings

Always

Just for now

@@ -26,6 +26,7 @@ use self::compare::CmpOp;
use std::io;
use std::borrow::Cow;
use std::string::FromUtf8Error;
use chrono::FixedOffset;
use tipb::expression::{Expr, ExprType, FieldType, ScalarFuncSig};
@@ -379,6 +380,15 @@ impl Expression {
.map(Datum::F64)
.map(|e| Expression::new_const(e, tp))
.map_err(Error::from),
ExprType::MysqlTime => expr.get_val()
.decode_u64()
.and_then(|ts| {

This comment has been minimized.

@BusyJay

BusyJay Aug 24, 2017

Contributor

ts is confusing considering this is not a timestamp actually.

@BusyJay

BusyJay Aug 24, 2017

Contributor

ts is confusing considering this is not a timestamp actually.

let fsp = expr.get_field_type().get_decimal() as i8;
let tp = expr.get_field_type().get_tp() as u8;
Time::from_packed_u64(ts, tp, fsp, &FixedOffset::east(0))

This comment has been minimized.

@BusyJay

BusyJay Aug 24, 2017

Contributor

Should use timezone from context.

@BusyJay

BusyJay Aug 24, 2017

Contributor

Should use timezone from context.

})
.map(|t| Expression::new_const(Datum::Time(t), tp))
.map_err(Error::from),
ExprType::MysqlDuration => expr.get_val()
.decode_i64()
.and_then(|n| Duration::from_nanos(n, MAX_FSP))
@@ -424,6 +434,7 @@ impl Expression {
#[cfg(test)]
mod test {
use coprocessor::codec::Datum;
use coprocessor::codec::mysql::{Time, MAX_FSP};
use coprocessor::select::xeval::evaluator::test::{col_expr, datum_expr};
use tipb::expression::{Expr, ExprType, FieldType, ScalarFuncSig};
use super::Expression;
@@ -447,14 +458,18 @@ mod test {
#[test]
fn test_expression_build() {
let colref = col_expr(1);
let constant = datum_expr(Datum::Null);
let const_null = datum_expr(Datum::Null);
let const_time = datum_expr(Datum::Time(
Time::parse_utc_datetime("1970-01-01 12:00:00", MAX_FSP).unwrap(),
));
let tests = vec![
(colref.clone(), 1, false),
(colref.clone(), 2, true),
(constant.clone(), 0, true),
(const_null.clone(), 0, true),
(const_time.clone(), 0, true),
(
fncall_expr(ScalarFuncSig::LTInt, &[colref.clone(), constant.clone()]),
fncall_expr(ScalarFuncSig::LTInt, &[colref.clone(), const_null.clone()]),
2,
true,
),
ProTip! Use n and p to navigate between commits in a pull request.