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

Method VisitQuery

query/sql/sql_parser.go:210–251  ·  view source on GitHub ↗

********************** Visit SQL grammar starts ******************** ********************** query expressions ******************** VisitQuery visits the node

(ctx *antlrgen.QueryContext)

Source from the content-addressed store, hash-verified

208
209// VisitQuery visits the node
210func (v *ASTBuilder) VisitQuery(ctx *antlrgen.QueryContext) interface{} {
211 v.Logger.Debugf("VisitQuery: %s", ctx.GetText())
212
213 location := v.getLocation(ctx)
214 level, levelWith, levelQuery := v.getCtxLevels(v.SQL2AqlCtx)
215 if levelQuery >= maxLevelQuery {
216 panic(fmt.Errorf("only support %v level subquery at (line:%d, col:%d)",
217 maxLevelQuery, location.Line, location.CharPosition))
218 }
219
220 // handle with
221 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
222 classWith := reflect.TypeOf((*tree.With)(nil))
223 with := v.visitIfPresent(ctx.With(), classWith).(*tree.With)
224
225 // handle queryNoWith
226 v.setCtxLevels(v.SQL2AqlCtx, level, levelWith, levelQuery)
227 body, _ := v.Visit(ctx.QueryNoWith()).(*tree.Query)
228 if body == nil {
229 panic(fmt.Errorf("missing queryNoWith body at (line:%d, col:%d)", location.Line, location.CharPosition))
230 }
231
232 if levelQuery == 0 {
233 if valid, err := v.isValidWithOrSubQuery(v.SQL2AqlCtx); !valid || err != nil {
234 panic(fmt.Errorf("line:%d, col:%d isValidWithOrSubQuery: %v, reason :%v",
235 location.Line, location.CharPosition, valid, err))
236 }
237 }
238
239 query := tree.NewQuery(
240 v.getLocation(ctx),
241 with,
242 body.QueryBody,
243 body.OrderBy,
244 body.Limit,
245 )
246 query.SetValue(fmt.Sprintf("Query: (%s)", v.getText(ctx.BaseParserRuleContext)))
247
248 // reset SQL2AqlContext
249 v.setCtxLevels(v.SQL2AqlCtx, level-1, levelWith, levelQuery)
250 return query
251}
252
253// VisitWith visits the node
254func (v *ASTBuilder) VisitWith(ctx *antlrgen.WithContext) interface{} {

Callers 3

VisitNamedQueryMethod · 0.95
VisitSubqueryRelationMethod · 0.95
ParseFunction · 0.95

Calls 13

getLocationMethod · 0.95
getCtxLevelsMethod · 0.95
setCtxLevelsMethod · 0.95
visitIfPresentMethod · 0.95
VisitMethod · 0.95
isValidWithOrSubQueryMethod · 0.95
getTextMethod · 0.95
NewQueryFunction · 0.92
DebugfMethod · 0.65
ErrorfMethod · 0.65
WithMethod · 0.65
SetValueMethod · 0.65

Tested by

no test coverage detected