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

Fix Pinot query validator bug when user pass in not equal query with value missing #5662

Merged
merged 2 commits into from
Feb 14, 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
9 changes: 4 additions & 5 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin
}
colNameStr := colName.Name.String()

if comparisonExpr.Operator != sqlparser.EqualStr {
if comparisonExpr.Operator != sqlparser.EqualStr && comparisonExpr.Operator != sqlparser.NotEqualStr {
if _, ok := timeSystemKeys[colNameStr]; ok {
sqlVal, ok := comparisonExpr.Right.(*sqlparser.SQLVal)
if !ok {
Expand Down Expand Up @@ -280,10 +280,9 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin
} else {
newColVal = "-1" // -1 is the default value for all Closed workflows related fields
}
comparisonExpr.Right = &sqlparser.ColName{
Metadata: colName.Metadata,
Name: sqlparser.NewColIdent(newColVal),
Qualifier: colName.Qualifier,
comparisonExpr.Right = &sqlparser.SQLVal{
Type: sqlparser.IntVal, // or sqlparser.StrVal if you need to assign a string
Val: []byte(newColVal),
}
} else {
if _, ok := timeSystemKeys[colNameStr]; ok {
Expand Down
12 changes: 10 additions & 2 deletions common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ func TestValidateQuery(t *testing.T) {
query: "Invalid SQL",
err: "Invalid query.",
},
"Case8: query with missing val": {
"Case8-1: query with missing val": {
query: "CloseTime = missing",
validated: "CloseTime = `-1`",
validated: "CloseTime = -1",
},
"Case8-2: query with not missing case": {
query: "CloseTime != missing",
validated: "CloseTime != -1",
},
"Case9: invalid where expression": {
query: "InvalidWhereExpr",
Expand Down Expand Up @@ -185,6 +189,10 @@ func TestValidateQuery(t *testing.T) {
query: "StartTime between '2024-02-07T15:32:30Z' and '2024-02-07T15:33:30Z'",
validated: "StartTime between 1707319950000 and 1707320010000",
},
"Case15-16: combined time and missing case": {
query: "CloseTime != missing and StartTime >= 1707662555754408145",
validated: "CloseTime != -1 and StartTime >= 1707662555754",
},
"Case16-1: custom int attribute greater than or equal to": {
query: "CustomIntField >= 0",
validated: "(JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 0)",
Expand Down