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

Pinot handle customer keyword type empty val #6302

Merged
merged 14 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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'''))",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit consider using backticks to make things more readable when fighting quotes in quites

ie

`(JSON_MATCH(Attr, '"$.CustomKeywordField"!=''0''') and JSON_MATCH(Attr, '"$.CustomKeywordField[*]"!=''0'''))`

I guess, or similar, I'm having slight trouble following this because I've not spent enough time close to the Pinot component

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in the next PR. I enabled auto-merge for this one

},
"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
Loading