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

Function DatumNext

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

DatumNext returns a datum that is "next" to the given one. For many types it just delegates to Datum.Next, but for some types that don't have an implementation of that function this method makes the best effort to come up with a reasonable next datum that is greater than the given one. The return v

(
	ctx context.Context, datum Datum, cmpCtx CompareContext, collationEnv *CollationEnvironment,
)

Source from the content-addressed store, hash-verified

6642// The return value is undefined if Datum.IsMax returns true or if the value is
6643// NaN or an infinity (for floats and decimals).
6644func DatumNext(
6645 ctx context.Context, datum Datum, cmpCtx CompareContext, collationEnv *CollationEnvironment,
6646) (Datum, bool) {
6647 datum = UnwrapDOidWrapper(datum)
6648 switch d := datum.(type) {
6649 case *DDecimal:
6650 var next DDecimal
6651 var add apd.Decimal
6652 _, err := add.SetFloat64(1e-6)
6653 if err != nil {
6654 return nil, false
6655 }
6656 _, err = ExactCtx.Add(&next.Decimal, &d.Decimal, &add)
6657 if err != nil {
6658 return nil, false
6659 }
6660 return &next, true
6661 case *DInterval:
6662 next := d.Add(duration.MakeDuration(1000000 /* nanos */, 0 /* days */, 0 /* months */))
6663 return NewDInterval(next, types.DefaultIntervalTypeMetadata), true
6664 default:
6665 // TODO(yuzefovich): consider adding support for other datums that don't
6666 // have Datum.Next implementation (DCollatedString, DGeography,
6667 // DGeometry, DBox2D, DJSON).
6668 return datum.Next(ctx, cmpCtx)
6669 }
6670}

Callers

nothing calls this directly

Calls 5

MakeDurationFunction · 0.92
UnwrapDOidWrapperFunction · 0.85
NewDIntervalFunction · 0.85
AddMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…