Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,11 @@ type Use struct {

// Format formats the node.
func (node *Use) Format(buf *TrackedBuffer) {
buf.Myprintf("use %v", node.DBName)
if node.DBName.v != "" {
buf.Myprintf("use %v", node.DBName)
} else {
buf.Myprintf("use")
}
}

// WalkSubtree walks the nodes of the subtree.
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,10 @@ use_statement:
{
$$ = &Use{DBName: $2}
}
| USE
{
$$ = &Use{DBName:TableIdent{v:""}}
}

other_statement:
DESC force_eof
Expand Down
39 changes: 39 additions & 0 deletions go/vt/vtgate/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,3 +941,42 @@ func TestPassthroughDDL(t *testing.T) {
sbc2.Queries = nil
masterSession.TargetString = ""
}

func TestParseEmptyTargetSingleKeyspace(t *testing.T) {
r, _, _, _ := createExecutorEnv()
altVSchema := &vindexes.VSchema{
Keyspaces: map[string]*vindexes.KeyspaceSchema{
KsTestUnsharded: r.vschema.Keyspaces[KsTestUnsharded],
},
}
r.vschema = altVSchema

got := r.ParseTarget("")
want := querypb.Target{
Keyspace: KsTestUnsharded,
TabletType: topodatapb.TabletType_MASTER,
}
if !proto.Equal(&got, &want) {
t.Errorf("ParseTarget(%s): %v, want %v", "@master", got, want)
}
}

func TestParseEmptyTargetMultiKeyspace(t *testing.T) {
r, _, _, _ := createExecutorEnv()
altVSchema := &vindexes.VSchema{
Keyspaces: map[string]*vindexes.KeyspaceSchema{
KsTestUnsharded: r.vschema.Keyspaces[KsTestUnsharded],
KsTestSharded: r.vschema.Keyspaces[KsTestSharded],
},
}
r.vschema = altVSchema

got := r.ParseTarget("")
want := querypb.Target{
Keyspace: "",
TabletType: topodatapb.TabletType_MASTER,
}
if !proto.Equal(&got, &want) {
t.Errorf("ParseTarget(%s): %v, want %v", "@master", got, want)
}
}