Skip to content

Commit 99d534b

Browse files
authored
refactor: rename DefaultKeyspace() to CurrentKeyspace() (#17303)
Signed-off-by: Andres Taylor <andres@planetscale.com>
1 parent 8c51043 commit 99d534b

File tree

11 files changed

+19
-17
lines changed

11 files changed

+19
-17
lines changed

go/test/vschemawrapper/vschema_wrapper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,12 @@ func (vw *VSchemaWrapper) getActualKeyspace() string {
299299
return ks.Name
300300
}
301301

302-
func (vw *VSchemaWrapper) DefaultKeyspace() (*vindexes.Keyspace, error) {
302+
func (vw *VSchemaWrapper) SelectedKeyspace() (*vindexes.Keyspace, error) {
303303
return vw.V.Keyspaces["main"].Keyspace, nil
304304
}
305305

306306
func (vw *VSchemaWrapper) AnyKeyspace() (*vindexes.Keyspace, error) {
307-
return vw.DefaultKeyspace()
307+
return vw.SelectedKeyspace()
308308
}
309309

310310
func (vw *VSchemaWrapper) FirstSortedKeyspace() (*vindexes.Keyspace, error) {

go/vt/vtgate/planbuilder/builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func buildDBDDLPlan(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vschema
275275
dbDDLstmt := stmt.(sqlparser.DBDDLStatement)
276276
ksName := dbDDLstmt.GetDatabaseName()
277277
if ksName == "" {
278-
ks, err := vschema.DefaultKeyspace()
278+
ks, err := vschema.SelectedKeyspace()
279279
if err != nil {
280280
return nil, err
281281
}
@@ -310,7 +310,7 @@ func buildDBDDLPlan(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vschema
310310
}
311311

312312
func buildLoadPlan(query string, vschema plancontext.VSchema) (*planResult, error) {
313-
keyspace, err := vschema.DefaultKeyspace()
313+
keyspace, err := vschema.SelectedKeyspace()
314314
if err != nil {
315315
return nil, err
316316
}
@@ -355,7 +355,7 @@ func buildFlushOptions(stmt *sqlparser.Flush, vschema plancontext.VSchema) (*pla
355355
return nil, vterrors.VT09012("FLUSH", vschema.TabletType().String())
356356
}
357357

358-
keyspace, err := vschema.DefaultKeyspace()
358+
keyspace, err := vschema.SelectedKeyspace()
359359
if err != nil {
360360
return nil, err
361361
}

go/vt/vtgate/planbuilder/bypass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func buildPlanForBypass(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vschema plancontext.VSchema) (*planResult, error) {
29-
keyspace, err := vschema.DefaultKeyspace()
29+
keyspace, err := vschema.SelectedKeyspace()
3030
if err != nil {
3131
return nil, err
3232
}

go/vt/vtgate/planbuilder/ddl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func buildGeneralDDLPlan(ctx context.Context, sql string, ddlStatement sqlparser
8181
}
8282

8383
func buildByPassPlan(sql string, vschema plancontext.VSchema, isDDL bool) (*planResult, error) {
84-
keyspace, err := vschema.DefaultKeyspace()
84+
keyspace, err := vschema.SelectedKeyspace()
8585
if err != nil {
8686
return nil, err
8787
}

go/vt/vtgate/planbuilder/operator_transformers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func routeToEngineRoute(ctx *plancontext.PlanningContext, op *operators.Route, h
545545
}
546546

547547
func newRoutingParams(ctx *plancontext.PlanningContext, opCode engine.Opcode) *engine.RoutingParameters {
548-
ks, _ := ctx.VSchema.DefaultKeyspace()
548+
ks, _ := ctx.VSchema.SelectedKeyspace()
549549
if ks == nil {
550550
// if we don't have a selected keyspace, any keyspace will do
551551
// this is used by operators that do not set the keyspace

go/vt/vtgate/planbuilder/plancontext/planning_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func CreatePlanningContext(stmt sqlparser.Statement,
9191
version querypb.ExecuteOptions_PlannerVersion,
9292
) (*PlanningContext, error) {
9393
ksName := ""
94-
if ks, _ := vschema.DefaultKeyspace(); ks != nil {
94+
if ks, _ := vschema.SelectedKeyspace(); ks != nil {
9595
ksName = ks.Name
9696
}
9797

go/vt/vtgate/planbuilder/plancontext/planning_context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (v *vschema) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Ta
201201
panic("implement me")
202202
}
203203

204-
func (v *vschema) DefaultKeyspace() (*vindexes.Keyspace, error) {
204+
func (v *vschema) SelectedKeyspace() (*vindexes.Keyspace, error) {
205205
// TODO implement me
206206
panic("implement me")
207207
}

go/vt/vtgate/planbuilder/plancontext/vschema.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ type VSchema interface {
2727
FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error)
2828
FindView(name sqlparser.TableName) sqlparser.SelectStatement
2929
FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error)
30-
DefaultKeyspace() (*vindexes.Keyspace, error)
30+
31+
// SelectedKeyspace returns the current keyspace if set, otherwise returns an error
32+
SelectedKeyspace() (*vindexes.Keyspace, error)
3133
TargetString() string
3234
Destination() key.Destination
3335
TabletType() topodatapb.TabletType

go/vt/vtgate/planbuilder/select.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func gen4SelectStmtPlanner(
4646
}
4747
if p != nil {
4848
used := "dual"
49-
keyspace, ksErr := vschema.DefaultKeyspace()
49+
keyspace, ksErr := vschema.SelectedKeyspace()
5050
if ksErr == nil {
5151
// we are just getting the ks to log the correct table use.
5252
// no need to fail this if we can't find the default keyspace
@@ -101,7 +101,7 @@ func gen4SelectStmtPlanner(
101101

102102
func gen4planSQLCalcFoundRows(vschema plancontext.VSchema, sel *sqlparser.Select, query string, reservedVars *sqlparser.ReservedVars) (*planResult, error) {
103103
ksName := ""
104-
if ks, _ := vschema.DefaultKeyspace(); ks != nil {
104+
if ks, _ := vschema.SelectedKeyspace(); ks != nil {
105105
ksName = ks.Name
106106
}
107107
semTable, err := semantics.Analyze(sel, ksName, vschema)

go/vt/vtgate/planbuilder/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func buildVschemaKeyspacesPlan(vschema plancontext.VSchema) (engine.Primitive, e
676676

677677
func buildVschemaTablesPlan(vschema plancontext.VSchema) (engine.Primitive, error) {
678678
vs := vschema.GetVSchema()
679-
ks, err := vschema.DefaultKeyspace()
679+
ks, err := vschema.SelectedKeyspace()
680680
if err != nil {
681681
return nil, err
682682
}

go/vt/vtgate/vcursor_impl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ func (vc *vcursorImpl) getActualKeyspace() string {
392392
return ks.Name
393393
}
394394

395-
// DefaultKeyspace returns the default keyspace of the current request
395+
// SelectedKeyspace returns the selected keyspace of the current request
396396
// if there is one. If the keyspace specified in the target cannot be
397397
// identified, it returns an error.
398-
func (vc *vcursorImpl) DefaultKeyspace() (*vindexes.Keyspace, error) {
398+
func (vc *vcursorImpl) SelectedKeyspace() (*vindexes.Keyspace, error) {
399399
if ignoreKeyspace(vc.keyspace) {
400400
return nil, errNoKeyspace
401401
}
@@ -409,7 +409,7 @@ func (vc *vcursorImpl) DefaultKeyspace() (*vindexes.Keyspace, error) {
409409
var errNoDbAvailable = vterrors.NewErrorf(vtrpcpb.Code_FAILED_PRECONDITION, vterrors.NoDB, "no database available")
410410

411411
func (vc *vcursorImpl) AnyKeyspace() (*vindexes.Keyspace, error) {
412-
keyspace, err := vc.DefaultKeyspace()
412+
keyspace, err := vc.SelectedKeyspace()
413413
if err == nil {
414414
return keyspace, nil
415415
}

0 commit comments

Comments
 (0)