Skip to content

Commit

Permalink
Improve filestore query parser for treating more values as valid clos…
Browse files Browse the repository at this point in the history
…e status
  • Loading branch information
yycptt committed Apr 1, 2020
1 parent 0976e69 commit 1082549
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
17 changes: 10 additions & 7 deletions common/archiver/filestore/queryParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr,
case CloseStatus:
val, err := extractStringValue(valStr)
if err != nil {
return err
// if failed to extract string value, it means user input close status as a number
val = valStr
}
if op != "=" {
return fmt.Errorf("only operation = is support for %s", CloseStatus)
Expand Down Expand Up @@ -241,17 +242,19 @@ func convertToTimestamp(timeStr string) (int64, error) {
}

func convertStatusStr(statusStr string) (shared.WorkflowExecutionCloseStatus, error) {
statusStr = strings.ToLower(statusStr)
statusStr = strings.ToLower(strings.TrimSpace(statusStr))
switch statusStr {
case "completed":
case "completed", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusCompleted)):
return shared.WorkflowExecutionCloseStatusCompleted, nil
case "failed":
case "failed", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusFailed)):
return shared.WorkflowExecutionCloseStatusFailed, nil
case "canceled":
case "canceled", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusCanceled)):
return shared.WorkflowExecutionCloseStatusCanceled, nil
case "continuedasnew":
case "terminated", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusTerminated)):
return shared.WorkflowExecutionCloseStatusTerminated, nil
case "continuedasnew", "continued_as_new", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusContinuedAsNew)):
return shared.WorkflowExecutionCloseStatusContinuedAsNew, nil
case "timedout":
case "timedout", "timed_out", strconv.Itoa(int(shared.WorkflowExecutionCloseStatusTimedOut)):
return shared.WorkflowExecutionCloseStatusTimedOut, nil
default:
return 0, fmt.Errorf("unknown workflow close status: %s", statusStr)
Expand Down
18 changes: 18 additions & 0 deletions common/archiver/filestore/queryParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ func (s *queryParserSuite) TestParseCloseStatus() {
closeStatus: shared.WorkflowExecutionCloseStatusContinuedAsNew.Ptr(),
},
},
{
query: "CloseStatus = 'TIMED_OUT'",
expectErr: false,
parsedQuery: &parsedQuery{
closeStatus: shared.WorkflowExecutionCloseStatusTimedOut.Ptr(),
},
},
{
query: "CloseStatus = 'Failed' and CloseStatus = \"Failed\"",
expectErr: false,
Expand Down Expand Up @@ -191,6 +198,17 @@ func (s *queryParserSuite) TestParseCloseStatus() {
query: "CloseStatus > \"Failed\"",
expectErr: true,
},
{
query: "CloseStatus = 1",
expectErr: false,
parsedQuery: &parsedQuery{
closeStatus: shared.WorkflowExecutionCloseStatusFailed.Ptr(),
},
},
{
query: "CloseStatus = 10",
expectErr: true,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 1082549

Please sign in to comment.