Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6269073
start
paleolimbot Oct 8, 2025
585bba9
builds!
paleolimbot Oct 8, 2025
16ac02d
backward compatible proto
paleolimbot Oct 9, 2025
a702499
move FieldMetadata
paleolimbot Oct 9, 2025
2c98b28
maybe working from proto
paleolimbot Oct 9, 2025
cbf75aa
oof
paleolimbot Oct 9, 2025
9982d32
maybe fix build
paleolimbot Oct 9, 2025
0091bbb
fix doc
paleolimbot Oct 10, 2025
4f01800
fix the name of the list
paleolimbot Oct 10, 2025
9b3a45a
undo trailing whitespace change
paleolimbot Oct 10, 2025
901a011
maybe fix failing tests
paleolimbot Oct 10, 2025
21af946
possibly reusable type equality
paleolimbot Oct 14, 2025
b7404c0
literal class
paleolimbot Oct 14, 2025
94cb418
doc
paleolimbot Oct 14, 2025
b982d4c
one more pass on documenting things
paleolimbot Oct 14, 2025
4f4820b
use the equality checker in one more place
paleolimbot Oct 14, 2025
63ae6fb
update data_types variables that were actually fields
paleolimbot Oct 14, 2025
a085cf1
revert tests
paleolimbot Oct 14, 2025
5475937
fix slt
paleolimbot Oct 14, 2025
05431a2
add a test that fails
paleolimbot Oct 14, 2025
45f15f4
fix test
paleolimbot Oct 16, 2025
4386a85
add tests for expression schema for typed parameters
paleolimbot Oct 16, 2025
8b5622f
more tests
paleolimbot Oct 16, 2025
df5aba8
add placeholder inference test
paleolimbot Oct 16, 2025
08d0e7a
add nullability to test
paleolimbot Oct 16, 2025
2b4b8e7
tests for proto
paleolimbot Oct 16, 2025
57437b9
make sure I don't forget these
paleolimbot Oct 16, 2025
70f3663
fix typo
paleolimbot Oct 16, 2025
58807fd
remove comment
paleolimbot Oct 16, 2025
4bfc5cd
fix
paleolimbot Oct 16, 2025
81c3baf
fmt
paleolimbot Oct 17, 2025
860e013
fix error string comparison
paleolimbot Oct 17, 2025
b6c71b3
add update/insert test
paleolimbot Oct 17, 2025
cfabfd0
Merge branch 'main' into params-with-metadata
paleolimbot Oct 17, 2025
acb6b6f
Merge branch 'main' into params-with-metadata
paleolimbot Oct 21, 2025
8752fd8
fix for merge
paleolimbot Oct 21, 2025
46d4e13
review comments
paleolimbot Oct 21, 2025
91d9549
rename literal
paleolimbot Oct 21, 2025
d665a6e
maybe LiteralValue?
paleolimbot Oct 21, 2025
8c2f549
remove custom field logic
paleolimbot Oct 21, 2025
749f168
Merge branch 'main' into params-with-metadata
paleolimbot Oct 22, 2025
f3fdf4a
use named constant
paleolimbot Oct 22, 2025
aecbfa9
Add DataTypeExt and FieldExt to assist converting to/from Fields and …
alamb Oct 22, 2025
9043163
Merge branch 'params-with-metadata' into alamb/datatype_ext
paleolimbot Oct 22, 2025
be5c11d
Merge pull request #1 from alamb/alamb/datatype_ext
paleolimbot Oct 22, 2025
d41616d
rename literalvalue
paleolimbot Oct 22, 2025
d8d07a6
more comments
paleolimbot Oct 22, 2025
f83ec4c
one more deprecation
paleolimbot Oct 22, 2025
e9df620
clean up ext traits
paleolimbot Oct 22, 2025
640a6f2
typos
paleolimbot Oct 23, 2025
4fdaebf
fix confusingly named variable
paleolimbot Oct 23, 2025
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
107 changes: 107 additions & 0 deletions datafusion/common/src/datatype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! [DataTypeExt] extension trait for converting DataTypes to Fields

use crate::arrow::datatypes::{DataType, Field, FieldRef};
use std::sync::Arc;

/// DataFusion extension methods for Arrow [`DataType`]
pub trait DataTypeExt {
/// Convert the type to field with nullable type and "" name
///
/// This is used to track the places where we convert a [`DataType`]
/// into a nameless field to interact with an API that is
/// capable of representing an extension type and/or nullability.
fn into_nullable_field(self) -> Field;

/// Convert the type to field ref with nullable type and "" name
///
/// Concise wrapper around [`DataTypeExt::into_nullable_field`] that
/// constructs a [`FieldRef`].
fn into_nullable_field_ref(self) -> FieldRef;
}

impl DataTypeExt for DataType {
fn into_nullable_field(self) -> Field {
Field::new("", self, true)
}

fn into_nullable_field_ref(self) -> FieldRef {
Arc::new(Field::new("", self, true))
}
}

/// DataFusion extension methods for Arrow [`Field`]
pub trait FieldExt {
/// Returns a new Field representing a List of this Field's DataType.
fn into_list(self) -> Self;

/// Return a new Field representing this Field as the item type of a FixedSizeList
fn into_fixed_size_list(self, list_size: i32) -> Self;

/// Create a field with the default list field name ("item")
///
/// Note that lists are allowed to have an arbitrarily named field;
/// however, a name other than 'item' will cause it to fail an
/// == check against a more idiomatically created list in
/// arrow-rs which causes issues.
fn into_list_item(self) -> Self;
}

impl FieldExt for Field {
fn into_list(self) -> Self {
DataType::List(Arc::new(self.into_list_item())).into_nullable_field()
}

fn into_fixed_size_list(self, list_size: i32) -> Self {
DataType::FixedSizeList(self.into_list_item().into(), list_size)
.into_nullable_field()
}

fn into_list_item(self) -> Self {
if self.name() != Field::LIST_FIELD_DEFAULT_NAME {
self.with_name(Field::LIST_FIELD_DEFAULT_NAME)
} else {
self
}
}
}

impl FieldExt for Arc<Field> {
fn into_list(self) -> Self {
DataType::List(self.into_list_item())
.into_nullable_field()
.into()
}

fn into_fixed_size_list(self, list_size: i32) -> Self {
DataType::FixedSizeList(self.into_list_item(), list_size)
.into_nullable_field()
.into()
}

fn into_list_item(self) -> Self {
if self.name() != Field::LIST_FIELD_DEFAULT_NAME {
Arc::unwrap_or_clone(self)
.with_name(Field::LIST_FIELD_DEFAULT_NAME)
.into()
} else {
self
}
}
}
2 changes: 2 additions & 0 deletions datafusion/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod alias;
pub mod cast;
pub mod config;
pub mod cse;
pub mod datatype;
pub mod diagnostic;
pub mod display;
pub mod encryption;
Expand All @@ -47,6 +48,7 @@ pub mod file_options;
pub mod format;
pub mod hash_utils;
pub mod instant;
pub mod metadata;
pub mod nested_struct;
mod null_equality;
pub mod parsers;
Expand Down
Loading