Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 41 additions & 1 deletion src/repr/src/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 11 additions & 6 deletions src/repr/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
(
Expand All @@ -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 {
Expand All @@ -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),
Expand Down