github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqlbase/evalctx.go (about) 1 // Copyright 2016 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 sqlbase 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/parser" 17 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" 18 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" 19 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 20 "github.com/cockroachdb/cockroach/pkg/sql/types" 21 "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" 22 "github.com/cockroachdb/errors" 23 ) 24 25 // DummySequenceOperators implements the tree.SequenceOperators interface by 26 // returning errors. 27 type DummySequenceOperators struct{} 28 29 var _ tree.EvalDatabase = &DummySequenceOperators{} 30 31 var errSequenceOperators = unimplemented.NewWithIssue(42508, 32 "cannot evaluate scalar expressions containing sequence operations in this context") 33 34 // ParseQualifiedTableName is part of the tree.EvalDatabase interface. 35 func (so *DummySequenceOperators) ParseQualifiedTableName(sql string) (*tree.TableName, error) { 36 return nil, errors.WithStack(errSequenceOperators) 37 } 38 39 // ResolveTableName is part of the tree.EvalDatabase interface. 40 func (so *DummySequenceOperators) ResolveTableName( 41 ctx context.Context, tn *tree.TableName, 42 ) (tree.ID, error) { 43 return 0, errors.WithStack(errSequenceOperators) 44 } 45 46 // LookupSchema is part of the tree.EvalDatabase interface. 47 func (so *DummySequenceOperators) LookupSchema( 48 ctx context.Context, dbName, scName string, 49 ) (bool, tree.SchemaMeta, error) { 50 return false, nil, errors.WithStack(errSequenceOperators) 51 } 52 53 // IncrementSequence is part of the tree.SequenceOperators interface. 54 func (so *DummySequenceOperators) IncrementSequence( 55 ctx context.Context, seqName *tree.TableName, 56 ) (int64, error) { 57 return 0, errors.WithStack(errSequenceOperators) 58 } 59 60 // GetLatestValueInSessionForSequence implements the tree.SequenceOperators 61 // interface. 62 func (so *DummySequenceOperators) GetLatestValueInSessionForSequence( 63 ctx context.Context, seqName *tree.TableName, 64 ) (int64, error) { 65 return 0, errors.WithStack(errSequenceOperators) 66 } 67 68 // SetSequenceValue implements the tree.SequenceOperators interface. 69 func (so *DummySequenceOperators) SetSequenceValue( 70 ctx context.Context, seqName *tree.TableName, newVal int64, isCalled bool, 71 ) error { 72 return errors.WithStack(errSequenceOperators) 73 } 74 75 // DummyEvalPlanner implements the tree.EvalPlanner interface by returning 76 // errors. 77 type DummyEvalPlanner struct{} 78 79 var _ tree.EvalPlanner = &DummyEvalPlanner{} 80 81 var errEvalPlanner = pgerror.New(pgcode.ScalarOperationCannotRunWithoutFullSessionContext, 82 "cannot evaluate scalar expressions using table lookups in this context") 83 84 // ParseQualifiedTableName is part of the tree.EvalDatabase interface. 85 func (ep *DummyEvalPlanner) ParseQualifiedTableName(sql string) (*tree.TableName, error) { 86 return parser.ParseQualifiedTableName(sql) 87 } 88 89 // LookupSchema is part of the tree.EvalDatabase interface. 90 func (ep *DummyEvalPlanner) LookupSchema( 91 ctx context.Context, dbName, scName string, 92 ) (bool, tree.SchemaMeta, error) { 93 return false, nil, errors.WithStack(errEvalPlanner) 94 } 95 96 // ResolveTableName is part of the tree.EvalDatabase interface. 97 func (ep *DummyEvalPlanner) ResolveTableName( 98 ctx context.Context, tn *tree.TableName, 99 ) (tree.ID, error) { 100 return 0, errors.WithStack(errEvalPlanner) 101 } 102 103 // ParseType is part of the tree.EvalPlanner interface. 104 func (ep *DummyEvalPlanner) ParseType(sql string) (*types.T, error) { 105 return nil, errors.WithStack(errEvalPlanner) 106 } 107 108 // EvalSubquery is part of the tree.EvalPlanner interface. 109 func (ep *DummyEvalPlanner) EvalSubquery(expr *tree.Subquery) (tree.Datum, error) { 110 return nil, errors.WithStack(errEvalPlanner) 111 } 112 113 // DummyPrivilegedAccessor implements the tree.PrivilegedAccessor interface by returning errors. 114 type DummyPrivilegedAccessor struct{} 115 116 var _ tree.PrivilegedAccessor = &DummyPrivilegedAccessor{} 117 118 var errEvalPrivileged = pgerror.New(pgcode.ScalarOperationCannotRunWithoutFullSessionContext, 119 "cannot evaluate privileged expressions in this context") 120 121 // LookupNamespaceID is part of the tree.PrivilegedAccessor interface. 122 func (ep *DummyPrivilegedAccessor) LookupNamespaceID( 123 ctx context.Context, parentID int64, name string, 124 ) (tree.DInt, bool, error) { 125 return 0, false, errors.WithStack(errEvalPrivileged) 126 } 127 128 // LookupZoneConfigByNamespaceID is part of the tree.PrivilegedAccessor interface. 129 func (ep *DummyPrivilegedAccessor) LookupZoneConfigByNamespaceID( 130 ctx context.Context, id int64, 131 ) (tree.DBytes, bool, error) { 132 return "", false, errors.WithStack(errEvalPrivileged) 133 } 134 135 // DummySessionAccessor implements the tree.EvalSessionAccessor interface by returning errors. 136 type DummySessionAccessor struct{} 137 138 var _ tree.EvalSessionAccessor = &DummySessionAccessor{} 139 140 var errEvalSessionVar = pgerror.New(pgcode.ScalarOperationCannotRunWithoutFullSessionContext, 141 "cannot evaluate scalar expressions that access session variables in this context") 142 143 // GetSessionVar is part of the tree.EvalSessionAccessor interface. 144 func (ep *DummySessionAccessor) GetSessionVar( 145 _ context.Context, _ string, _ bool, 146 ) (bool, string, error) { 147 return false, "", errors.WithStack(errEvalSessionVar) 148 } 149 150 // SetSessionVar is part of the tree.EvalSessionAccessor interface. 151 func (ep *DummySessionAccessor) SetSessionVar(_ context.Context, _, _ string) error { 152 return errors.WithStack(errEvalSessionVar) 153 } 154 155 // HasAdminRole is part of the tree.EvalSessionAccessor interface. 156 func (ep *DummySessionAccessor) HasAdminRole(_ context.Context) (bool, error) { 157 return false, errors.WithStack(errEvalSessionVar) 158 } 159 160 // DummyClientNoticeSender implements the tree.ClientNoticeSender interface. 161 type DummyClientNoticeSender struct{} 162 163 var _ tree.ClientNoticeSender = &DummyClientNoticeSender{} 164 165 // SendClientNotice is part of the tree.ClientNoticeSender interface. 166 func (c *DummyClientNoticeSender) SendClientNotice(context.Context, error) {} 167 168 // DummyTenantOperator implements the tree.TenantOperator interface. 169 type DummyTenantOperator struct{} 170 171 var _ tree.TenantOperator = &DummyTenantOperator{} 172 173 var errEvalTenant = pgerror.New(pgcode.ScalarOperationCannotRunWithoutFullSessionContext, 174 "cannot evaluate tenant operation in this context") 175 176 // CreateTenant is part of the tree.TenantOperator interface. 177 func (c *DummyTenantOperator) CreateTenant(_ context.Context, _ uint64, _ []byte) error { 178 return errors.WithStack(errEvalTenant) 179 } 180 181 // DestroyTenant is part of the tree.TenantOperator interface. 182 func (c *DummyTenantOperator) DestroyTenant(_ context.Context, _ uint64) error { 183 return errors.WithStack(errEvalTenant) 184 }