VisitNamedQuery visits the node
(ctx *antlrgen.NamedQueryContext)
| 293 | |
| 294 | // VisitNamedQuery visits the node |
| 295 | func (v *ASTBuilder) VisitNamedQuery(ctx *antlrgen.NamedQueryContext) interface{} { |
| 296 | v.Logger.Debugf("VisitNamedQuery: %s", ctx.GetText()) |
| 297 | |
| 298 | location := v.getLocation(ctx) |
| 299 | level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx) |
| 300 | |
| 301 | // handle name |
| 302 | if ctx.GetName() == nil { |
| 303 | panic(fmt.Errorf("missing with identifier at (line:%d, col:%d)", location.Line, location.CharPosition)) |
| 304 | } |
| 305 | identifier := v.getText(ctx.GetName()) |
| 306 | v.SQL2AqlCtx.MapQueryIdentifier[v.SQL2AqlCtx.mapKey] = identifier |
| 307 | v.addQIdentifier(v.SQL2AqlCtx, identifier, v.SQL2AqlCtx.mapKey) |
| 308 | name, _ := v.Visit(ctx.GetName()).(*tree.Identifier) |
| 309 | |
| 310 | // handle columnAliases |
| 311 | var columnAliases []*tree.Identifier |
| 312 | if ctxColumnAliase, ok := ctx.ColumnAliases().(*antlrgen.ColumnAliasesContext); ok { |
| 313 | ctxArr := ctxColumnAliase.AllIdentifier() |
| 314 | columnAliases = make([]*tree.Identifier, len(ctxArr)) |
| 315 | for i, c := range ctxArr { |
| 316 | v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey] = |
| 317 | append(v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey], |
| 318 | queryCom.Measure{ |
| 319 | Alias: v.getText(c), |
| 320 | }) |
| 321 | columnAliases[i], _ = v.Visit(c).(*tree.Identifier) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // handle query |
| 326 | v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery) |
| 327 | ctxQuery, ok := ctx.Query().(*antlrgen.QueryContext) |
| 328 | if !ok { |
| 329 | panic(fmt.Errorf("missing with query body at (line:%d, col:%d)", location.Line, location.CharPosition)) |
| 330 | } |
| 331 | query, _ := v.VisitQuery(ctxQuery).(*tree.Query) |
| 332 | withQuery := tree.NewWithQuery(v.getLocation(ctx), |
| 333 | name, |
| 334 | query, |
| 335 | columnAliases) |
| 336 | withQuery.SetValue(fmt.Sprintf("WithQuery: (%s)", v.getText(ctx.BaseParserRuleContext))) |
| 337 | |
| 338 | v.setCtxLevels(v.SQL2AqlCtx, level-1, levelWith, levelQuery) |
| 339 | return withQuery |
| 340 | } |
| 341 | |
| 342 | // VisitQueryNoWith visits the node |
| 343 | func (v *ASTBuilder) VisitQueryNoWith(ctx *antlrgen.QueryNoWithContext) interface{} { |
no test coverage detected