VisitQuerySpecification visits the node
(ctx *antlrgen.QuerySpecificationContext)
| 403 | |
| 404 | // VisitQuerySpecification visits the node |
| 405 | func (v *ASTBuilder) VisitQuerySpecification(ctx *antlrgen.QuerySpecificationContext) interface{} { |
| 406 | v.Logger.Debugf("VisitQuerySpecification: %s", ctx.GetText()) |
| 407 | |
| 408 | level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx) |
| 409 | |
| 410 | // handle from => join/table |
| 411 | // first process from clause so that subquery/withQuery identifier can be found in expression |
| 412 | v.SQL2AqlCtx.exprOrigin = ExprOriginJoinOn |
| 413 | ctxArrRelation := ctx.AllRelation() |
| 414 | arrRelations := make([]tree.IRelation, len(ctxArrRelation)) |
| 415 | for i, c := range ctxArrRelation { |
| 416 | v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery) |
| 417 | arrRelations[i], _ = v.Visit(c).(tree.IRelation) |
| 418 | } |
| 419 | |
| 420 | var myFrom tree.IRelation |
| 421 | if len(arrRelations) > 0 { |
| 422 | relationL := arrRelations[0] |
| 423 | // synthesize implicit join nodes |
| 424 | for i := 1; i < len(arrRelations); i++ { |
| 425 | relationR := arrRelations[i] |
| 426 | relationL = tree.NewJoin(v.getLocation(ctx), tree.IMPLICIT, relationL, relationR, nil) |
| 427 | relationL.SetValue(fmt.Sprintf("Join: (%s)", v.getText(ctxArrRelation[i]))) |
| 428 | } |
| 429 | myFrom = relationL |
| 430 | } |
| 431 | |
| 432 | // handle select => measure |
| 433 | v.SQL2AqlCtx.exprOrigin = ExprOriginOthers |
| 434 | ctxArrSelectItem := ctx.AllSelectItem() |
| 435 | arrSelectItems := make([]tree.ISelectItem, len(ctxArrSelectItem)) |
| 436 | for i, c := range ctxArrSelectItem { |
| 437 | v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery) |
| 438 | arrSelectItems[i], _ = v.Visit(c).(tree.ISelectItem) |
| 439 | |
| 440 | if i < len(v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey]) { |
| 441 | // handle subquery/withQuery with columnAliases,8 |
| 442 | // subquery/withQuery columnalias has higher priority, ignore subquery/withQuery selectSingle identifier |
| 443 | switch item := arrSelectItems[i].(type) { |
| 444 | case *tree.SingleColumn: |
| 445 | v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey][i].Expr = util.GetSubstring(item.Expression.GetValue()) |
| 446 | case *tree.AllColumns: |
| 447 | v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey][i].Expr = v.getText(c) |
| 448 | } |
| 449 | } else { |
| 450 | // handle query or subquery/withQuery w/o columnAliases |
| 451 | switch item := arrSelectItems[i].(type) { |
| 452 | case *tree.SingleColumn: |
| 453 | var alias string |
| 454 | if item.Alias != nil { |
| 455 | alias = util.GetSubstring(item.Alias.GetValue()) |
| 456 | } |
| 457 | v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey] = append(v.SQL2AqlCtx.MapMeasures[v.SQL2AqlCtx.mapKey], |
| 458 | queryCom.Measure{ |
| 459 | Alias: alias, |
| 460 | Expr: util.GetSubstring(item.Expression.GetValue()), |
| 461 | }) |
| 462 | case *tree.AllColumns: |
nothing calls this directly
no test coverage detected