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

Method Compare

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

Compare implements the Datum interface.

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

Source from the content-addressed store, hash-verified

851
852// Compare implements the Datum interface.
853func (d *DFloat) Compare(ctx context.Context, cmpCtx CompareContext, other Datum) (int, error) {
854 if other == DNull {
855 // NULL is less than any non-NULL value.
856 return 1, nil
857 }
858 var v DFloat
859 switch t := cmpCtx.UnwrapDatum(ctx, other).(type) {
860 case *DFloat:
861 v = *t
862 case *DInt:
863 v = DFloat(MustBeDInt(t))
864 case *DDecimal:
865 res, err := t.Compare(ctx, cmpCtx, d)
866 if err != nil {
867 return 0, err
868 }
869 return -res, nil
870 default:
871 return 0, makeUnsupportedComparisonMessage(d, other)
872 }
873 if *d < v {
874 return -1, nil
875 }
876 if *d > v {
877 return 1, nil
878 }
879 // NaN sorts before non-NaN (#10109).
880 if *d == v {
881 return 0, nil
882 }
883 if math.IsNaN(float64(*d)) {
884 if math.IsNaN(float64(v)) {
885 return 0, nil
886 }
887 return -1, nil
888 }
889 return 1, nil
890}
891
892// Prev implements the Datum interface.
893func (d *DFloat) Prev(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 5

DFloatTypeAlias · 0.85
MustBeDIntFunction · 0.85
UnwrapDatumMethod · 0.80
CompareMethod · 0.65

Tested by

no test coverage detected