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
2 changes: 0 additions & 2 deletions go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ func ASTToStatementType(stmt Statement) StatementType {
return StmtSRollback
case *Release:
return StmtRelease
case *ShowTableStatus:
return StmtShow
default:
return StmtUnknown
}
Expand Down
67 changes: 53 additions & 14 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ type (
// DDLAction is an enum for DDL.Action
DDLAction int8

// Load is for s3 statement
Load struct {
InfileS3 string
}
Expand All @@ -253,19 +254,7 @@ type (

// Show represents a show statement.
Show struct {
Extended string
Type string
OnTable TableName
Table TableName
ShowTablesOpt *ShowTablesOpt
Scope Scope
ShowCollationFilterOpt Expr
}

// ShowTableStatus is a struct for SHOW TABLE STATUS queries.
ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
Internal ShowInternal
}

// Use represents a use statement.
Expand Down Expand Up @@ -344,13 +333,47 @@ func (*Select) iSelectStatement() {}
func (*Union) iSelectStatement() {}
func (*ParenSelect) iSelectStatement() {}
func (*Load) iStatement() {}
func (*ShowTableStatus) iStatement() {}

// ParenSelect can actually not be a top level statement,
// but we have to allow it because it's a requirement
// of SelectStatement.
func (*ParenSelect) iStatement() {}

//ShowInternal will represent all the show statement types.
type ShowInternal interface {
isShowInternal()
SQLNode
}

//ShowLegacy is of ShowInternal type, holds the legacy show ast struct.
type ShowLegacy struct {
Extended string
Type string
OnTable TableName
Table TableName
ShowTablesOpt *ShowTablesOpt
Scope Scope
ShowCollationFilterOpt Expr
}

//ShowColumns is of ShowInternal type, holds the show columns statement.
type ShowColumns struct {
Full string
Table TableName
DbName string
Filter *ShowFilter
}

// ShowTableStatus is of ShowInternal type, holds SHOW TABLE STATUS queries.
type ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
}

func (*ShowLegacy) isShowInternal() {}
func (*ShowColumns) isShowInternal() {}
func (*ShowTableStatus) isShowInternal() {}

// InsertRows represents the rows for an INSERT statement.
type InsertRows interface {
iInsertRows()
Expand Down Expand Up @@ -1401,6 +1424,22 @@ func (f *ForeignKeyDefinition) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *Show) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%v", node.Internal)
}

// Format formats the node.
func (node *ShowColumns) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show %s", node.Full)
buf.astPrintf(node, "columns from %v", node.Table)

buf.printIf(node.DbName != "", " from "+node.DbName)
if node.Filter != nil {
buf.astPrintf(node, "%v", node.Filter)
}
}

// Format formats the node.
func (node *ShowLegacy) Format(buf *TrackedBuffer) {
nodeType := strings.ToLower(node.Type)
if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys" || nodeType == "indexes" ||
nodeType == "databases" || nodeType == "keyspaces" || nodeType == "vitess_keyspaces" || nodeType == "vitess_shards" || nodeType == "vitess_tablets") && node.ShowTablesOpt != nil {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ var _ ConstraintInfo = &ForeignKeyDefinition{}
func (f *ForeignKeyDefinition) iConstraintInfo() {}

// HasOnTable returns true if the show statement has an "on" clause
func (node *Show) HasOnTable() bool {
func (node *ShowLegacy) HasOnTable() bool {
return node.OnTable.Name.v != ""
}

// HasTable returns true if the show statement has a parsed table name.
// Not all show statements parse table names.
func (node *Show) HasTable() bool {
func (node *ShowLegacy) HasTable() bool {
return node.Table.Name.v != ""
}

Expand Down
10 changes: 5 additions & 5 deletions go/vt/sqlparser/like_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestLikePrefixRegexp(t *testing.T) {
}

want := "^key.*$"
got := LikeToRegexp(show.(*Show).ShowTablesOpt.Filter.Like).String()
got := LikeToRegexp(show.(*Show).Internal.(*ShowLegacy).ShowTablesOpt.Filter.Like).String()

assert.Equal(t, want, got)
}
Expand All @@ -48,7 +48,7 @@ func TestLikeAnyCharsRegexp(t *testing.T) {
}

want := "^.*val1.*val2.*$"
got := LikeToRegexp(show.(*Show).ShowTablesOpt.Filter.Like).String()
got := LikeToRegexp(show.(*Show).Internal.(*ShowLegacy).ShowTablesOpt.Filter.Like).String()

assert.Equal(t, want, got)
}
Expand All @@ -60,7 +60,7 @@ func TestSingleAndMultipleCharsRegexp(t *testing.T) {
}

want := "^.val1.val2.*$"
got := LikeToRegexp(show.(*Show).ShowTablesOpt.Filter.Like).String()
got := LikeToRegexp(show.(*Show).Internal.(*ShowLegacy).ShowTablesOpt.Filter.Like).String()

assert.Equal(t, want, got)
}
Expand All @@ -72,7 +72,7 @@ func TestSpecialCharactersRegexp(t *testing.T) {
}

want := "^\\?\\.\\*\\?$"
got := LikeToRegexp(show.(*Show).ShowTablesOpt.Filter.Like).String()
got := LikeToRegexp(show.(*Show).Internal.(*ShowLegacy).ShowTablesOpt.Filter.Like).String()

assert.Equal(t, want, got)
}
Expand All @@ -84,7 +84,7 @@ func TestQuoteLikeSpecialCharacters(t *testing.T) {
}

want := "^part1.part2%part3.part4_part5.*$"
got := LikeToRegexp(show.(*Show).ShowTablesOpt.Filter.Like).String()
got := LikeToRegexp(show.(*Show).Internal.(*ShowLegacy).ShowTablesOpt.Filter.Like).String()

assert.Equal(t, want, got)
}
9 changes: 6 additions & 3 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,13 +1376,16 @@ var (
}, {
input: "show full tables where 1 = 0",
}, {
input: "show full columns from a like '%'",
input: "show full columns in a in b like '%'",
output: "show full columns from a from b like '%'",
}, {
input: "show full columns from messages from test_keyspace like '%'",
}, {
input: "show full fields from a like '%'",
input: "show full fields from a like '%'",
output: "show full columns from a like '%'",
}, {
input: "show fields from a like '%'",
input: "show fields from a where 1 = 1",
output: "show columns from a where 1 = 1",
}, {
input: "show triggers",
output: "show triggers",
Expand Down
37 changes: 28 additions & 9 deletions go/vt/sqlparser/rewriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading