Skip to content
Permalink
Browse files

Simplify some code using field type converts. (#4649)

Signed-off-by: Breezewish <breezewish@pingcap.com>
  • Loading branch information...
breeswish committed May 8, 2019
1 parent 0609d44 commit 73c549573c351ef45b13a12663f693fc2cf2ac65
@@ -287,9 +287,6 @@ mod tests {
fn test_lazy_batch_column_clone() {
use cop_datatype::FieldTypeTp;

let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Long);

let mut col = LazyBatchColumn::raw_with_capacity(5);
assert!(col.is_raw());
assert_eq!(col.len(), 0);
@@ -306,7 +303,7 @@ mod tests {
{
// Empty raw to empty decoded.
let mut col = col.clone();
col.decode(&Tz::utc(), &ft).unwrap();
col.decode(&Tz::utc(), &FieldTypeTp::Long.into()).unwrap();
assert!(col.is_decoded());
assert_eq!(col.len(), 0);
assert_eq!(col.capacity(), 5);
@@ -346,7 +343,7 @@ mod tests {
assert_eq!(col.raw()[1].as_slice(), datum_raw_2.as_slice());
}
// Non-empty raw to non-empty decoded.
col.decode(&Tz::utc(), &ft).unwrap();
col.decode(&Tz::utc(), &FieldTypeTp::Long.into()).unwrap();
assert!(col.is_decoded());
assert_eq!(col.len(), 2);
assert_eq!(col.capacity(), 5);
@@ -471,11 +468,9 @@ mod benches {
column.push_raw(datum_raw.as_slice());
}

let mut ft = tipb::expression::FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
let tz = Tz::utc();

column.decode(&tz, &ft).unwrap();
column
.decode(&Tz::utc(), &FieldTypeTp::LongLong.into())
.unwrap();

b.iter(|| {
test::black_box(test::black_box(&column).clone());
@@ -499,8 +494,7 @@ mod benches {
column.push_raw(datum_raw.as_slice());
}

let mut ft = tipb::expression::FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
let ft = FieldTypeTp::LongLong.into();
let tz = Tz::utc();

b.iter(|| {
@@ -528,8 +522,7 @@ mod benches {
column.push_raw(datum_raw.as_slice());
}

let mut ft = tipb::expression::FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
let ft = FieldTypeTp::LongLong.into();
let tz = Tz::utc();

column.decode(&tz, &ft).unwrap();
@@ -215,7 +215,7 @@ impl std::ops::DerefMut for LazyBatchColumnVec {
mod tests {
use super::*;

use cop_datatype::{EvalType, FieldTypeAccessor};
use cop_datatype::EvalType;

use crate::coprocessor::codec::datum::{Datum, DatumEncoder};

@@ -268,26 +268,10 @@ mod tests {

for comparable in &[true, false] {
let schema = [
{
// Column 1: Long
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Long);
ft
},
{
// Column 2: Double
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Double);
ft
},
{
// Column 3: VarChar
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::VarChar);
ft
},
FieldTypeTp::Long.into(),
FieldTypeTp::Double.into(),
FieldTypeTp::VarChar.into(),
];

let values = vec![
vec![Datum::U64(1), Datum::F64(1.0), Datum::Null],
vec![Datum::Null, Datum::Null, Datum::Bytes(vec![0u8, 2u8])],
@@ -355,21 +339,7 @@ mod tests {
fn test_retain_rows_by_index() {
use cop_datatype::FieldTypeTp;

let schema = [
{
// Column 1: Long
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Long);
ft
},
{
// Column 2: Double
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Double);
ft
},
];

let schema = [FieldTypeTp::Long.into(), FieldTypeTp::Double.into()];
let mut columns = LazyBatchColumnVec::with_raw_columns(2);
assert_eq!(columns.rows_len(), 0);
assert_eq!(columns.columns_len(), 2);
@@ -957,8 +957,7 @@ mod benches {
let mut datum_raw: Vec<u8> = Vec::new();
DatumEncoder::encode(&mut datum_raw, &[Datum::U64(0xDEADBEEF)], true).unwrap();

let mut field_type = tipb::expression::FieldType::new();
field_type.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
let field_type = FieldTypeTp::LongLong.into();
let tz = Tz::utc();

b.iter(move || {
@@ -247,7 +247,6 @@ mod tests {

use cop_datatype::{FieldTypeAccessor, FieldTypeTp};
use kvproto::coprocessor::KeyRange;
use tipb::expression::FieldType;
use tipb::schema::ColumnInfo;

use crate::coprocessor::codec::mysql::Tz;
@@ -293,21 +292,9 @@ mod tests {

// The schema of these columns. Used to check executor output.
let schema = vec![
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::Double);
ft
},
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
FieldTypeTp::LongLong.into(),
FieldTypeTp::Double.into(),
FieldTypeTp::LongLong.into(),
];

// Case 1. Normal index.
@@ -66,7 +66,7 @@ mod tests {
use crate::coprocessor::codec::data_type::VectorValue;
use crate::coprocessor::dag::exec_summary::*;
use crate::coprocessor::dag::expr::EvalConfig;
use cop_datatype::{EvalType, FieldTypeAccessor, FieldTypeTp};
use cop_datatype::{EvalType, FieldTypeTp};
use tipb::expression::FieldType;

struct MockExecutor {
@@ -77,12 +77,6 @@ mod tests {
cfg: EvalConfig,
}

fn field_type(ft: FieldTypeTp) -> FieldType {
let mut f = FieldType::new();
f.as_mut_accessor().set_tp(ft);
f
}

impl MockExecutor {
/// create the MockExecutor with fixed schema and data.
fn new() -> MockExecutor {
@@ -93,11 +87,10 @@ mod tests {
(5, None, Some(0.1)),
(6, None, Some(4.5)),
];

let field_types = vec![
field_type(FieldTypeTp::LongLong),
field_type(FieldTypeTp::LongLong),
field_type(FieldTypeTp::Double),
FieldTypeTp::LongLong.into(),
FieldTypeTp::LongLong.into(),
FieldTypeTp::Double.into(),
];

MockExecutor {
@@ -1,12 +1,12 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

mod index_scan_executor;
mod limit;
mod limit_executor;
mod selection_executor;
mod table_scan_executor;
mod util;

pub use self::index_scan_executor::BatchIndexScanExecutor;
pub use self::limit::BatchLimitExecutor;
pub use self::limit_executor::BatchLimitExecutor;
pub use self::selection_executor::BatchSelectionExecutor;
pub use self::table_scan_executor::BatchTableScanExecutor;
@@ -326,12 +326,6 @@ mod tests {
use crate::coprocessor::util::convert_to_prefix_next;
use crate::storage::{FixtureStore, Key};

fn field_type(ft: FieldTypeTp) -> FieldType {
let mut f = FieldType::new();
f.as_mut_accessor().set_tp(ft);
f
}

/// Test Helper for normal test with fixed schema and data.
/// Table Schema: ID (INT, PK), Foo (INT), Bar (FLOAT, Default 4.5)
/// Column id: 1, 2, 4
@@ -429,9 +423,9 @@ mod tests {
];

let field_types = vec![
field_type(FieldTypeTp::LongLong),
field_type(FieldTypeTp::LongLong),
field_type(FieldTypeTp::Double),
FieldTypeTp::LongLong.into(),
FieldTypeTp::LongLong.into(),
FieldTypeTp::Double.into(),
];

let store = {
@@ -725,23 +719,10 @@ mod tests {
ci
},
];

let schema = vec![
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
FieldTypeTp::LongLong.into(),
FieldTypeTp::LongLong.into(),
FieldTypeTp::LongLong.into(),
];

let mut kv = vec![];
@@ -843,19 +824,7 @@ mod tests {
ci
},
];

let schema = vec![
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
{
let mut ft = FieldType::new();
ft.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
ft
},
];
let schema = vec![FieldTypeTp::LongLong.into(), FieldTypeTp::LongLong.into()];

let mut kv = vec![];
{

0 comments on commit 73c5495

Please sign in to comment.
You can’t perform that action at this time.