MCPcopy Create free account
hub / github.com/brimdata/super / sqlJoinCond

Method sqlJoinCond

compiler/semantic/sql.go:609–648  ·  view source on GitHub ↗
(cond ast.JoinCond, typ super.Type)

Source from the content-addressed store, hash-verified

607}
608
609func (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
650func andUsingExprs(cond ast.Node, exprs []sem.Expr) sem.Expr {
651 n := len(exprs)

Callers 1

sqlJoinMethod · 0.95

Calls 7

exprMethod · 0.95
NewThisFunction · 0.92
NewBinaryExprFunction · 0.92
andUsingExprsFunction · 0.85
booleanMethod · 0.80
resolveUnqualifiedMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected