Skip to content

Commit 0698355

Browse files
committed
Merge pull request #1614 from sougou/v3
V3: More features
2 parents 01af7d7 + d855f13 commit 0698355

34 files changed

Lines changed: 641 additions & 528 deletions

File tree

data/test/vtgate/dml_cases.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
"delete from nouser"
77
"table nouser not found"
88

9+
# explicit keyspace reference
10+
"update main.m1 set val = 1"
11+
{
12+
"Original": "update main.m1 set val = 1",
13+
"Instructions": {
14+
"Opcode": "UpdateUnsharded",
15+
"Keyspace": {
16+
"Name": "main",
17+
"Sharded": false
18+
},
19+
"Query": "update m1 set val = 1",
20+
"Table": "m1"
21+
}
22+
}
23+
924
# update unsharded
1025
"update main1 set val = 1"
1126
{

data/test/vtgate/from_cases.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,25 @@
790790
}
791791
}
792792

793+
# implicit table reference for unsharded keyspace
794+
"select main.foo.col from main.foo"
795+
{
796+
"Original": "select main.foo.col from main.foo",
797+
"Instructions": {
798+
"Opcode": "SelectUnsharded",
799+
"Keyspace": {
800+
"Name": "main",
801+
"Sharded": false
802+
},
803+
"Query": "select foo.col from foo",
804+
"FieldQuery": "select foo.col from foo where 1 != 1"
805+
}
806+
}
807+
808+
# implicit table reference for sharded keyspace
809+
"select user.foo.col from user.foo"
810+
"table foo not found"
811+
793812
# duplicate symbols
794813
"select user.id from user join user"
795814
"duplicate symbol: user"

data/test/vtgate/schema_test.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"Owner": "user"
2121
}
2222
},
23-
"Classes": {
23+
"Tables": {
2424
"user": {
2525
"ColVindexes": [
2626
{
@@ -77,23 +77,14 @@
7777
}
7878
]
7979
}
80-
},
81-
"Tables": {
82-
"user": "user",
83-
"user_extra": "user_extra",
84-
"music": "music",
85-
"music_extra": "music_extra"
8680
}
8781
},
8882
"main": {
89-
"Classes": {
83+
"Tables": {
84+
"main1": {},
9085
"seq": {
9186
"Type": "Sequence"
9287
}
93-
},
94-
"Tables": {
95-
"main1": "",
96-
"seq": "seq"
9788
}
9889
}
9990
}

data/test/vtgate/unsupported_cases.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@
146146
"delete from user where col = (select id from main1)"
147147
"unsupported: subqueries in DML"
148148

149-
# qualified table name in DMLs
150-
"update u.user set id = 1"
151-
"unsupported: compex table expression in DML"
152-
153149
# update with no where clause
154150
"update user set val = 1"
155151
"unsupported: multi-shard where clause in DML"

examples/demo/schema/vschema.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"Type": "numeric"
2929
}
3030
},
31-
"Classes": {
31+
"Tables": {
3232
"user": {
3333
"ColVindexes": [
3434
{
@@ -89,26 +89,18 @@
8989
}
9090
]
9191
}
92-
},
93-
"Tables": {
94-
"user": "user",
95-
"user_extra": "user_extra",
96-
"music": "music",
97-
"music_extra": "music_extra",
98-
"music_user_idx": "music_user_idx"
9992
}
10093
},
10194
"lookup": {
10295
"Sharded": false,
103-
"Classes": {
104-
"seq": {
105-
"Type": "Sequence"
106-
}
107-
},
10896
"Tables": {
109-
"user_seq": "seq",
110-
"music_seq": "seq",
111-
"name_user_idx": ""
97+
"user_seq": {
98+
"Type": "Sequence"
99+
},
100+
"music_seq": {
101+
"Type": "Sequence"
102+
},
103+
"name_user_idx": {}
112104
}
113105
}
114106
}

go/cmd/vtgateclienttest/services/callerid.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func (c *callerIDClient) checkCallerID(ctx context.Context, received string) (bo
6565
return true, fmt.Errorf("SUCCESS: callerid matches")
6666
}
6767

68-
func (c *callerIDClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
68+
func (c *callerIDClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
6969
if ok, err := c.checkCallerID(ctx, sql); ok {
7070
return nil, err
7171
}
72-
return c.fallbackClient.Execute(ctx, sql, bindVariables, tabletType, session, notInTransaction)
72+
return c.fallbackClient.Execute(ctx, sql, bindVariables, keyspace, tabletType, session, notInTransaction)
7373
}
7474

7575
func (c *callerIDClient) ExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
@@ -118,11 +118,11 @@ func (c *callerIDClient) ExecuteBatchKeyspaceIds(ctx context.Context, queries []
118118
return c.fallbackClient.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, asTransaction, session)
119119
}
120120

121-
func (c *callerIDClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
121+
func (c *callerIDClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
122122
if ok, err := c.checkCallerID(ctx, sql); ok {
123123
return err
124124
}
125-
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, tabletType, sendReply)
125+
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, keyspace, tabletType, sendReply)
126126
}
127127

