Skip to content

Commit

Permalink
coprocessor: move 'is_unsigned' to 'FieldTypeAccessor' (tikv#5095)
Browse files Browse the repository at this point in the history
Signed-off-by: Lonng <heng@lonng.org>
  • Loading branch information
lonng committed Jul 16, 2019
1 parent e2c7184 commit b149310
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions components/cop_datatype/src/def/field_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ pub trait FieldTypeAccessor {
fn is_non_binary_string_like(&self) -> bool {
self.collation() != Collation::Binary && self.is_string_like()
}

/// Whether the flag contains `FieldTypeFlag::UNSIGNED`
fn is_unsigned(&self) -> bool {
self.flag().contains(FieldTypeFlag::UNSIGNED)
}
}

impl FieldTypeAccessor for FieldType {
Expand Down
9 changes: 2 additions & 7 deletions src/coprocessor/dag/rpn_expr/impl_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::convert::TryFrom;

use cop_codegen::rpn_fn;
use cop_datatype::{EvalType, FieldTypeAccessor, FieldTypeFlag};
use cop_datatype::{EvalType, FieldTypeAccessor};
use tipb::expression::FieldType;

use crate::coprocessor::codec::data_type::*;
Expand All @@ -23,7 +23,7 @@ pub fn get_cast_fn_rpn_node(
let to = box_try!(EvalType::try_from(to_field_type.tp()));
let func_meta = match (from, to) {
(EvalType::Int, EvalType::Decimal) => {
if !is_unsigned(from_field_type) && !is_unsigned(&to_field_type) {
if !from_field_type.is_unsigned() && !to_field_type.is_unsigned() {
cast_int_as_decimal_fn_meta()
} else {
cast_uint_as_decimal_fn_meta()
Expand All @@ -47,11 +47,6 @@ pub fn get_cast_fn_rpn_node(
})
}

#[inline]
fn is_unsigned(ft: &FieldType) -> bool {
ft.as_accessor().flag().contains(FieldTypeFlag::UNSIGNED)
}

fn produce_dec_with_specified_tp(
ctx: &mut EvalContext,
dec: Decimal,
Expand Down

0 comments on commit b149310

Please sign in to comment.