Skip to content
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: move 'is_unsigned' to 'FieldTypeAccessor' #5095

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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