VisitAliasedRelation visits the node
(ctx *antlrgen.AliasedRelationContext)
| 836 | |
| 837 | // VisitAliasedRelation visits the node |
| 838 | func (v *ASTBuilder) VisitAliasedRelation(ctx *antlrgen.AliasedRelationContext) interface{} { |
| 839 | v.Logger.Debugf("VisitAliasedRelation: %s", ctx.GetText()) |
| 840 | |
| 841 | level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx) |
| 842 | mapKey := v.SQL2AqlCtx.mapKey |
| 843 | |
| 844 | // handle identifier |
| 845 | if ctx.Identifier() != nil { |
| 846 | v.SQL2AqlCtx.MapJoinTables[v.SQL2AqlCtx.mapKey] = append(v.SQL2AqlCtx.MapJoinTables[v.SQL2AqlCtx.mapKey], |
| 847 | queryCom.Join{ |
| 848 | Alias: v.getText(ctx.Identifier()), |
| 849 | }) |
| 850 | } else { |
| 851 | v.SQL2AqlCtx.MapJoinTables[v.SQL2AqlCtx.mapKey] = append(v.SQL2AqlCtx.MapJoinTables[v.SQL2AqlCtx.mapKey], |
| 852 | queryCom.Join{}) |
| 853 | } |
| 854 | |
| 855 | // handle relationPrimary |
| 856 | v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery) |
| 857 | child, _ := v.Visit(ctx.RelationPrimary()).(tree.IRelation) |
| 858 | if ctx.Identifier() == nil { |
| 859 | child.SetValue(fmt.Sprintf("Relation: (%s)", v.getText(ctx.BaseParserRuleContext))) |
| 860 | v.setCtxLevels(v.SQL2AqlCtx, level-1, levelWith, levelQuery) |
| 861 | v.SQL2AqlCtx.mapKey = mapKey |
| 862 | return child |
| 863 | } |
| 864 | |
| 865 | // handle columnAliases |
| 866 | var aliasedRelation *tree.AliasedRelation |
| 867 | identifier, _ := v.Visit(ctx.Identifier()).(*tree.Identifier) |
| 868 | if ctxColumnAliases, ok := ctx.ColumnAliases().(*antlrgen.ColumnAliasesContext); ok { |
| 869 | ctxArr := ctxColumnAliases.AllIdentifier() |
| 870 | columnAliases := make([]*tree.Identifier, len(ctxArr)) |
| 871 | last := len(v.SQL2AqlCtx.MapJoinTables[v.SQL2AqlCtx.mapKey]) - 1 |
| 872 | subqueryKey := v.generateKey(levelQuery+1, typeSubQuery, last) |
| 873 | for i, c := range ctxArr { |
| 874 | v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery) |
| 875 | if i < len(v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey]) { |
| 876 | v.SQL2AqlCtx.MapMeasures[subqueryKey][i].Alias = v.getText(c) |
| 877 | } else { |
| 878 | v.SQL2AqlCtx.MapMeasures[subqueryKey] = |
| 879 | append(v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey], |
| 880 | queryCom.Measure{ |
| 881 | Alias: v.getText(c), |
| 882 | }) |
| 883 | } |
| 884 | columnAliases[i], _ = v.Visit(c).(*tree.Identifier) |
| 885 | } |
| 886 | |
| 887 | aliasedRelation = tree.NewAliasedRelation( |
| 888 | v.getLocation(ctx), |
| 889 | child, |
| 890 | identifier, |
| 891 | columnAliases) |
| 892 | } else { |
| 893 | aliasedRelation = tree.NewAliasedRelation( |
| 894 | v.getLocation(ctx), |
| 895 | child, |
no test coverage detected