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

Method Prev

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

Prev implements the Datum interface.

(ctx context.Context, cmpCtx CompareContext)

Source from the content-addressed store, hash-verified

4615
4616// Prev implements the Datum interface.
4617func (d *DTuple) Prev(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {
4618 // Note: (a:decimal, b:int, c:int) has a prev value; that's (a, b,
4619 // c-1). With an exception if c is MinInt64, in which case the prev
4620 // value is (a, b-1, max(_ *EvalContext)). However, (a:int, b:decimal) does not
4621 // have a prev value, because decimal doesn't have one.
4622 //
4623 // In general, a tuple has a prev value if and only if it ends with
4624 // zero or more values that are a minimum and a maximum value of the
4625 // same type exists, and the first element before that has a prev
4626 // value.
4627 res := NewDTupleWithLen(d.typ, len(d.D))
4628 copy(res.D, d.D)
4629 for i := len(res.D) - 1; i >= 0; i-- {
4630 if !res.D[i].IsMin(ctx, cmpCtx) {
4631 prevVal, ok := res.D[i].Prev(ctx, cmpCtx)
4632 if !ok {
4633 return nil, false
4634 }
4635 res.D[i] = prevVal
4636 break
4637 }
4638 maxVal, ok := res.D[i].Max(ctx, cmpCtx)
4639 if !ok {
4640 return nil, false
4641 }
4642 res.D[i] = maxVal
4643 }
4644 return res, true
4645}
4646
4647// Next implements the Datum interface.
4648func (d *DTuple) Next(ctx context.Context, cmpCtx CompareContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 4

NewDTupleWithLenFunction · 0.85
IsMinMethod · 0.65
PrevMethod · 0.65
MaxMethod · 0.65

Tested by

no test coverage detected