Skip to content

Commit

Permalink
Pass dynamic map into pinot query validator (#6175)
Browse files Browse the repository at this point in the history
* Pass dynamic map into pinot query validator

* fmt
  • Loading branch information
bowenxia authored Jul 18, 2024
1 parent 8dde72e commit c9bbbe5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/persistence/pinot/pinot_visibility_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewPinotVisibilityStore(
producer: producer,
logger: logger.WithTags(tag.ComponentPinotVisibilityManager),
config: config,
pinotQueryValidator: pnt.NewPinotQueryValidator(config.ValidSearchAttributes()),
pinotQueryValidator: pnt.NewPinotQueryValidator(config.ValidSearchAttributes),
}
}

Expand Down
9 changes: 5 additions & 4 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import (

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/definition"
"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/types"
)

// VisibilityQueryValidator for sql query validation
type VisibilityQueryValidator struct {
validSearchAttributes map[string]interface{}
validSearchAttributes dynamicconfig.MapPropertyFn
}

var timeSystemKeys = map[string]bool{
Expand All @@ -50,7 +51,7 @@ var timeSystemKeys = map[string]bool{
}

// NewPinotQueryValidator create VisibilityQueryValidator
func NewPinotQueryValidator(validSearchAttributes map[string]interface{}) *VisibilityQueryValidator {
func NewPinotQueryValidator(validSearchAttributes dynamicconfig.MapPropertyFn) *VisibilityQueryValidator {
return &VisibilityQueryValidator{
validSearchAttributes: validSearchAttributes,
}
Expand Down Expand Up @@ -226,7 +227,7 @@ func (qv *VisibilityQueryValidator) validateComparisonExpr(expr sqlparser.Expr)

// IsValidSearchAttributes return true if key is registered
func (qv *VisibilityQueryValidator) IsValidSearchAttributes(key string) bool {
validAttr := qv.validSearchAttributes
validAttr := qv.validSearchAttributes()
_, isValidKey := validAttr[key]
return isValidKey
}
Expand Down Expand Up @@ -354,7 +355,7 @@ func (qv *VisibilityQueryValidator) processCustomKey(expr sqlparser.Expr) (strin
colNameStr := colName.Name.String()

// check type: if is IndexedValueTypeString, change to like statement for partial match
valType, ok := qv.validSearchAttributes[colNameStr]
valType, ok := qv.validSearchAttributes()[colNameStr]
if !ok {
return "", fmt.Errorf("invalid search attribute")
}
Expand Down
4 changes: 2 additions & 2 deletions common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestValidateQuery(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
validSearchAttr := dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys())
qv := NewPinotQueryValidator(validSearchAttr())
qv := NewPinotQueryValidator(validSearchAttr)
validated, err := qv.ValidateQuery(test.query)
if err != nil {
assert.Equal(t, test.err, err.Error())
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestProcessInClause_FailedInputExprCases(t *testing.T) {

// Create a new VisibilityQueryValidator
validSearchAttr := dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys())
qv := NewPinotQueryValidator(validSearchAttr())
qv := NewPinotQueryValidator(validSearchAttr)

for name, test := range tests {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit c9bbbe5

Please sign in to comment.