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

Method Compare

pkg/sql/sem/tree/datum.go:5468–5499  ·  view source on GitHub ↗

Compare implements the Datum interface.

(ctx context.Context, cmpCtx CompareContext, other Datum)

Source from the content-addressed store, hash-verified

5466
5467// Compare implements the Datum interface.
5468func (d *DEnum) Compare(ctx context.Context, cmpCtx CompareContext, other Datum) (int, error) {
5469 if other == DNull {
5470 return 1, nil
5471 }
5472 v, ok := cmpCtx.UnwrapDatum(ctx, other).(*DEnum)
5473 if !ok {
5474 return 0, makeUnsupportedComparisonMessage(d, other)
5475 }
5476
5477 // Different enums count as different types.
5478 if v.EnumTyp.Oid() != d.EnumTyp.Oid() {
5479 return 0, makeUnsupportedComparisonMessage(d, other)
5480 }
5481
5482 // We should never be comparing two different versions of the same enum.
5483 if v.EnumTyp.TypeMeta.Version != d.EnumTyp.TypeMeta.Version {
5484 var gist redact.SafeString
5485 if PlanGistFromCtx != nil {
5486 // Plan gist, by construction, doesn't contain any PII, so it's a
5487 // safe string.
5488 gist = redact.SafeString(PlanGistFromCtx(ctx))
5489 }
5490 return 0, errors.AssertionFailedf(
5491 "comparison of two different versions of enum %s oid %d: versions %d and %d, gist %q",
5492 d.EnumTyp.SQLStringForError(), errors.Safe(d.EnumTyp.Oid()), d.EnumTyp.TypeMeta.Version,
5493 v.EnumTyp.TypeMeta.Version, gist,
5494 )
5495 }
5496
5497 res := bytes.Compare(d.PhysicalRep, v.PhysicalRep)
5498 return res, nil
5499}
5500
5501// Prev implements the Datum interface.
5502func (d *DEnum) Prev(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 5

UnwrapDatumMethod · 0.80
OidMethod · 0.80
SQLStringForErrorMethod · 0.80
CompareMethod · 0.65

Tested by

no test coverage detected