MCPcopy
hub / github.com/uber/aresdb / VisitJoinRelation

Method VisitJoinRelation

query/sql/sql_parser.go:752–815  ·  view source on GitHub ↗

*************** from clause ***************** VisitJoinRelation visits the node

(ctx *antlrgen.JoinRelationContext)

Source from the content-addressed store, hash-verified

750
751// VisitJoinRelation visits the node
752func (v *ASTBuilder) VisitJoinRelation(ctx *antlrgen.JoinRelationContext) interface{} {
753 v.Logger.Debugf("VisitJoinRelation: %s", ctx.GetText())
754
755 location := v.getLocation(ctx)
756 level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx)
757
758 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
759 left, _ := v.Visit(ctx.GetLeft()).(tree.IRelation)
760
761 var right tree.IRelation
762 if ctx.CROSS() != nil {
763 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
764 right, _ = v.VisitSampledRelation(ctx.GetRight().(*antlrgen.SampledRelationContext)).(tree.IRelation)
765 join := tree.NewJoin(v.getLocation(ctx), tree.CROSS, left, right, nil)
766 join.SetValue(fmt.Sprintf("Join: (%s)", v.getText(ctx.BaseParserRuleContext)))
767 return join
768 }
769
770 var criteria tree.IJoinCriteria
771 if ctx.NATURAL() != nil {
772 if levelQuery != 0 {
773 panic(fmt.Errorf("natural join not supported at subquery/withQuery at (line:%d, col:%d)",
774 location.Line, location.CharPosition))
775 }
776 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
777 right, _ = v.VisitSampledRelation(ctx.GetRight().(*antlrgen.SampledRelationContext)).(tree.IRelation)
778 criteria = tree.NewNaturalJoin()
779 } else {
780 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
781 right, _ = v.Visit(ctx.GetRightRelation()).(tree.IRelation)
782
783 ctxJoinCriteria, ok := ctx.JoinCriteria().(*antlrgen.JoinCriteriaContext)
784 if !ok {
785 panic(fmt.Errorf("missing join criteria at (line:%d, col:%d)", location.Line, location.CharPosition))
786 }
787 if ctxJoinCriteria.ON() != nil {
788 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
789 v.SQL2AqlCtx.exprCheck = true
790 v.Visit(ctx.JoinCriteria().(*antlrgen.JoinCriteriaContext).
791 BooleanExpression())
792 v.SQL2AqlCtx.exprCheck = false
793 joinOn, _ := v.Visit(ctx.JoinCriteria().(*antlrgen.JoinCriteriaContext).
794 BooleanExpression()).(tree.IExpression)
795 criteria = tree.NewJoinOn(joinOn)
796 } else if ctxJoinCriteria.USING() != nil {
797 ctxArr := ctx.JoinCriteria().(*antlrgen.JoinCriteriaContext).AllIdentifier()
798 expressions := make([]*tree.Identifier, len(ctxArr))
799 for i, c := range ctxArr {
800 expressions[i], _ = v.Visit(c).(*tree.Identifier)
801 }
802 criteria = tree.NewJoinUsing(expressions)
803 }
804 }
805
806 joinType := v.getJoinType(ctx)
807 if joinType != tree.LEFT {
808 panic(fmt.Errorf("join type %v not supported yet at (line:%d, col:%d)",
809 tree.JoinTypes[joinType], location.Line, location.CharPosition))

Callers

nothing calls this directly

Calls 15

getLocationMethod · 0.95
getCtxLevelsMethod · 0.95
setCtxLevelsMethod · 0.95
VisitMethod · 0.95
VisitSampledRelationMethod · 0.95
getTextMethod · 0.95
getJoinTypeMethod · 0.95
NewJoinFunction · 0.92
NewNaturalJoinFunction · 0.92
NewJoinOnFunction · 0.92
NewJoinUsingFunction · 0.92
CROSSMethod · 0.80

Tested by

no test coverage detected