Apache DataFusion SQL Query Engine
ARROW-10656: [Rust] Use DataType comparison without values
Christoph Schulzef1f3fe51d5b4
diff --git a/rust/datafusion/src/physical_plan/distinct_expressions.rs b/rust/datafusion/src/physical_plan/distinct_expressions.rsindex bbccc3be6e..a441c0b76c 100644--- a/rust/datafusion/src/physical_plan/distinct_expressions.rs+++ b/rust/datafusion/src/physical_plan/distinct_expressions.rs@@ -22,7 +22,7 @@ use std::fmt::Debug;use std::hash::Hash;use std::sync::Arc;-use arrow::datatypes::{DataType, Field};+use arrow::datatypes::{DataType, Field, NullableDataType};use ahash::RandomState;use std::collections::HashSet;@@ -81,7 +81,10 @@ impl AggregateExpr for DistinctCount {.map(|data_type| {Field::new(&format_state_name(&self.name, "count distinct"),- DataType::List(Box::new(Field::new("item", data_type.clone(), true))),+ DataType::List(Box::new(NullableDataType::new(+ data_type.clone(),+ true,+ ))),false,)})diff --git a/rust/datafusion/src/physical_plan/functions.rs b/rust/datafusion/src/physical_plan/functions.rsindex b954f479d9..41fd210519 100644--- a/rust/datafusion/src/physical_plan/functions.rs+++ b/rust/datafusion/src/physical_plan/functions.rs@@ -39,11 +39,12 @@ use crate::physical_plan::datetime_expressions;use crate::physical_plan::expressions::{nullif_func, SUPPORTED_NULLIF_TYPES};use crate::physical_plan::math_expressions;use crate::physical_plan::string_expressions;+use arrow::datatypes::NullableDataType;use arrow::{array::ArrayRef,compute::kernels::length::length,datatypes::TimeUnit,- datatypes::{DataType, Field, Schema},+ datatypes::{DataType, Schema},record_batch::RecordBatch,};use fmt::{Debug, Formatter};@@ -207,7 +208,7 @@ pub fn return_type(Ok(DataType::Timestamp(TimeUnit::Nanosecond, None))}BuiltinScalarFunction::Array => Ok(DataType::FixedSizeList(- Box::new(Field::new("item", arg_types[0].clone(), true)),+ Box::new(NullableDataType::new(arg_types[0].clone(), true)),arg_types.len() as i32,)),BuiltinScalarFunction::NullIf => {@@ -484,7 +485,10 @@ mod tests {assert_eq!(expr.data_type(&schema)?,// type equals to a common coercion- DataType::FixedSizeList(Box::new(Field::new("item", expected_type, true)), 2)+ DataType::FixedSizeList(+ Box::new(NullableDataType::new(expected_type, true)),+ 2+ ));// evaluate worksdiff --git a/rust/datafusion/src/physical_plan/planner.rs b/rust/datafusion/src/physical_plan/planner.rsindex b592111b59..d6082f3a72 100644--- a/rust/datafusion/src/physical_plan/planner.rs+++ b/rust/datafusion/src/physical_plan/planner.rs@@ -786,7 +786,7 @@ mod tests {};let plan = planner.create_physical_plan(&logical_plan, &ctx_state);- let expected_error = "Extension planner for NoOp created an ExecutionPlan with mismatched schema. LogicalPlan schema: Schema { fields: [Field { name: \"a\", data_type: Int32, nullable: false, dict_id: 0, dict_is_ordered: false }], metadata: {} }, ExecutionPlan schema: Schema { fields: [Field { name: \"b\", data_type: Int32, nullable: false, dict_id: 0, dict_is_ordered: false }], metadata: {} }";+ let expected_error = "Extension planner for NoOp created an ExecutionPlan with mismatched schema. LogicalPlan schema: Schema { fields: [Field { name: \"a\", data_type: NullableDataType { data_type: Int32, nullable: false }, dict_id: 0, dict_is_ordered: false }], metadata: {} }, ExecutionPlan schema: Schema { fields: [Field { name: \"b\", data_type: NullableDataType { data_type: Int32, nullable: false }, dict_id: 0, dict_is_ordered: false }], metadata: {} }";match plan {Ok(_) => assert!(false, "Expected planning failure"),diff --git a/rust/datafusion/src/scalar.rs b/rust/datafusion/src/scalar.rsindex 06309ab84c..c64f1a2d02 100644--- a/rust/datafusion/src/scalar.rs+++ b/rust/datafusion/src/scalar.rs@@ -23,10 +23,7 @@ use arrow::array::{Int16Builder, Int32Builder, Int64Builder, Int8Builder, ListBuilder, UInt16Builder,UInt32Builder, UInt64Builder, UInt8Builder,};-use arrow::{- array::ArrayRef,- datatypes::{DataType, Field},-};+use arrow::{array::ArrayRef, datatypes::DataType};use arrow::{array::{Array, BooleanArray, Date32Array, Float32Array, Float64Array, Int16Array,@@ -37,6 +34,7 @@ use arrow::{};use crate::error::{DataFusionError, Result};+use arrow::datatypes::NullableDataType;/// Represents a dynamically typed, nullable single value./// This is the single-valued counter-part of arrow’s `Array`.@@ -136,7 +134,7 @@ impl ScalarValue {ScalarValue::Utf8(_) => DataType::Utf8,ScalarValue::LargeUtf8(_) => DataType::LargeUtf8,ScalarValue::List(_, data_type) => {- DataType::List(Box::new(Field::new("item", data_type.clone(), true)))+ DataType::List(Box::new(NullableDataType::new(data_type.clone(), true)))}ScalarValue::Date32(_) => DataType::Date32(DateUnit::Day),}diff --git a/rust/datafusion/tests/sql.rs b/rust/datafusion/tests/sql.rsindex 7327487d3b..bb503a102e 100644--- a/rust/datafusion/tests/sql.rs+++ b/rust/datafusion/tests/sql.rs@@ -25,7 +25,7 @@ extern crate datafusion;use arrow::{array::*, datatypes::TimeUnit};use arrow::{datatypes::Int32Type, datatypes::Int64Type, record_batch::RecordBatch};use arrow::{- datatypes::{DataType, Field, Schema, SchemaRef},+ datatypes::{DataType, Field, NullableDataType, Schema, SchemaRef},util::display::array_value_to_string,};@@ -142,12 +142,12 @@ async fn parquet_list_columns() {let schema = Arc::new(Schema::new(vec![Field::new("int64_list",- DataType::List(Box::new(Field::new("item", DataType::Int64, true))),+ DataType::List(Box::new(NullableDataType::new(DataType::Int64, true))),true,),Field::new("utf8_list",- DataType::List(Box::new(Field::new("item", DataType::Utf8, true))),+ DataType::List(Box::new(NullableDataType::new(DataType::Utf8, true))),true,),]));