Skip to content

Commit 1650fdd

Browse files
qrilkaTed-Jiang
authored andcommitted
Remove redundant is_numeric for DataType (apache#7734)
It's available in arrow-rs since version 3.0.0 Resolves apache#1613
1 parent 1575815 commit 1650fdd

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

datafusion/expr/src/type_coercion/binary.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use arrow::datatypes::{
2727
use datafusion_common::Result;
2828
use datafusion_common::{plan_err, DataFusionError};
2929

30-
use crate::type_coercion::is_numeric;
3130
use crate::Operator;
3231

3332
/// The type signature of an instantiation of binary expression
@@ -310,10 +309,10 @@ pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
310309
fn string_numeric_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
311310
use arrow::datatypes::DataType::*;
312311
match (lhs_type, rhs_type) {
313-
(Utf8, _) if is_numeric(rhs_type) => Some(Utf8),
314-
(LargeUtf8, _) if is_numeric(rhs_type) => Some(LargeUtf8),
315-
(_, Utf8) if is_numeric(lhs_type) => Some(Utf8),
316-
(_, LargeUtf8) if is_numeric(lhs_type) => Some(LargeUtf8),
312+
(Utf8, _) if rhs_type.is_numeric() => Some(Utf8),
313+
(LargeUtf8, _) if rhs_type.is_numeric() => Some(LargeUtf8),
314+
(_, Utf8) if lhs_type.is_numeric() => Some(Utf8),
315+
(_, LargeUtf8) if lhs_type.is_numeric() => Some(LargeUtf8),
317316
_ => None,
318317
}
319318
}
@@ -365,7 +364,7 @@ fn comparison_binary_numeric_coercion(
365364
rhs_type: &DataType,
366365
) -> Option<DataType> {
367366
use arrow::datatypes::DataType::*;
368-
if !is_numeric(lhs_type) || !is_numeric(rhs_type) {
367+
if !lhs_type.is_numeric() || !rhs_type.is_numeric() {
369368
return None;
370369
};
371370

@@ -563,14 +562,18 @@ fn create_decimal256_type(precision: u8, scale: i8) -> DataType {
563562
fn both_numeric_or_null_and_numeric(lhs_type: &DataType, rhs_type: &DataType) -> bool {
564563
use arrow::datatypes::DataType::*;
565564
match (lhs_type, rhs_type) {
566-
(_, Null) => is_numeric(lhs_type),
567-
(Null, _) => is_numeric(rhs_type),
565+
(_, Null) => lhs_type.is_numeric(),
566+
(Null, _) => rhs_type.is_numeric(),
568567
(Dictionary(_, lhs_value_type), Dictionary(_, rhs_value_type)) => {
569-
is_numeric(lhs_value_type) && is_numeric(rhs_value_type)
568+
lhs_value_type.is_numeric() && rhs_value_type.is_numeric()
570569
}
571-
(Dictionary(_, value_type), _) => is_numeric(value_type) && is_numeric(rhs_type),
572-
(_, Dictionary(_, value_type)) => is_numeric(lhs_type) && is_numeric(value_type),
573-
_ => is_numeric(lhs_type) && is_numeric(rhs_type),
570+
(Dictionary(_, value_type), _) => {
571+
value_type.is_numeric() && rhs_type.is_numeric()
572+
}
573+
(_, Dictionary(_, value_type)) => {
574+
lhs_type.is_numeric() && value_type.is_numeric()
575+
}
576+
_ => lhs_type.is_numeric() && rhs_type.is_numeric(),
574577
}
575578
}
576579

datafusion/expr/src/type_coercion/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ pub fn is_null(dt: &DataType) -> bool {
5858
*dt == DataType::Null
5959
}
6060

61-
/// Determine whether the given data type `dt` represents numeric values.
62-
pub fn is_numeric(dt: &DataType) -> bool {
63-
is_signed_numeric(dt)
64-
|| matches!(
65-
dt,
66-
DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64
67-
)
68-
}
69-
7061
/// Determine whether the given data type `dt` is a `Timestamp`.
7162
pub fn is_timestamp(dt: &DataType) -> bool {
7263
matches!(dt, DataType::Timestamp(_, _))

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use datafusion_expr::type_coercion::functions::data_types;
4141
use datafusion_expr::type_coercion::other::{
4242
get_coerce_type_for_case_expression, get_coerce_type_for_list,
4343
};
44-
use datafusion_expr::type_coercion::{is_datetime, is_numeric, is_utf8_or_large_utf8};
44+
use datafusion_expr::type_coercion::{is_datetime, is_utf8_or_large_utf8};
4545
use datafusion_expr::{
4646
is_false, is_not_false, is_not_true, is_not_unknown, is_true, is_unknown,
4747
type_coercion, window_function, AggregateFunction, BuiltinScalarFunction, Expr,
@@ -496,7 +496,7 @@ fn coerce_window_frame(
496496
let target_type = match window_frame.units {
497497
WindowFrameUnits::Range => {
498498
if let Some(col_type) = current_types.first() {
499-
if is_numeric(col_type) || is_utf8_or_large_utf8(col_type) {
499+
if col_type.is_numeric() || is_utf8_or_large_utf8(col_type) {
500500
col_type
501501
} else if is_datetime(col_type) {
502502
&DataType::Interval(IntervalUnit::MonthDayNano)

0 commit comments

Comments
 (0)