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

Method VisitNamedQuery

query/sql/sql_parser.go:295–340  ·  view source on GitHub ↗

VisitNamedQuery visits the node

(ctx *antlrgen.NamedQueryContext)

Source from the content-addressed store, hash-verified

293
294// VisitNamedQuery visits the node
295func (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
343func (v *ASTBuilder) VisitQueryNoWith(ctx *antlrgen.QueryNoWithContext) interface{} {

Callers 1

VisitWithMethod · 0.95

Calls 15

getLocationMethod · 0.95
getCtxLevelsMethod · 0.95
getTextMethod · 0.95
addQIdentifierMethod · 0.95
VisitMethod · 0.95
setCtxLevelsMethod · 0.95
VisitQueryMethod · 0.95
NewWithQueryFunction · 0.92
DebugfMethod · 0.65
GetNameMethod · 0.65
ErrorfMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected