291
}
292
293
>
func (a *andConverter) Convert(expr sqlparser.Expr) (elastic.Query, error) {
converter_legacy.go
294
>
andExpr, ok := expr.(*sqlparser.AndExpr)
295
>
if !ok {
296
return nil, NewConverterError("%v is not an 'and' expression", sqlparser.String(expr))
297
}
298
300
>
rightExpr := andExpr.Right
301
>
leftQuery, err := a.where.Convert(leftExpr)
302
>
if err != nil {
303
return nil, err
304
}
306
>
if err != nil {
307
return nil, err
308
}
309
310
// If left or right is a BoolQuery built from AndExpr then reuse it w/o creating new BoolQuery.
312
>
_, isLEAnd := leftExpr.(*sqlparser.AndExpr)
313
>
if isLQBool && isLEAnd {
315
>
}
316
318
>
_, isREAnd := rightExpr.(*sqlparser.AndExpr)
319
>
if isRQBool && isREAnd {
320
return rqBool.Filter(leftQuery), nil
321
}
322
324
}
325
326
>
func (o *orConverter) Convert(expr sqlparser.Expr) (elastic.Query, error) {
converter_legacy.go
327
>
orExpr, ok := expr.(*sqlparser.OrExpr)
328
>
if !ok {
329
return nil, NewConverterError("%v is not an 'or' expression", sqlparser.String(expr))
330
}
331
333
>
rightExpr := orExpr.Right
334
>
leftQuery, err := o.where.Convert(leftExpr)
335
>
if err != nil {
336
return nil, err
337
}
339
>
if err != nil {
340
return nil, err
341
}
342
343
// If left or right is a BoolQuery built from OrExpr then reuse it w/o creating new BoolQuery.
345
>
_, isLEOr := leftExpr.(*sqlparser.OrExpr)
346
>
if isLQBool && isLEOr {
347
return lqBool.Should(rightQuery), nil
348
}
349
351
>
_, isREOr := rightExpr.(*sqlparser.OrExpr)
352
>
if isRQBool && isREOr {
353
return rqBool.Should(leftQuery), nil
354
}
355
357
}
358
359
>
func (r *rangeCondConverter) Convert(expr sqlparser.Expr) (elastic.Query, error) {
converter_legacy.go
360
>
rangeCond, ok := expr.(*sqlparser.RangeCond)
361
>
if !ok {
362
return nil, NewConverterError("%v is not a range condition", sqlparser.String(expr))
363
}
364
365
>
alias, colName, err := convertColName(r.fnInterceptor, rangeCond.Left, FieldNameFilter)
converter_legacy.go
366
>
if err != nil {
367
return nil, wrapConverterError("unable to convert left part of 'between' expression", err)
368
}
369
370
>
fromValue, err := sqlquery.ParseValue(sqlparser.String(rangeCond.From))
converter_legacy.go
371
>
if err != nil {
372
return nil, err
373
}
375
>
if err != nil {
376
return nil, err
377
}
378
379
>
values, err := r.fvInterceptor.Values(alias, colName, fromValue, toValue)
converter_legacy.go
380
>
if err != nil {
381
return nil, wrapConverterError("unable to convert values of 'between' expression", err)
382
}
384
>
toValue = values[1]
385
>
386
>
var query elastic.Query
387
>
switch rangeCond.Operator {
388
>
case "between":
389
>
query = elastic.NewRangeQuery(colName).Gte(fromValue).Lte(toValue)
391
>
if !r.notBetweenSupported {
392
return nil, NewConverterError("%s: 'not between' expression", NotSupportedErrMessage)
393
}
394
>
query = elastic.NewBoolQuery().MustNot(elastic.NewRangeQuery(colName).Gte(fromValue).Lte(toValue))
converter_legacy.go
395
default:
396
return nil, NewConverterError("%s: range condition operator must be 'between' or 'not between'", InvalidExpressionErrMessage)
397
}
399
}
400
401
>
func (i *isConverter) Convert(expr sqlparser.Expr) (elastic.Query, error) {
converter_legacy.go
402
>
isExpr, ok := expr.(*sqlparser.IsExpr)
403
>
if !ok {
404
return nil, NewConverterError("%v is not an 'is' expression", sqlparser.String(expr))
405
}
406
407
>
_, colName, err := convertColName(i.fnInterceptor, isExpr.Expr, FieldNameFilter)
converter_legacy.go
408
>
if err != nil {
409
return nil, wrapConverterError("unable to convert left part of 'is' expression", err)
410
}
411
413
>
switch isExpr.Operator {
414
>
case "is null":
415
>
query = elastic.NewBoolQuery().MustNot(elastic.NewExistsQuery(colName))
417
>
query = elastic.NewExistsQuery(colName)
418
default:
419
return nil, NewConverterError("%s: 'is' operator can be used with 'null' and 'not null' only", InvalidExpressionErrMessage)
420
}
421
423
}
424
425
>
func (c *comparisonExprConverter) Convert(expr sqlparser.Expr) (elastic.Query, error) {
converter_legacy.go
426
>
comparisonExpr, ok := expr.(*sqlparser.ComparisonExpr)
427
>
if !ok {
428
return nil, NewConverterError("%v is not a comparison expression", sqlparser.String(expr))
429
}
430
431
>
alias, colName, err := convertColName(c.fnInterceptor, comparisonExpr.Left, FieldNameFilter)
converter_legacy.go
432
>
if err != nil {
433
return nil, wrapConverterError(
434
fmt.Sprintf("unable to convert left side of %q", sqlparser.String(expr)),