Skip to content

Commit

Permalink
Fix bug when pass close status as an integar string (#5935)
Browse files Browse the repository at this point in the history
* Handle close status equals to integar string case
  • Loading branch information
neil-xie authored Apr 23, 2024
1 parent dce7e4b commit fb26a4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,13 @@ func parseCloseStatus(original *sqlparser.SQLVal) (*sqlparser.SQLVal, error) {
statusStr := string(original.Val)

// first check if already in int64 format
if _, err := strconv.ParseInt(statusStr, 10, 64); err == nil {
return original, nil
if status, err := strconv.ParseInt(statusStr, 10, 64); err == nil {
// Instead of returning the original value, return a new SQLVal that holds the integer value
// Or it will fail the case CloseStatus = '1'
return &sqlparser.SQLVal{
Type: sqlparser.IntVal,
Val: []byte(strconv.FormatInt(status, 10)),
}, nil
}

// try to parse close status string
Expand Down
11 changes: 9 additions & 2 deletions common/pinot/pinotQueryValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,22 @@ func TestValidateQuery(t *testing.T) {
query: "CustomKeywordField < 0",
validated: "(JSON_MATCH(Attr, '\"$.CustomKeywordField\"<''0''') or JSON_MATCH(Attr, '\"$.CustomKeywordField[*]\"<''0'''))",
},
// TODO
"Case18: custom int order by. Will have errors at run time. Doesn't support for now": {
query: "CustomIntField = 0 order by CustomIntField desc",
validated: "JSON_MATCH(Attr, '\"$.CustomIntField\"=''0''') order by CustomIntField desc",
},
"case 19: close status parse": {
"case19-1: close status parse string": {
query: "CloseStatus = 'CONTINUED_AS_NEW'",
validated: "CloseStatus = 4",
},
"case19-2: close status parse number": {
query: "CloseStatus = '1'",
validated: "CloseStatus = 1",
},
"case19-3: close status parse normal case": {
query: "CloseStatus = 1",
validated: "CloseStatus = 1",
},
}

for name, test := range tests {
Expand Down

0 comments on commit fb26a4c

Please sign in to comment.