github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sequence_select.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 18 "github.com/cockroachdb/errors" 19 ) 20 21 type sequenceSelectNode struct { 22 optColumnsSlot 23 24 desc *sqlbase.ImmutableTableDescriptor 25 26 val int64 27 done bool 28 } 29 30 var _ planNode = &sequenceSelectNode{} 31 32 func (p *planner) SequenceSelectNode(desc *sqlbase.ImmutableTableDescriptor) (planNode, error) { 33 if desc.SequenceOpts == nil { 34 return nil, errors.New("descriptor is not a sequence") 35 } 36 return &sequenceSelectNode{ 37 desc: desc, 38 }, nil 39 } 40 41 func (ss *sequenceSelectNode) startExec(runParams) error { 42 return nil 43 } 44 45 func (ss *sequenceSelectNode) Next(params runParams) (bool, error) { 46 if ss.done { 47 return false, nil 48 } 49 val, err := params.p.GetSequenceValue(params.ctx, params.ExecCfg().Codec, ss.desc) 50 if err != nil { 51 return false, err 52 } 53 ss.val = val 54 ss.done = true 55 return true, nil 56 } 57 58 func (ss *sequenceSelectNode) Values() tree.Datums { 59 valDatum := tree.DInt(ss.val) 60 cntDatum := tree.DInt(0) 61 calledDatum := tree.DBoolTrue 62 return []tree.Datum{ 63 &valDatum, 64 &cntDatum, 65 calledDatum, 66 } 67 } 68 69 func (ss *sequenceSelectNode) Close(ctx context.Context) {}