128128
func (c *callerIDClient) StreamExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {

go/cmd/vtgateclienttest/services/echo.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ func echoQueryResult(vals map[string]interface{}) *sqltypes.Result {
8686
return qr
8787
}
8888

89-
func (c *echoClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
89+
func (c *echoClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
9090
if strings.HasPrefix(sql, EchoPrefix) {
9191
return echoQueryResult(map[string]interface{}{
9292
"callerId": callerid.EffectiveCallerIDFromContext(ctx),
9393
"query": sql,
9494
"bindVars": bindVariables,
95+
"keyspace": keyspace,
9596
"tabletType": tabletType,
9697
"session": session,
9798
"notInTransaction": notInTransaction,
9899
}), nil
99100
}
100-
return c.fallbackClient.Execute(ctx, sql, bindVariables, tabletType, session, notInTransaction)
101+
return c.fallbackClient.Execute(ctx, sql, bindVariables, keyspace, tabletType, session, notInTransaction)
101102
}
102103

103104
func (c *echoClient) ExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
@@ -205,17 +206,18 @@ func (c *echoClient) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtg
205206
return c.fallbackClient.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, asTransaction, session)
206207
}
207208

208-
func (c *echoClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
209+
func (c *echoClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
209210
if strings.HasPrefix(sql, EchoPrefix) {
210211
sendReply(echoQueryResult(map[string]interface{}{
211212
"callerId": callerid.EffectiveCallerIDFromContext(ctx),
212213
"query": sql,
213214
"bindVars": bindVariables,
215+
"keyspace": keyspace,
214216
"tabletType": tabletType,
215217
}))
216218
return nil
217219
}
218-
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, tabletType, sendReply)
220+
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, keyspace, tabletType, sendReply)
219221
}
220222

221223
func (c *echoClient) StreamExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {

go/cmd/vtgateclienttest/services/errors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ func trimmedRequestToError(received string) error {
118118
}
119119
}
120120

121-
func (c *errorClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
121+
func (c *errorClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
122122
if err := requestToPartialError(sql, session); err != nil {
123123
return nil, err
124124
}
125125
if err := requestToError(sql); err != nil {
126126
return nil, err
127127
}
128-
return c.fallbackClient.Execute(ctx, sql, bindVariables, tabletType, session, notInTransaction)
128+
return c.fallbackClient.Execute(ctx, sql, bindVariables, keyspace, tabletType, session, notInTransaction)
129129
}
130130

131131
func (c *errorClient) ExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
@@ -192,11 +192,11 @@ func (c *errorClient) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vt
192192
return c.fallbackClient.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, asTransaction, session)
193193
}
194194

195-
func (c *errorClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
195+
func (c *errorClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
196196
if err := requestToError(sql); err != nil {
197197
return err
198198
}
199-
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, tabletType, sendReply)
199+
return c.fallbackClient.StreamExecute(ctx, sql, bindVariables, keyspace, tabletType, sendReply)
200200
}
201201

202202
func (c *errorClient) StreamExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {

go/cmd/vtgateclienttest/services/fallback.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func newFallbackClient(fallback vtgateservice.VTGateService) fallbackClient {
2727
return fallbackClient{fallback: fallback}
2828
}
2929

30-
func (c fallbackClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
31-
return c.fallback.Execute(ctx, sql, bindVariables, tabletType, session, notInTransaction)
30+
func (c fallbackClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
31+
return c.fallback.Execute(ctx, sql, bindVariables, keyspace, tabletType, session, notInTransaction)
3232
}
3333

3434
func (c fallbackClient) ExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
@@ -55,8 +55,8 @@ func (c fallbackClient) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*
5555
return c.fallback.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, asTransaction, session)
5656
}
5757

58-
func (c fallbackClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
59-
return c.fallback.StreamExecute(ctx, sql, bindVariables, tabletType, sendReply)
58+
func (c fallbackClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
59+
return c.fallback.StreamExecute(ctx, sql, bindVariables, keyspace, tabletType, sendReply)
6060
}
6161

6262
func (c fallbackClient) StreamExecuteShards(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, shards []string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {

go/cmd/vtgateclienttest/services/terminal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func newTerminalClient() *terminalClient {
2929
return &terminalClient{}
3030
}
3131

32-
func (c *terminalClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
32+
func (c *terminalClient) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool) (*sqltypes.Result, error) {
3333
if sql == "quit://" {
3434
log.Fatal("Received quit:// query. Going down.")
3535
}
@@ -60,7 +60,7 @@ func (c *terminalClient) ExecuteBatchKeyspaceIds(ctx context.Context, queries []
6060
return nil, errTerminal
6161
}
6262

63-
func (c *terminalClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
63+
func (c *terminalClient) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, sendReply func(*sqltypes.Result) error) error {
6464
return errTerminal
6565
}
6666

0 commit comments

Comments
 (0)