This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 8469aa1dcd minor: implement more arms for `get_data_types()` for
`NativeType` (#19449)
8469aa1dcd is described below
commit 8469aa1dcd409d1b6da40e006ef3febf65959feb
Author: Jeffrey Vo <[email protected]>
AuthorDate: Tue Dec 30 11:20:52 2025 +0900
minor: implement more arms for `get_data_types()` for `NativeType` (#19449)
Work towards a minor TODO item. Also some minor doc updates.
---
datafusion/expr-common/src/signature.rs | 67 +++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 3 deletions(-)
diff --git a/datafusion/expr-common/src/signature.rs
b/datafusion/expr-common/src/signature.rs
index 90bd141500..8893d63943 100644
--- a/datafusion/expr-common/src/signature.rs
+++ b/datafusion/expr-common/src/signature.rs
@@ -19,9 +19,13 @@
use std::fmt::Display;
use std::hash::Hash;
+use std::sync::Arc;
use crate::type_coercion::aggregates::NUMERICS;
-use arrow::datatypes::{DataType, Decimal128Type, DecimalType, IntervalUnit,
TimeUnit};
+use arrow::datatypes::{
+ DECIMAL32_MAX_PRECISION, DECIMAL64_MAX_PRECISION,
DECIMAL128_MAX_PRECISION, DataType,
+ Decimal128Type, DecimalType, Field, IntervalUnit, TimeUnit,
+};
use datafusion_common::types::{LogicalType, LogicalTypeRef, NativeType};
use datafusion_common::utils::ListCoercion;
use datafusion_common::{Result, internal_err, plan_err};
@@ -328,14 +332,23 @@ impl TypeSignature {
/// arguments that can be coerced to a particular class of types.
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash)]
pub enum TypeSignatureClass {
+ /// Timestamps, allowing arbitrary (or no) timezones
Timestamp,
+ /// All time types
Time,
+ /// All interval types
Interval,
+ /// All duration types
Duration,
+ /// A specific native type
Native(LogicalTypeRef),
+ /// Signed and unsigned integers
Integer,
+ /// All float types
Float,
+ /// All decimal types, allowing arbitrary precision & scale
Decimal,
+ /// Integers, floats and decimals
Numeric,
/// Encompasses both the native Binary/LargeBinary types as well as
arbitrarily sized FixedSizeBinary types
Binary,
@@ -888,8 +901,56 @@ fn get_data_types(native_type: &NativeType) ->
Vec<DataType> {
NativeType::String => {
vec![DataType::Utf8, DataType::LargeUtf8, DataType::Utf8View]
}
- // TODO: support other native types
- _ => vec![],
+ NativeType::Decimal(precision, scale) => {
+ // We assume incoming NativeType is valid already, in terms of
precision & scale
+ let mut types = vec![DataType::Decimal256(*precision, *scale)];
+ if *precision <= DECIMAL32_MAX_PRECISION {
+ types.push(DataType::Decimal32(*precision, *scale));
+ }
+ if *precision <= DECIMAL64_MAX_PRECISION {
+ types.push(DataType::Decimal64(*precision, *scale));
+ }
+ if *precision <= DECIMAL128_MAX_PRECISION {
+ types.push(DataType::Decimal128(*precision, *scale));
+ }
+ types
+ }
+ NativeType::Timestamp(time_unit, timezone) => {
+ vec![DataType::Timestamp(*time_unit, timezone.to_owned())]
+ }
+ NativeType::Time(TimeUnit::Second) =>
vec![DataType::Time32(TimeUnit::Second)],
+ NativeType::Time(TimeUnit::Millisecond) => {
+ vec![DataType::Time32(TimeUnit::Millisecond)]
+ }
+ NativeType::Time(TimeUnit::Microsecond) => {
+ vec![DataType::Time64(TimeUnit::Microsecond)]
+ }
+ NativeType::Time(TimeUnit::Nanosecond) => {
+ vec![DataType::Time64(TimeUnit::Nanosecond)]
+ }
+ NativeType::Duration(time_unit) =>
vec![DataType::Duration(*time_unit)],
+ NativeType::Interval(interval_unit) =>
vec![DataType::Interval(*interval_unit)],
+ NativeType::FixedSizeBinary(size) =>
vec![DataType::FixedSizeBinary(*size)],
+ NativeType::FixedSizeList(logical_field, size) => {
+ get_data_types(logical_field.logical_type.native())
+ .iter()
+ .map(|child_dt| {
+ let field = Field::new(
+ logical_field.name.clone(),
+ child_dt.clone(),
+ logical_field.nullable,
+ );
+ DataType::FixedSizeList(Arc::new(field), *size)
+ })
+ .collect()
+ }
+ // TODO: implement for nested types
+ NativeType::List(_)
+ | NativeType::Struct(_)
+ | NativeType::Union(_)
+ | NativeType::Map(_) => {
+ vec![]
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]