Skip to content

Commit

Permalink
Merge #61968
Browse files Browse the repository at this point in the history
61968: Fix missing node of sqlWalker in reducesql.go r=rafiss a=auxten

I wrote a [AST walker](https://github.com/auxten/postgresql-parser/blob/main/pkg/walk/walker.go) which modified from `pkg/testutils/reduce/reducesql/reducesql.go` and fixed some missing nodes in the switch case.

Co-authored-by: auxten <[email protected]>
  • Loading branch information
craig[bot] and auxten committed Mar 18, 2021
2 parents b90dd8c + 79c0e2a commit 75cf42e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/testutils/reduce/reducesql/reducesql.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,23 @@ func (w sqlWalker) Transform(s string, i int) (out string, ok bool, err error) {
case *tree.IndexTableDef:
case *tree.JoinTableExpr:
walk(node.Left, node.Right, node.Cond)
case *tree.Limit:
walk(node.Count)
case *tree.NotExpr:
walk(node.Expr)
case *tree.NumVal:
case *tree.OnJoinCond:
walk(node.Expr)
case *tree.Order:
walk(node.Expr, node.Table)
case *tree.OrExpr:
walk(node.Left, node.Right)
case *tree.ParenExpr:
walk(node.Expr)
case *tree.ParenSelect:
walk(node.Select)
case *tree.RangeCond:
walk(node.Left, node.From, node.To)
case *tree.RowsFromExpr:
for _, expr := range node.Items {
walk(expr)
Expand All @@ -223,6 +229,14 @@ func (w sqlWalker) Transform(s string, i int) (out string, ok bool, err error) {
walk(node.With)
}
walk(node.Select)
if node.OrderBy != nil {
for _, order := range node.OrderBy {
walk(order)
}
}
if node.Limit != nil {
walk(node.Limit)
}
case *tree.SelectClause:
walk(node.Exprs)
if node.Where != nil {
Expand All @@ -234,6 +248,16 @@ func (w sqlWalker) Transform(s string, i int) (out string, ok bool, err error) {
for _, table := range node.From.Tables {
walk(table)
}
if node.DistinctOn != nil {
for _, distinct := range node.DistinctOn {
walk(distinct)
}
}
if node.GroupBy != nil {
for _, group := range node.GroupBy {
walk(group)
}
}
case tree.SelectExpr:
walk(node.Expr)
case tree.SelectExprs:
Expand All @@ -247,7 +271,7 @@ func (w sqlWalker) Transform(s string, i int) (out string, ok bool, err error) {
case *tree.StrVal:
case *tree.Subquery:
walk(node.Select)
case *tree.TableName:
case *tree.TableName, tree.TableName:
case *tree.Tuple:
for _, expr := range node.Exprs {
walk(expr)
Expand Down

0 comments on commit 75cf42e

Please sign in to comment.