********************** Visit SQL grammar starts ******************** ********************** query expressions ******************** VisitQuery visits the node
(ctx *antlrgen.QueryContext)
| 208 | |
| 209 | // VisitQuery visits the node |
| 210 | func (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 |
| 254 | func (v *ASTBuilder) VisitWith(ctx *antlrgen.WithContext) interface{} { |
no test coverage detected