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
37 changes: 37 additions & 0 deletions data/test/vtgate/from_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,43 @@
}
}

# keyspace-qualified queries
"select user.user.col1, main.main1.col1 from user.user join main.main1 where main.main1.col2 = user.user.col2"
{
"Original": "select user.user.col1, main.main1.col1 from user.user join main.main1 where main.main1.col2 = user.user.col2",
"Instructions": {
"Opcode": "Join",
"Left": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user.col1, user.col2 from user",
"FieldQuery": "select user.col1, user.col2 from user where 1 != 1"
},
"Right": {
"Opcode": "SelectUnsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"Query": "select main1.col1 from main1 where main1.col2 = :user_col2",
"FieldQuery": "select main1.col1 from main1 where 1 != 1",
"JoinVars": {
"user_col2": {}
}
},
"Cols": [
-1,
1
],
"Vars": {
"user_col2": 1
}
}
}

# duplicate symbols
"select user.id from user join user"
"duplicate symbol: user"
Expand Down
4 changes: 0 additions & 4 deletions data/test/vtgate/unsupported_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
"select id, (select id from user) from user"
"unsupported: scatter subquery"

# keyspace name
"select * from user.user"
"unsupported: keyspace name qualifier for tables"

# natural join
"select * from user natural join user_extra"
"unsupported: natural join"
Expand Down
13 changes: 11 additions & 2 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ type TableName struct {

// Format formats the node.
func (node *TableName) Format(buf *TrackedBuffer) {
// node can be nil for unqualified column names.
if node == nil {
return
}
if node.Qualifier != "" {
buf.Myprintf("%v.", node.Qualifier)
}
Expand All @@ -664,6 +668,11 @@ func (node *TableName) WalkSubtree(visit Visit) error {
)
}

// IsEmpty returns true if TableName is nil or empty.
func (node *TableName) IsEmpty() bool {
return node == nil || (node.Qualifier == "" && node.Name == "")
}

// ParenTableExpr represents a parenthesized list of TableExpr.
type ParenTableExpr struct {
Exprs TableExprs
Expand Down Expand Up @@ -1179,12 +1188,12 @@ type ColName struct {
// table or column this node references.
Metadata interface{}
Name SQLName
Qualifier SQLName
Qualifier *TableName
}

// Format formats the node.
func (node *ColName) Format(buf *TrackedBuffer) {
if node.Qualifier != "" {
if !node.Qualifier.IsEmpty() {
buf.Myprintf("%v.", node.Qualifier)
}
buf.Myprintf("%v", node.Name)
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func TestValid(t *testing.T) {
input: "select /* a */ a from t",
}, {
input: "select /* a.b */ a.b from t",
}, {
input: "select /* a.b.c */ a.b.c from t",
}, {
input: "select /* keyword a.b */ `By`.`bY` from t",
output: "select /* keyword a.b */ `By`.`by` from t",
Expand Down
Loading