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

Method VisitQueryNoWith

query/sql/sql_parser.go:343–402  ·  view source on GitHub ↗

VisitQueryNoWith visits the node

(ctx *antlrgen.QueryNoWithContext)

Source from the content-addressed store, hash-verified

341
342// VisitQueryNoWith visits the node
343func (v *ASTBuilder) VisitQueryNoWith(ctx *antlrgen.QueryNoWithContext) interface{} {
344 v.Logger.Debugf("VisitQueryNoWith: %s", ctx.GetText())
345
346 location := v.getLocation(ctx)
347 level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx)
348
349 // handle queryTerm
350 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
351 term := v.Visit(ctx.QueryTerm())
352
353 // handle ORDER BY
354 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
355 v.SQL2AqlCtx.exprOrigin = ExprOriginOthers
356 var orderBy = v.getOrderBy(ctx)
357
358 limit := 0
359 limitNode := ctx.GetLimit()
360 if limitParsed, err := strconv.Atoi(v.GetTextIfPresent(limitNode)); limitNode != nil && err != nil {
361 limitLoc := v.getLocation(limitNode)
362 v.Logger.Panicf("failed to parse limit %s at (line:%d, col:%d)", limitNode.GetText(), limitLoc.Line, limitLoc.CharPosition)
363 } else {
364 limit = limitParsed
365 }
366
367 var query *tree.Query
368 if qSpec, ok := term.(*tree.QuerySpecification); ok {
369 qSpecNew := tree.NewQuerySpecification(v.getLocation(ctx),
370 qSpec.Select, qSpec.From, qSpec.Where, qSpec.GroupBy, qSpec.Having, orderBy, v.GetTextIfPresent(ctx.GetLimit()))
371 qSpecNew.SetValue(fmt.Sprintf("QuerySpecification: (%s)", v.getText(ctx.QueryTerm())))
372
373 v.SQL2AqlCtx.MapLimit[v.SQL2AqlCtx.mapKey] = limit
374 query = tree.NewQuery(v.getLocation(ctx),
375 nil,
376 qSpecNew,
377 nil,
378 "")
379 } else if qBody, ok := term.(*tree.QueryBody); ok {
380 query = tree.NewQuery(v.getLocation(ctx),
381 nil,
382 qBody,
383 orderBy,
384 v.GetTextIfPresent(ctx.GetLimit()))
385 if ctx.GetLimit() != nil {
386 if levelQuery == 0 {
387 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
388 v.SQL2AqlCtx.MapLimit[v.SQL2AqlCtx.mapKey] = limit
389 } else {
390 panic(fmt.Errorf("limit on query level %d > 0 not supported at (line:%d, col:%d)",
391 levelQuery, location.Line, location.CharPosition))
392 }
393 }
394
395 } else {
396 panic(fmt.Errorf("invalid query term: %v at (line:%d, col:%d)", term, location.Line, location.CharPosition))
397 }
398 query.SetValue(fmt.Sprintf("Query: (%s)", v.getText(ctx.BaseParserRuleContext)))
399
400 v.setCtxLevels(v.SQL2AqlCtx, level-1, levelWith, levelQuery)

Callers

nothing calls this directly

Calls 15

getLocationMethod · 0.95
getCtxLevelsMethod · 0.95
setCtxLevelsMethod · 0.95
VisitMethod · 0.95
getOrderByMethod · 0.95
GetTextIfPresentMethod · 0.95
getTextMethod · 0.95
NewQuerySpecificationFunction · 0.92
NewQueryFunction · 0.92
DebugfMethod · 0.65
GetLimitMethod · 0.65
PanicfMethod · 0.65

Tested by

no test coverage detected