Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass dynamic map into pinot query validator #6175

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +25,7 @@ package pinot
import (
"errors"
"fmt"
"github.com/uber/cadence/common/dynamicconfig"
"strconv"
"strings"
"time"
Expand All @@ -39,7 +40,7 @@ import (

// 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
Loading