Compute the output columns for a statement. Return an error if column references are ambiguous Return an error if column references don't exist Return an error if a table is referenced twice Return an error if an unknown column is referenced
(qc *QueryCatalog, node ast.Node)
| 479 | // Return an error if a table is referenced twice |
| 480 | // Return an error if an unknown column is referenced |
| 481 | func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, error) { |
| 482 | list := &ast.List{} |
| 483 | switch n := node.(type) { |
| 484 | case *ast.DeleteStmt: |
| 485 | if n.Relations != nil { |
| 486 | list = n.Relations |
| 487 | } else if n.FromClause != nil { |
| 488 | // Multi-table DELETE: walk FromClause to find tables |
| 489 | var tv tableVisitor |
| 490 | astutils.Walk(&tv, n.FromClause) |
| 491 | list = &tv.list |
| 492 | } |
| 493 | case *ast.InsertStmt: |
| 494 | list = &ast.List{ |
| 495 | Items: []ast.Node{n.Relation}, |
| 496 | } |
| 497 | case *ast.SelectStmt: |
| 498 | var tv tableVisitor |
| 499 | astutils.Walk(&tv, n.FromClause) |
| 500 | list = &tv.list |
| 501 | case *ast.TruncateStmt: |
| 502 | list = astutils.Search(n.Relations, func(node ast.Node) bool { |
| 503 | _, ok := node.(*ast.RangeVar) |
| 504 | return ok |
| 505 | }) |
| 506 | case *ast.RefreshMatViewStmt: |
| 507 | list = astutils.Search(n.Relation, func(node ast.Node) bool { |
| 508 | _, ok := node.(*ast.RangeVar) |
| 509 | return ok |
| 510 | }) |
| 511 | case *ast.UpdateStmt: |
| 512 | var tv tableVisitor |
| 513 | astutils.Walk(&tv, n.FromClause) |
| 514 | astutils.Walk(&tv, n.Relations) |
| 515 | list = &tv.list |
| 516 | } |
| 517 | |
| 518 | var tables []*Table |
| 519 | for _, item := range list.Items { |
| 520 | item := item |
| 521 | switch n := item.(type) { |
| 522 | |
| 523 | case *ast.RangeFunction: |
| 524 | var funcCall *ast.FuncCall |
| 525 | switch f := n.Functions.Items[0].(type) { |
| 526 | case *ast.List: |
| 527 | switch fi := f.Items[0].(type) { |
| 528 | case *ast.FuncCall: |
| 529 | funcCall = fi |
| 530 | case *ast.SQLValueFunction: |
| 531 | continue // TODO handle this correctly |
| 532 | default: |
| 533 | continue |
| 534 | } |
| 535 | case *ast.FuncCall: |
| 536 | funcCall = f |
| 537 | default: |
| 538 | return nil, fmt.Errorf("sourceTables: unsupported function call type %T", n.Functions.Items[0]) |
no test coverage detected