Apache DataFusion SQL Query Engine
ignore metadata when compare with nested type (#15366)
Jax Liu86db4bf3c5af
diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rsindex c874067af3..c49de39840 100644--- a/datafusion/expr-common/src/type_coercion/binary.rs+++ b/datafusion/expr-common/src/type_coercion/binary.rs@@ -719,7 +719,7 @@ pub fn try_type_union_resolution_with_struct(/// strings. For example when comparing `'2' > 1`, the arguments will be/// coerced to `Utf8` for comparisonpub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {- if lhs_type == rhs_type {+ if lhs_type.equals_datatype(rhs_type) {// same type => equality is possiblereturn Some(lhs_type.clone());}diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rsindex a77249424f..d47f7ea6ce 100644--- a/datafusion/optimizer/src/analyzer/type_coercion.rs+++ b/datafusion/optimizer/src/analyzer/type_coercion.rs@@ -1054,7 +1054,7 @@ mod test {use std::sync::Arc;use arrow::datatypes::DataType::Utf8;- use arrow::datatypes::{DataType, Field, Schema, TimeUnit};+ use arrow::datatypes::{DataType, Field, Schema, SchemaBuilder, TimeUnit};use crate::analyzer::type_coercion::{coerce_case_expression, TypeCoercion, TypeCoercionRewriter,@@ -2091,6 +2091,31 @@ mod test {Ok(())}+ #[test]+ fn test_map_with_diff_name() -> Result<()> {+ let mut builder = SchemaBuilder::new();+ builder.push(Field::new("key", Utf8, false));+ builder.push(Field::new("value", DataType::Float64, true));+ let struct_fields = builder.finish().fields;++ let fields =+ Field::new("entries", DataType::Struct(struct_fields.clone()), false);+ let map_type_entries = DataType::Map(Arc::new(fields), false);++ let fields = Field::new("key_value", DataType::Struct(struct_fields), false);+ let may_type_cutsom = DataType::Map(Arc::new(fields), false);++ let expr = col("a").eq(cast(col("a"), may_type_cutsom));+ let empty = empty_with_type(map_type_entries);+ let plan = LogicalPlan::Projection(Projection::try_new(vec![expr], empty)?);+ let expected = "Projection: a = CAST(CAST(a AS Map(Field { name: \"key_value\", data_type: Struct([Field { name: \"key\", data_type: Utf8, \+ nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: \"value\", data_type: Float64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), \+ nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false)) AS Map(Field { name: \"entries\", data_type: Struct([Field { name: \"key\", data_type: Utf8, nullable: false, \+ dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: \"value\", data_type: Float64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false))\n \+ EmptyRelation";+ assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), plan, expected)+ }+#[test]fn interval_plus_timestamp() -> Result<()> {// SELECT INTERVAL '1' YEAR + '2000-01-01T00:00:00'::timestamp;