|
| 1 | +// Copyright 2023 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/pgrepl/lsn" |
| 17 | + "github.com/cockroachdb/cockroach/pkg/sql/pgrepl/lsnutil" |
| 18 | + "github.com/cockroachdb/cockroach/pkg/sql/pgrepl/pgrepltree" |
| 19 | + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" |
| 20 | +) |
| 21 | + |
| 22 | +type identifySystemNode struct { |
| 23 | + optColumnsSlot |
| 24 | + clusterID string |
| 25 | + database string |
| 26 | + lsn lsn.LSN |
| 27 | + shown bool |
| 28 | +} |
| 29 | + |
| 30 | +func (s *identifySystemNode) startExec(params runParams) error { |
| 31 | + return nil |
| 32 | +} |
| 33 | + |
| 34 | +func (s *identifySystemNode) Next(params runParams) (bool, error) { |
| 35 | + if s.shown { |
| 36 | + return false, nil |
| 37 | + } |
| 38 | + s.shown = true |
| 39 | + return true, nil |
| 40 | +} |
| 41 | + |
| 42 | +func (s *identifySystemNode) Values() tree.Datums { |
| 43 | + db := tree.DNull |
| 44 | + if s.database != "" { |
| 45 | + db = tree.NewDString(s.database) |
| 46 | + } |
| 47 | + return tree.Datums{ |
| 48 | + tree.NewDString(s.clusterID), |
| 49 | + tree.NewDInt(1), // timeline |
| 50 | + tree.NewDString(s.lsn.String()), |
| 51 | + db, |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func (s *identifySystemNode) Close(ctx context.Context) {} |
| 56 | + |
| 57 | +func (p *planner) IdentifySystem( |
| 58 | + ctx context.Context, n *pgrepltree.IdentifySystem, |
| 59 | +) (planNode, error) { |
| 60 | + return &identifySystemNode{ |
| 61 | + // TODO(#105130): correctly populate this field. |
| 62 | + lsn: lsnutil.HLCToLSN(p.Txn().ReadTimestamp()), |
| 63 | + clusterID: p.ExecCfg().NodeInfo.LogicalClusterID().String(), |
| 64 | + database: p.SessionData().Database, |
| 65 | + }, nil |
| 66 | +} |
0 commit comments