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

Method Compare

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

Compare implements the Datum interface.

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

Source from the content-addressed store, hash-verified

707
708// Compare implements the Datum interface.
709func (d *DInt) Compare(ctx context.Context, cmpCtx CompareContext, other Datum) (int, error) {
710 if other == DNull {
711 // NULL is less than any non-NULL value.
712 return 1, nil
713 }
714 thisInt := *d
715 var v DInt
716 switch t := cmpCtx.UnwrapDatum(ctx, other).(type) {
717 case *DInt:
718 v = *t
719 case *DFloat, *DDecimal:
720 res, err := t.Compare(ctx, cmpCtx, d)
721 if err != nil {
722 return 0, err
723 }
724 return -res, nil
725 case *DOid:
726 // OIDs are always unsigned 32-bit integers. Some languages, like Java,
727 // compare OIDs to signed 32-bit integers, so we implement the comparison
728 // by converting to a uint32 first. This matches Postgres behavior.
729 o, err := IntToOid(thisInt)
730 if err != nil {
731 return 0, err
732 }
733 thisInt = DInt(o)
734 v = DInt(t.Oid)
735 default:
736 return 0, makeUnsupportedComparisonMessage(d, other)
737 }
738 if thisInt < v {
739 return -1, nil
740 }
741 if thisInt > v {
742 return 1, nil
743 }
744 return 0, nil
745}
746
747// Prev implements the Datum interface.
748func (d *DInt) Prev(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 5

IntToOidFunction · 0.85
DIntTypeAlias · 0.85
UnwrapDatumMethod · 0.80
CompareMethod · 0.65

Tested by

no test coverage detected