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

Method Compare

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

Compare implements the Datum interface.

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

Source from the content-addressed store, hash-verified

5067
5068// Compare implements the Datum interface.
5069func (d *DArray) Compare(ctx context.Context, cmpCtx CompareContext, other Datum) (int, error) {
5070 if other == DNull {
5071 // NULL is less than any non-NULL value.
5072 return 1, nil
5073 }
5074 v, ok := cmpCtx.UnwrapDatum(ctx, other).(*DArray)
5075 if !ok {
5076 return 0, makeUnsupportedComparisonMessage(d, other)
5077 }
5078 n := d.Len()
5079 if n > v.Len() {
5080 n = v.Len()
5081 }
5082 for i := 0; i < n; i++ {
5083 c, err := d.Array[i].Compare(ctx, cmpCtx, v.Array[i])
5084 if err != nil {
5085 return 0, err
5086 }
5087 if c != 0 {
5088 return c, nil
5089 }
5090 }
5091 if d.Len() < v.Len() {
5092 return -1, nil
5093 }
5094 if d.Len() > v.Len() {
5095 return 1, nil
5096 }
5097 return 0, nil
5098}
5099
5100// Prev implements the Datum interface.
5101func (d *DArray) Prev(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 5

LenMethod · 0.95
UnwrapDatumMethod · 0.80
LenMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected