go.temporal.io/server@v1.23.0/common/persistence/visibility/store/elasticsearch/converter.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Copyright (c) 2017 Xargin
     8  //
     9  // Permission is hereby granted, free of charge, to any person obtaining a copy
    10  // of this software and associated documentation files (the "Software"), to deal
    11  // in the Software without restriction, including without limitation the rights
    12  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    13  // copies of the Software, and to permit persons to whom the Software is
    14  // furnished to do so, subject to the following conditions:
    15  //
    16  // The above copyright notice and this permission notice shall be included in
    17  // all copies or substantial portions of the Software.
    18  //
    19  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    20  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    21  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    22  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    23  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    24  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    25  // THE SOFTWARE.
    26  
    27  package elasticsearch
    28  
    29  import (
    30  	"github.com/temporalio/sqlparser"
    31  
    32  	"go.temporal.io/server/common/persistence/visibility/store/query"
    33  )
    34  
    35  var allowedComparisonOperators = map[string]struct{}{
    36  	sqlparser.EqualStr:         {},
    37  	sqlparser.NotEqualStr:      {},
    38  	sqlparser.GreaterThanStr:   {},
    39  	sqlparser.GreaterEqualStr:  {},
    40  	sqlparser.LessThanStr:      {},
    41  	sqlparser.LessEqualStr:     {},
    42  	sqlparser.LikeStr:          {},
    43  	sqlparser.NotLikeStr:       {},
    44  	sqlparser.InStr:            {},
    45  	sqlparser.NotInStr:         {},
    46  	sqlparser.StartsWithStr:    {},
    47  	sqlparser.NotStartsWithStr: {},
    48  }
    49  
    50  func newQueryConverter(
    51  	fnInterceptor query.FieldNameInterceptor,
    52  	fvInterceptor query.FieldValuesInterceptor,
    53  ) *query.Converter {
    54  	if fnInterceptor == nil {
    55  		fnInterceptor = &query.NopFieldNameInterceptor{}
    56  	}
    57  
    58  	if fvInterceptor == nil {
    59  		fvInterceptor = &query.NopFieldValuesInterceptor{}
    60  	}
    61  
    62  	rangeCond := query.NewRangeCondConverter(fnInterceptor, fvInterceptor, true)
    63  	comparisonExpr := query.NewComparisonExprConverter(fnInterceptor, fvInterceptor, allowedComparisonOperators)
    64  	is := query.NewIsConverter(fnInterceptor)
    65  
    66  	whereConverter := &query.WhereConverter{
    67  		RangeCond:      rangeCond,
    68  		ComparisonExpr: comparisonExpr,
    69  		Is:             is,
    70  	}
    71  	whereConverter.And = query.NewAndConverter(whereConverter)
    72  	whereConverter.Or = query.NewOrConverter(whereConverter)
    73  
    74  	return query.NewConverter(fnInterceptor, whereConverter)
    75  }