Skip to content

Commit

Permalink
Fix Pinot query validator bug when user pass in not equal query with …
Browse files Browse the repository at this point in the history
…value missing (#5662)
  • Loading branch information
neil-xie authored Feb 14, 2024
1 parent 346def2 commit 30ffa2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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

0 comments on commit 30ffa2d

Please sign in to comment.