Skip to content

Commit 7569d6f

Browse files
yuananfbramp
authored andcommitted
Support show [full] tables from db_name
Signed-off-by: yuananf <[email protected]>
1 parent df35e18 commit 7569d6f

File tree

5 files changed

+2566
-2321
lines changed

5 files changed

+2566
-2321
lines changed

ast.go

+48-3
Original file line numberDiff line numberDiff line change
@@ -1277,13 +1277,31 @@ func (node VindexParam) walkSubtree(visit Visit) error {
12771277

12781278
// Show represents a show statement.
12791279
type Show struct {
1280-
Type string
1281-
OnTable TableName
1282-
Scope string
1280+
Type string
1281+
OnTable TableName
1282+
ShowTablesOpt *ShowTablesOpt
1283+
Scope string
12831284
}
12841285

12851286
// Format formats the node.
12861287
func (node *Show) Format(buf *TrackedBuffer) {
1288+
if node.Type == "tables" && node.ShowTablesOpt != nil {
1289+
opt := node.ShowTablesOpt
1290+
if opt.DbName != "" {
1291+
if opt.Filter != nil {
1292+
buf.Myprintf("show %s%stables from %s %v", opt.Extended, opt.Full, opt.DbName, opt.Filter)
1293+
} else {
1294+
buf.Myprintf("show %s%stables from %s", opt.Extended, opt.Full, opt.DbName)
1295+
}
1296+
} else {
1297+
if opt.Filter != nil {
1298+
buf.Myprintf("show %s%stables %v", opt.Extended, opt.Full, opt.Filter)
1299+
} else {
1300+
buf.Myprintf("show %s%stables", opt.Extended, opt.Full)
1301+
}
1302+
}
1303+
return
1304+
}
12871305
if node.Scope == "" {
12881306
buf.Myprintf("show %s", node.Type)
12891307
} else {
@@ -1303,6 +1321,33 @@ func (node *Show) walkSubtree(visit Visit) error {
13031321
return nil
13041322
}
13051323

1324+
// ShowTablesOpt is show tables option
1325+
type ShowTablesOpt struct {
1326+
Extended string
1327+
Full string
1328+
DbName string
1329+
Filter *ShowFilter
1330+
}
1331+
1332+
// ShowFilter is show tables filter
1333+
type ShowFilter struct {
1334+
Like string
1335+
Filter Expr
1336+
}
1337+
1338+
// Format formats the node.
1339+
func (node *ShowFilter) Format(buf *TrackedBuffer) {
1340+
if node.Like != "" {
1341+
buf.Myprintf("like '%s'", node.Like)
1342+
} else {
1343+
buf.Myprintf("where %v", node.Filter)
1344+
}
1345+
}
1346+
1347+
func (node *ShowFilter) walkSubtree(visit Visit) error {
1348+
return nil
1349+
}
1350+
13061351
// Use represents a use statement.
13071352
type Use struct {
13081353
DBName TableIdent

parse_test.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ var (
10731073
output: "show processlist",
10741074
}, {
10751075
input: "show full processlist",
1076-
output: "show full",
1076+
output: "show processlist",
10771077
}, {
10781078
input: "show profile cpu for query 1",
10791079
output: "show profile",
@@ -1102,11 +1102,32 @@ var (
11021102
input: "show table status",
11031103
output: "show table",
11041104
}, {
1105-
input: "show tables",
1106-
output: "show tables",
1105+
input: "show tables",
1106+
}, {
1107+
input: "show tables like '%keyspace%'",
1108+
}, {
1109+
input: "show tables where 1 = 0",
1110+
}, {
1111+
input: "show tables from a",
1112+
}, {
1113+
input: "show tables from a where 1 = 0",
1114+
}, {
1115+
input: "show tables from a like '%keyspace%'",
1116+
}, {
1117+
input: "show full tables",
1118+
}, {
1119+
input: "show full tables from a",
1120+
}, {
1121+
input: "show full tables in a",
1122+
output: "show full tables from a",
1123+
}, {
1124+
input: "show full tables from a like '%keyspace%'",
1125+
}, {
1126+
input: "show full tables from a where 1 = 0",
1127+
}, {
1128+
input: "show full tables like '%keyspace%'",
11071129
}, {
1108-
input: "show full tables",
1109-
output: "show full",
1130+
input: "show full tables where 1 = 0",
11101131
}, {
11111132
input: "show triggers",
11121133
output: "show triggers",

0 commit comments

Comments
 (0)