MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EquivalentOrNull

Method EquivalentOrNull

pkg/sql/types/types.go:2255–2289  ·  view source on GitHub ↗

EquivalentOrNull is the same as Equivalent, except it returns true if: * `t` is Unknown (i.e., NULL) AND (allowNullTupleEquivalence OR `other` is not a tuple), * `t` is a tuple with all non-Unknown elements matching the types in `other`.

(other *T, allowNullTupleEquivalence bool)

Source from the content-addressed store, hash-verified

2253// * `t` is Unknown (i.e., NULL) AND (allowNullTupleEquivalence OR `other` is not a tuple),
2254// * `t` is a tuple with all non-Unknown elements matching the types in `other`.
2255func (t *T) EquivalentOrNull(other *T, allowNullTupleEquivalence bool) bool {
2256 // Check normal equivalency first, then check for Null
2257 normalEquivalency := t.Equivalent(other)
2258 if normalEquivalency {
2259 return true
2260 }
2261
2262 switch t.Family() {
2263 case UnknownFamily:
2264 return allowNullTupleEquivalence || other.Family() != TupleFamily
2265
2266 case TupleFamily:
2267 if other.Family() != TupleFamily {
2268 return false
2269 }
2270 // If either tuple is the wildcard tuple, it's equivalent to any other
2271 // tuple type. This allows overloads to specify that they take an arbitrary
2272 // tuple type.
2273 if IsWildcardTupleType(t) || IsWildcardTupleType(other) {
2274 return true
2275 }
2276 if len(t.TupleContents()) != len(other.TupleContents()) {
2277 return false
2278 }
2279 for i := range t.TupleContents() {
2280 if !t.TupleContents()[i].EquivalentOrNull(other.TupleContents()[i], allowNullTupleEquivalence) {
2281 return false
2282 }
2283 }
2284 return true
2285
2286 default:
2287 return normalEquivalency
2288 }
2289}
2290
2291// Identical returns true if every field in this ColumnType is exactly the same
2292// as every corresponding field in the given ColumnType. Identical performs a

Callers 3

AppendMethod · 0.80
typeCheckSubqueryWithInFunction · 0.80

Calls 4

EquivalentMethod · 0.95
FamilyMethod · 0.95
TupleContentsMethod · 0.95
IsWildcardTupleTypeFunction · 0.85

Tested by

no test coverage detected