@@ -18,6 +18,7 @@ package vschemawrapper
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"strings"
23
24
@@ -275,17 +276,6 @@ func (vw *VSchemaWrapper) FindTableOrVindex(tab sqlparser.TableName) (*vindexes.
275
276
return vw .Vcursor .FindTableOrVindex (tab )
276
277
}
277
278
278
- func (vw * VSchemaWrapper ) getfirstKeyspace () (ks * vindexes.Keyspace ) {
279
- var f string
280
- for name , schema := range vw .V .Keyspaces {
281
- if f == "" || f > name {
282
- f = name
283
- ks = schema .Keyspace
284
- }
285
- }
286
- return
287
- }
288
-
289
279
func (vw * VSchemaWrapper ) getActualKeyspace () string {
290
280
if vw .Keyspace == nil {
291
281
return ""
@@ -301,15 +291,24 @@ func (vw *VSchemaWrapper) getActualKeyspace() string {
301
291
}
302
292
303
293
func (vw * VSchemaWrapper ) SelectedKeyspace () (* vindexes.Keyspace , error ) {
304
- return vw .V . Keyspaces [ "main" ]. Keyspace , nil
294
+ return vw .AnyKeyspace ()
305
295
}
306
296
307
297
func (vw * VSchemaWrapper ) AnyKeyspace () (* vindexes.Keyspace , error ) {
308
- return vw .SelectedKeyspace ()
298
+ ks , found := vw .V .Keyspaces ["main" ]
299
+ if found {
300
+ return ks .Keyspace , nil
301
+ }
302
+
303
+ for _ , ks := range vw .V .Keyspaces {
304
+ return ks .Keyspace , nil
305
+ }
306
+
307
+ return nil , errors .New ("no keyspace found in vschema" )
309
308
}
310
309
311
310
func (vw * VSchemaWrapper ) FirstSortedKeyspace () (* vindexes.Keyspace , error ) {
312
- return vw .V . Keyspaces [ "main" ]. Keyspace , nil
311
+ return vw .AnyKeyspace ()
313
312
}
314
313
315
314
func (vw * VSchemaWrapper ) TargetString () string {
@@ -344,12 +343,12 @@ func (vw *VSchemaWrapper) IsViewsEnabled() bool {
344
343
345
344
// FindMirrorRule finds the mirror rule for the requested keyspace, table
346
345
// name, and the tablet type in the VSchema.
347
- func (vs * VSchemaWrapper ) FindMirrorRule (tab sqlparser.TableName ) (* vindexes.MirrorRule , error ) {
346
+ func (vw * VSchemaWrapper ) FindMirrorRule (tab sqlparser.TableName ) (* vindexes.MirrorRule , error ) {
348
347
destKeyspace , destTabletType , _ , err := topoproto .ParseDestination (tab .Qualifier .String (), topodatapb .TabletType_PRIMARY )
349
348
if err != nil {
350
349
return nil , err
351
350
}
352
- mirrorRule , err := vs .V .FindMirrorRule (destKeyspace , tab .Name .String (), destTabletType )
351
+ mirrorRule , err := vw .V .FindMirrorRule (destKeyspace , tab .Name .String (), destTabletType )
353
352
if err != nil {
354
353
return nil , err
355
354
}
0 commit comments