Skip to content

Commit b149310

Browse files
authored
coprocessor: move 'is_unsigned' to 'FieldTypeAccessor' (tikv#5095)
Signed-off-by: Lonng <heng@lonng.org>
1 parent e2c7184 commit b149310

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

components/cop_datatype/src/def/field_type.rs

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ pub trait FieldTypeAccessor {
193193
fn is_non_binary_string_like(&self) -> bool {
194194
self.collation() != Collation::Binary && self.is_string_like()
195195
}
196+
197+
/// Whether the flag contains `FieldTypeFlag::UNSIGNED`
198+
fn is_unsigned(&self) -> bool {
199+
self.flag().contains(FieldTypeFlag::UNSIGNED)
200+
}
196201
}
197202

198203
impl FieldTypeAccessor for FieldType {

src/coprocessor/dag/rpn_expr/impl_cast.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::convert::TryFrom;
44

55
use cop_codegen::rpn_fn;
6-
use cop_datatype::{EvalType, FieldTypeAccessor, FieldTypeFlag};
6+
use cop_datatype::{EvalType, FieldTypeAccessor};
77
use tipb::expression::FieldType;
88

99
use crate::coprocessor::codec::data_type::*;
@@ -23,7 +23,7 @@ pub fn get_cast_fn_rpn_node(
2323
let to = box_try!(EvalType::try_from(to_field_type.tp()));
2424
let func_meta = match (from, to) {
2525
(EvalType::Int, EvalType::Decimal) => {
26-
if !is_unsigned(from_field_type) && !is_unsigned(&to_field_type) {
26+
if !from_field_type.is_unsigned() && !to_field_type.is_unsigned() {
2727
cast_int_as_decimal_fn_meta()
2828
} else {
2929
cast_uint_as_decimal_fn_meta()
@@ -47,11 +47,6 @@ pub fn get_cast_fn_rpn_node(
4747
})
4848
}
4949

50-
#[inline]
51-
fn is_unsigned(ft: &FieldType) -> bool {
52-
ft.as_accessor().flag().contains(FieldTypeFlag::UNSIGNED)
53-
}
54-
5550
fn produce_dec_with_specified_tp(
5651
ctx: &mut EvalContext,
5752
dec: Decimal,

0 commit comments

Comments
 (0)