diff --git a/common/persistence/pinot/pinot_visibility_store.go b/common/persistence/pinot/pinot_visibility_store.go index 28db7707d38..297835038f1 100644 --- a/common/persistence/pinot/pinot_visibility_store.go +++ b/common/persistence/pinot/pinot_visibility_store.go @@ -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), } } diff --git a/common/pinot/pinotQueryValidator.go b/common/pinot/pinotQueryValidator.go index 32704b2950a..38101f8cd83 100644 --- a/common/pinot/pinotQueryValidator.go +++ b/common/pinot/pinotQueryValidator.go @@ -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{ @@ -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, } @@ -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 } @@ -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") } diff --git a/common/pinot/pinotQueryValidator_test.go b/common/pinot/pinotQueryValidator_test.go index 6ceea71132d..c9ea69ee004 100644 --- a/common/pinot/pinotQueryValidator_test.go +++ b/common/pinot/pinotQueryValidator_test.go @@ -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()) @@ -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) {