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

Update Pinot query validator to support "like" in queries #6188

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin
}
colNameStr := colName.Name.String()

if comparisonExpr.Operator == sqlparser.LikeStr {
colVal, ok := comparisonExpr.Right.(*sqlparser.SQLVal)
if !ok {
return "", fmt.Errorf("right comparison is invalid: %v", comparisonExpr.Right)
}
colValStr := string(colVal.Val)
return processCustomString(comparisonExpr, colNameStr, colValStr), nil
sankari165 marked this conversation as resolved.
Show resolved Hide resolved
}

if comparisonExpr.Operator != sqlparser.EqualStr && comparisonExpr.Operator != sqlparser.NotEqualStr {
if _, ok := timeSystemKeys[colNameStr]; ok {
sqlVal, ok := comparisonExpr.Right.(*sqlparser.SQLVal)
Expand Down
13 changes: 12 additions & 1 deletion common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ func TestValidateQuery(t *testing.T) {
query: "",
validated: "",
},
"Case2: simple query": {
"Case2-1: simple query": {
query: "WorkflowID = 'wid'",
validated: "WorkflowID = 'wid'",
},
"Case2-2: simple query with partial match": {
query: "WorkflowID like 'wid'",
validated: "(JSON_MATCH(Attr, '\"$.WorkflowID\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.WorkflowID', 'string'), 'wid*'))",
},
"Case2-3: invalid simple query with partial match": {
query: "WorkflowID like wid",
err: "right comparison is invalid: &{<nil> wid { }}"},
"Case3-1: query with custom field": {
query: "CustomStringField = 'custom'",
validated: "(JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom*'))",
Expand Down Expand Up @@ -78,6 +85,10 @@ func TestValidateQuery(t *testing.T) {
query: "WorkflowID = 'wid' and (CustomStringField = 'custom and custom2 or custom3 order by' or CustomIntField between 1 and 10)",
validated: "WorkflowID = 'wid' and ((JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom and custom2 or custom3 order by*')) or (JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 1 AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) <= 10))",
},
"Case6-5: complex query with partial match": {
query: "RunID like '123' or WorkflowID like '123'",
validated: "((JSON_MATCH(Attr, '\"$.RunID\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.RunID', 'string'), '123*')) or (JSON_MATCH(Attr, '\"$.WorkflowID\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.WorkflowID', 'string'), '123*')))",
},
"Case7: invalid sql query": {
query: "Invalid SQL",
err: "Invalid query: syntax error at position 38 near 'sql'",
Expand Down
Loading