nodeTableExpr handles tree.TableExpr nodes.
(ctx *Context, node tree.TableExpr)
| 25 | |
| 26 | // nodeTableExpr handles tree.TableExpr nodes. |
| 27 | func nodeTableExpr(ctx *Context, node tree.TableExpr) (vitess.TableExpr, error) { |
| 28 | switch node := node.(type) { |
| 29 | case *tree.AliasedTableExpr: |
| 30 | return nodeAliasedTableExpr(ctx, node) |
| 31 | case *tree.JoinTableExpr: |
| 32 | left, err := nodeTableExpr(ctx, node.Left) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | right, err := nodeTableExpr(ctx, node.Right) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | var condition vitess.JoinCondition |
| 41 | switch treeCondition := node.Cond.(type) { |
| 42 | case tree.NaturalJoinCond: |
| 43 | // Nothing to do, the default value is equivalent |
| 44 | case *tree.OnJoinCond: |
| 45 | onExpr, err := nodeExpr(ctx, treeCondition.Expr) |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | condition.On = onExpr |
| 50 | case *tree.UsingJoinCond: |
| 51 | condition.Using = make([]vitess.ColIdent, len(treeCondition.Cols)) |
| 52 | for i := range treeCondition.Cols { |
| 53 | condition.Using[i] = vitess.NewColIdent(string(treeCondition.Cols[i])) |
| 54 | } |
| 55 | case nil: |
| 56 | // cross join (no join condition) |
| 57 | default: |
| 58 | return nil, errors.Errorf("unknown JOIN condition: `%T`", treeCondition) |
| 59 | } |
| 60 | var joinType string |
| 61 | switch node.JoinType { |
| 62 | case tree.AstFull: |
| 63 | joinType = vitess.FullOuterJoinStr |
| 64 | case tree.AstLeft: |
| 65 | if condition.On == nil && len(condition.Using) == 0 { |
| 66 | joinType = vitess.NaturalLeftJoinStr |
| 67 | } else { |
| 68 | joinType = vitess.LeftJoinStr |
| 69 | } |
| 70 | case tree.AstRight: |
| 71 | if condition.On == nil && len(condition.Using) == 0 { |
| 72 | joinType = vitess.NaturalRightJoinStr |
| 73 | } else { |
| 74 | joinType = vitess.RightJoinStr |
| 75 | } |
| 76 | case tree.AstCross, tree.AstInner: |
| 77 | joinType = vitess.JoinStr |
| 78 | case "": |
| 79 | if condition.On == nil && len(condition.Using) == 0 { |
| 80 | joinType = vitess.NaturalJoinStr |
| 81 | } else { |
| 82 | joinType = vitess.JoinStr |
| 83 | } |
| 84 | default: |
no test coverage detected