(cond ast.JoinCond, typ super.Type)
| 607 | } |
| 608 | |
| 609 | func (t *translator) sqlJoinCond(cond ast.JoinCond, typ super.Type) sem.Expr { |
| 610 | switch cond := cond.(type) { |
| 611 | case *ast.JoinOnCond: |
| 612 | e, typ := t.expr(cond.Expr, typ) |
| 613 | t.checker.boolean(cond.Expr, typ) |
| 614 | return e |
| 615 | case *ast.JoinUsingCond: |
| 616 | jsch := t.scope.sql.(*joinUsingScope).joinScope |
| 617 | var exprs []sem.Expr |
| 618 | for _, id := range cond.Fields { |
| 619 | left, _, err := jsch.left.resolveUnqualified(id.Name) |
| 620 | if err != nil { |
| 621 | t.error(id, err) |
| 622 | continue |
| 623 | } |
| 624 | if left == nil { |
| 625 | t.error(id, fmt.Errorf("column %q in USING clause does not exist in left table", id.Name)) |
| 626 | continue |
| 627 | } |
| 628 | right, _, err := jsch.right.resolveUnqualified(id.Name) |
| 629 | if err != nil { |
| 630 | t.error(id, err) |
| 631 | continue |
| 632 | } |
| 633 | if right == nil { |
| 634 | t.error(id, fmt.Errorf("column %q in USING clause does not exist in right table", id.Name)) |
| 635 | continue |
| 636 | } |
| 637 | lhs := sem.NewThis(id, append([]string{"left"}, left...)) |
| 638 | rhs := sem.NewThis(id, append([]string{"right"}, right...)) |
| 639 | exprs = append(exprs, sem.NewBinaryExpr(id, "==", lhs, rhs)) |
| 640 | } |
| 641 | if len(exprs) == 0 { |
| 642 | return badExpr |
| 643 | } |
| 644 | return andUsingExprs(cond, exprs) |
| 645 | default: |
| 646 | panic(cond) |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | func andUsingExprs(cond ast.Node, exprs []sem.Expr) sem.Expr { |
| 651 | n := len(exprs) |
no test coverage detected