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

Remove redundant is_numeric for DataType #7734

Merged
merged 1 commit into from
Oct 4, 2023
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
27 changes: 15 additions & 12 deletions datafusion/expr/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use arrow::datatypes::{
use datafusion_common::Result;
use datafusion_common::{plan_err, DataFusionError};

use crate::type_coercion::is_numeric;
use crate::Operator;

/// The type signature of an instantiation of binary expression
Expand Down Expand Up @@ -310,10 +309,10 @@ pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
fn string_numeric_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
(Utf8, _) if is_numeric(rhs_type) => Some(Utf8),
(LargeUtf8, _) if is_numeric(rhs_type) => Some(LargeUtf8),
(_, Utf8) if is_numeric(lhs_type) => Some(Utf8),
(_, LargeUtf8) if is_numeric(lhs_type) => Some(LargeUtf8),
(Utf8, _) if rhs_type.is_numeric() => Some(Utf8),
(LargeUtf8, _) if rhs_type.is_numeric() => Some(LargeUtf8),
(_, Utf8) if lhs_type.is_numeric() => Some(Utf8),
(_, LargeUtf8) if lhs_type.is_numeric() => Some(LargeUtf8),
_ => None,
}
}
Expand Down Expand Up @@ -365,7 +364,7 @@ fn comparison_binary_numeric_coercion(
rhs_type: &DataType,
) -> Option<DataType> {
use arrow::datatypes::DataType::*;
if !is_numeric(lhs_type) || !is_numeric(rhs_type) {
if !lhs_type.is_numeric() || !rhs_type.is_numeric() {
return None;
};

Expand Down Expand Up @@ -563,14 +562,18 @@ fn create_decimal256_type(precision: u8, scale: i8) -> DataType {
fn both_numeric_or_null_and_numeric(lhs_type: &DataType, rhs_type: &DataType) -> bool {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
(_, Null) => is_numeric(lhs_type),
(Null, _) => is_numeric(rhs_type),
(_, Null) => lhs_type.is_numeric(),
(Null, _) => rhs_type.is_numeric(),
(Dictionary(_, lhs_value_type), Dictionary(_, rhs_value_type)) => {
is_numeric(lhs_value_type) && is_numeric(rhs_value_type)
lhs_value_type.is_numeric() && rhs_value_type.is_numeric()
}
(Dictionary(_, value_type), _) => is_numeric(value_type) && is_numeric(rhs_type),
(_, Dictionary(_, value_type)) => is_numeric(lhs_type) && is_numeric(value_type),
_ => is_numeric(lhs_type) && is_numeric(rhs_type),
(Dictionary(_, value_type), _) => {
value_type.is_numeric() && rhs_type.is_numeric()
}
(_, Dictionary(_, value_type)) => {
lhs_type.is_numeric() && value_type.is_numeric()
}
_ => lhs_type.is_numeric() && rhs_type.is_numeric(),
}
}

Expand Down
9 changes: 0 additions & 9 deletions datafusion/expr/src/type_coercion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ pub fn is_null(dt: &DataType) -> bool {
*dt == DataType::Null
}

/// Determine whether the given data type `dt` represents numeric values.
pub fn is_numeric(dt: &DataType) -> bool {
is_signed_numeric(dt)
|| matches!(
dt,
DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64
)
}

/// Determine whether the given data type `dt` is a `Timestamp`.
pub fn is_timestamp(dt: &DataType) -> bool {
matches!(dt, DataType::Timestamp(_, _))
Expand Down
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use datafusion_expr::type_coercion::functions::data_types;
use datafusion_expr::type_coercion::other::{
get_coerce_type_for_case_expression, get_coerce_type_for_list,
};
use datafusion_expr::type_coercion::{is_datetime, is_numeric, is_utf8_or_large_utf8};
use datafusion_expr::type_coercion::{is_datetime, is_utf8_or_large_utf8};
use datafusion_expr::{
is_false, is_not_false, is_not_true, is_not_unknown, is_true, is_unknown,
type_coercion, window_function, AggregateFunction, BuiltinScalarFunction, Expr,
Expand Down Expand Up @@ -496,7 +496,7 @@ fn coerce_window_frame(
let target_type = match window_frame.units {
WindowFrameUnits::Range => {
if let Some(col_type) = current_types.first() {
if is_numeric(col_type) || is_utf8_or_large_utf8(col_type) {
if col_type.is_numeric() || is_utf8_or_large_utf8(col_type) {
col_type
} else if is_datetime(col_type) {
&DataType::Interval(IntervalUnit::MonthDayNano)
Expand Down