Skip to content

Commit

Permalink
Pinot handle customer keyword type empty val (#6302)
Browse files Browse the repository at this point in the history
* add query to handle empty keyword val
  • Loading branch information
bowenxia authored Sep 24, 2024
1 parent a6e62ee commit 50e3558
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 12 additions & 4 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,20 @@ func processEqual(colNameStr string, colValStr string) string {
func processCustomKeyword(operator string, colNameStr string, colValStr string) string {
// edge case
if operator == "!=" {
return fmt.Sprintf("JSON_MATCH(Attr, '\"$.%s\"%s''%s''') and JSON_MATCH(Attr, '\"$.%s[*]\"%s''%s''')",
colNameStr, operator, colValStr, colNameStr, operator, colValStr)
return createKeywordQuery(operator, colNameStr, colValStr, "and", "NOT ")
}

return fmt.Sprintf("(JSON_MATCH(Attr, '\"$.%s\"%s''%s''') or JSON_MATCH(Attr, '\"$.%s[*]\"%s''%s'''))",
colNameStr, operator, colValStr, colNameStr, operator, colValStr)
return createKeywordQuery(operator, colNameStr, colValStr, "or", "")
}

func createKeywordQuery(operator string, colNameStr string, colValStr string, connector string, notEqual string) string {
if colValStr == "" {
// partial match for an empty string (still it will only match empty string)
// so it equals to exact match for an empty string
return createCustomStringQuery(colNameStr, colValStr, notEqual)
}
return fmt.Sprintf("(JSON_MATCH(Attr, '\"$.%s\"%s''%s''') %s JSON_MATCH(Attr, '\"$.%s[*]\"%s''%s'''))",
colNameStr, operator, colValStr, connector, colNameStr, operator, colValStr)
}

func processCustomString(operator string, colNameStr string, colValStr string) string {
Expand Down
10 changes: 9 additions & 1 deletion common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestValidateQuery(t *testing.T) {
},
"Case8-4: query with custom keyword field not equal": {
query: "CustomKeywordField != 0",
validated: "JSON_MATCH(Attr, '\"$.CustomKeywordField\"!=''0''') and JSON_MATCH(Attr, '\"$.CustomKeywordField[*]\"!=''0''')",
validated: "(JSON_MATCH(Attr, '\"$.CustomKeywordField\"!=''0''') and JSON_MATCH(Attr, '\"$.CustomKeywordField[*]\"!=''0'''))",
},
"Case9: invalid where expression": {
query: "InvalidWhereExpr",
Expand Down Expand Up @@ -359,6 +359,14 @@ func TestValidateQuery(t *testing.T) {
query: "CustomStringField = 'abc' OR CustomStringField = 'def'",
validated: "(JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND JSON_MATCH(Attr, 'REGEXP_LIKE(\"$.CustomStringField\", ''.*abc.*'')') or JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND JSON_MATCH(Attr, 'REGEXP_LIKE(\"$.CustomStringField\", ''.*def.*'')'))",
},
"case23-1: custom keyword field is empty case": {
query: "CustomKeywordField = ''",
validated: "JSON_MATCH(Attr, '\"$.CustomKeywordField\" is not null') AND JSON_MATCH(Attr, 'REGEXP_LIKE(\"$.CustomKeywordField\", ''^$'')')",
},
"case23-2: custom keyword field is not empty case": {
query: "CustomKeywordField != ''",
validated: "JSON_MATCH(Attr, '\"$.CustomKeywordField\" is not null') AND NOT JSON_MATCH(Attr, 'REGEXP_LIKE(\"$.CustomKeywordField\", ''^$'')')",
},
}

for name, test := range tests {
Expand Down

0 comments on commit 50e3558

Please sign in to comment.