Skip to content

Commit

Permalink
handle not equal in custom keyword field (#6185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenxia authored Jul 23, 2024
1 parent ebda4b1 commit 736d66b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ 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 fmt.Sprintf("(JSON_MATCH(Attr, '\"$.%s\"%s''%s''') or JSON_MATCH(Attr, '\"$.%s[*]\"%s''%s'''))",
colNameStr, operator, colValStr, colNameStr, operator, colValStr)
}
Expand Down
4 changes: 4 additions & 0 deletions common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func TestValidateQuery(t *testing.T) {
query: "CustomKeywordField = missing",
err: "invalid comparison expression, right",
},
"Case8-4: query with custom keyword field not equal": {
query: "CustomKeywordField != 0",
validated: "JSON_MATCH(Attr, '\"$.CustomKeywordField\"!=''0''') and JSON_MATCH(Attr, '\"$.CustomKeywordField[*]\"!=''0''')",
},
"Case9: invalid where expression": {
query: "InvalidWhereExpr",
err: "invalid where clause",
Expand Down

0 comments on commit 736d66b

Please sign in to comment.