From 89bb07cf0b49f65ef9785d1b982aab667c1e05e0 Mon Sep 17 00:00:00 2001 From: Gabor Gevay Date: Wed, 3 Dec 2025 14:07:13 +0100 Subject: [PATCH] Hacky fix of SqlColumnType::union --- src/repr/src/relation.rs | 42 +++++++++++++++++++++++++++++++++++++++- src/repr/src/scalar.rs | 17 ++++++++++------ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/repr/src/relation.rs b/src/repr/src/relation.rs index fc7a788f6d679..059a4b93e2314 100644 --- a/src/repr/src/relation.rs +++ b/src/repr/src/relation.rs @@ -30,6 +30,7 @@ pub use crate::relation_and_scalar::{ ProtoRelationVersion, }; use crate::{Datum, ReprScalarType, Row, SqlScalarType, arb_datum_for_column}; +use crate::SqlScalarType::{Array, List, Map, Range}; /// The type of a [`Datum`]. /// @@ -68,12 +69,51 @@ impl SqlColumnType { nullable: self.nullable || other.nullable, }) } - (scalar_type, other_scalar_type) if scalar_type.base_eq(other_scalar_type) => { + (scalar_type, other_scalar_type) if scalar_type.base_eq_with_nullability(other_scalar_type) => { Ok(SqlColumnType { scalar_type: scalar_type.without_modifiers(), nullable: self.nullable || other.nullable, }) } + + ( + List { + element_type: l, + custom_id: oid_l, + }, + List { + element_type: r, + custom_id: _oid_r, + }, + ) if SqlColumnType {scalar_type: (**l).clone(), nullable: true}.union(&SqlColumnType {scalar_type: (**r).clone(), nullable: true}).is_ok() => { + Ok(SqlColumnType { + scalar_type: List { + element_type: Box::new(SqlColumnType {scalar_type: (**l).clone(), nullable: true}.union(&SqlColumnType {scalar_type: (**r).clone(), nullable: true}).unwrap().scalar_type), + custom_id: None, //////// todo + }, + nullable: self.nullable || other.nullable, + }) + } + ( + Map { + value_type: l, + custom_id: oid_l, + }, + Map { + value_type: r, + custom_id: _oid_r, + }, + ) if SqlColumnType {scalar_type: (**l).clone(), nullable: true}.union(&SqlColumnType {scalar_type: (**r).clone(), nullable: true}).is_ok() => { + Ok(SqlColumnType { + scalar_type: Map { + value_type: Box::new(SqlColumnType {scalar_type: (**l).clone(), nullable: true}.union(&SqlColumnType {scalar_type: (**r).clone(), nullable: true}).unwrap().scalar_type), + custom_id: None, //////// todo + }, + nullable: self.nullable || other.nullable, + }) + } + ///////// todo: Array; Range + ( SqlScalarType::Record { fields, custom_id }, SqlScalarType::Record { diff --git a/src/repr/src/scalar.rs b/src/repr/src/scalar.rs index 7f33492bf299a..1e2507925fcd4 100644 --- a/src/repr/src/scalar.rs +++ b/src/repr/src/scalar.rs @@ -3156,16 +3156,20 @@ impl SqlScalarType { /// contrast, two `Numeric` values with different scales are never `Eq` to /// one another. pub fn base_eq(&self, other: &SqlScalarType) -> bool { - self.eq_inner(other, false) + self.eq_inner(other, false, true) + } + + pub fn base_eq_with_nullability(&self, other: &SqlScalarType) -> bool { + self.eq_inner(other, false, false) } // Determines equality among scalar types that ignores any custom OIDs or // embedded values. pub fn structural_eq(&self, other: &SqlScalarType) -> bool { - self.eq_inner(other, true) + self.eq_inner(other, true, true) } - pub fn eq_inner(&self, other: &SqlScalarType, structure_only: bool) -> bool { + pub fn eq_inner(&self, other: &SqlScalarType, structure_only: bool, ignore_nullability: bool) -> bool { use SqlScalarType::*; match (self, other) { ( @@ -3187,9 +3191,9 @@ impl SqlScalarType { value_type: r, custom_id: oid_r, }, - ) => l.eq_inner(r, structure_only) && (oid_l == oid_r || structure_only), + ) => l.eq_inner(r, structure_only, ignore_nullability) && (oid_l == oid_r || structure_only), (Array(a), Array(b)) | (Range { element_type: a }, Range { element_type: b }) => { - a.eq_inner(b, structure_only) + a.eq_inner(b, structure_only, ignore_nullability) } ( Record { @@ -3209,7 +3213,8 @@ impl SqlScalarType { // Ignore nullability. .all(|(a, b)| { (a.0 == b.0 || structure_only) - && a.1.scalar_type.eq_inner(&b.1.scalar_type, structure_only) + && a.1.scalar_type.eq_inner(&b.1.scalar_type, structure_only, ignore_nullability) + && if !ignore_nullability {a.1.nullable == b.1.nullable} else {true} }) } (s, o) => SqlScalarBaseType::from(s) == SqlScalarBaseType::from(o),