@@ -66,12 +66,10 @@ func ParseSchema(sql string) (*core.SQLSchema, error) {
6666
6767 w := & walk.AstWalker {
6868 Fn : func (ctx interface {}, node interface {}) (stop bool ) {
69- // log.Printf("node type %T", node)
7069 switch stmt := node .(type ) {
7170 case * tree.CreateTable :
7271 parseTable (schema , stmt )
7372 case * tree.CreateIndex :
74- // fmt.Println("index name: ", stmt.Name)
7573 refTable := schema .Tables [stmt .Table .TableName .Normalize ()]
7674 if stmt .Unique {
7775 refTable .Constraints = append (refTable .Constraints , & core.SQLTableConstraint {
@@ -177,35 +175,26 @@ func findTableDeps(schema *core.SQLSchema, table *tree.SelectClause, macro []cor
177175 case * tree.Subquery :
178176 case * tree.ParenSelect :
179177 walk (ctx , s .Select )
180- // fmt.Printf("FindSelect %T %s\n", s, s)
181178 case * tree.Select :
182179 walk (ctx , s .Select )
183180 case * tree.TableName :
184181 ctx .tables = append (ctx .tables , s .TableName .Normalize ())
185- // fmt.Printf("FindTableName %T %s\n", s, s)
186182 case * tree.AliasedTableExpr :
187183 subCtx := & FindTableDepsCtx {}
188184 walk (subCtx , s .Expr )
189- // fmt.Printf("FindAliasedTableExpr %T %s (%s|%s|%s)\n", s, s, s.Expr, s.As, subCtx.tables)
190185 ctx .tables = append (ctx .tables , subCtx .tables ... )
191186 ctx .Tables = append (ctx .Tables , core.TableDeps {
192187 Names : subCtx .tables ,
193188 As : s .As .Alias .Normalize (),
194189 })
195190 case * tree.JoinTableExpr :
196- // fmt.Printf("FindJoinTableExpr %T %s (%s|%s|%s|%s)\n", s, s, s.JoinType, s.Left, s.Right, s.Cond)
197- // fmt.Printf("> Left %T %s\n", s.Left, s.Left)
198- // fmt.Printf("> Right %T %s\n", s.Right, s.Right)
199191 walk (ctx , s .Left )
200192 walk (ctx , s .Right )
201193 query .From = s .String ()
202194 case * tree.Where :
203- // fmt.Println("Where", s)
204195 if s != nil && s .Expr != nil {
205196 query .Where = s .Expr .String ()
206197 }
207- case * tree.GroupBy :
208- // fmt.Println("GROUP BY", s)
209198 default :
210199 fmt .Printf ("not supported : %T %s\n " , s , s )
211200 }
@@ -456,9 +445,7 @@ func parseTable(schema *core.SQLSchema, stmt *tree.CreateTable) {
456445}
457446
458447func parseAlterTable (schema * core.SQLSchema , stmt * tree.AlterTable ) {
459- // fmt.Println("alter table")
460448 for _ , cmd := range stmt .Cmds {
461- // fmt.Println("cmd type: ", cmd)
462449 switch cmd := cmd .(type ) {
463450 case * tree.AlterTableDropColumn :
464451 refTable := schema .Tables [stmt .Table .ToTableName ().TableName .Normalize ()]
@@ -520,7 +507,6 @@ func parseAlterTable(schema *core.SQLSchema, stmt *tree.AlterTable) {
520507 TableColumns : NameListToStrings (fk .ToCols ),
521508 })
522509 }
523-
524510 }
525511 }
526512}
0 commit comments