Skip to content

Commit

Permalink
fix error wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-xie committed Feb 15, 2024
1 parent bf87dbd commit 353c5f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions common/persistence/pinot/pinotVisibilityStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func (v *pinotVisibilityStore) getListWorkflowExecutionsByQueryQuery(tableName s

token, err := pnt.GetNextPageToken(request.NextPageToken)
if err != nil {
return "", err
return "", fmt.Errorf("next page token: %w", err)
}

query := NewPinotQuery(tableName)
Expand All @@ -810,8 +810,7 @@ func (v *pinotVisibilityStore) getListWorkflowExecutionsByQueryQuery(tableName s
comparExpr, orderBy := parseOrderBy(requestQuery)
comparExpr, err = v.pinotQueryValidator.ValidateQuery(comparExpr)
if err != nil {
v.logger.Error(fmt.Sprintf("pinot query validator error: %s, query: %s", err, request.Query))
return "", err
return "", fmt.Errorf(fmt.Sprintf("pinot query validator error: %w, query: %s", err, request.Query))
}

comparExpr = filterPrefix(comparExpr)
Expand Down Expand Up @@ -942,7 +941,7 @@ func getListWorkflowExecutionsQuery(tableName string, request *p.InternalListWor

token, err := pnt.GetNextPageToken(request.NextPageToken)
if err != nil {
return "", err
return "", fmt.Errorf("next page token: %w", err)
}

from := token.From
Expand Down Expand Up @@ -996,7 +995,7 @@ func getListWorkflowExecutionsByTypeQuery(tableName string, request *p.InternalL

token, err := pnt.GetNextPageToken(request.NextPageToken)
if err != nil {
return "", err
return "", fmt.Errorf("next page token: %w", err)
}

from := token.From
Expand Down Expand Up @@ -1032,7 +1031,7 @@ func getListWorkflowExecutionsByWorkflowIDQuery(tableName string, request *p.Int

token, err := pnt.GetNextPageToken(request.NextPageToken)
if err != nil {
return "", err
return "", fmt.Errorf("next page token: %w", err)
}

from := token.From
Expand Down Expand Up @@ -1075,7 +1074,7 @@ func getListWorkflowExecutionsByStatusQuery(tableName string, request *p.Interna

token, err := pnt.GetNextPageToken(request.NextPageToken)
if err != nil {
return "", err
return "", fmt.Errorf("next page token: %w", err)
}

from := token.From
Expand Down
18 changes: 9 additions & 9 deletions common/pinot/pinotQueryValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func (qv *VisibilityQueryValidator) validateRangeExpr(expr sqlparser.Expr) (stri
if lowerBound, ok := rangeCond.From.(*sqlparser.SQLVal); ok {
trimmed, err := trimTimeFieldValueFromNanoToMilliSeconds(lowerBound)
if err != nil {
return "", err
return "", fmt.Errorf("trim time feild %s got error: %w", colNameStr, err)
}
rangeCond.From = trimmed
}
if upperBound, ok := rangeCond.To.(*sqlparser.SQLVal); ok {
trimmed, err := trimTimeFieldValueFromNanoToMilliSeconds(upperBound)
if err != nil {
return "", err
return "", fmt.Errorf("trim time feild %s got error: %w", colNameStr, err)
}
rangeCond.To = trimmed
}
Expand Down Expand Up @@ -237,19 +237,19 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin

colName, ok := comparisonExpr.Left.(*sqlparser.ColName)
if !ok {
return "", errors.New("invalid comparison expression, left")
return "", fmt.Errorf("left comparison is invalid: %v", comparisonExpr.Left)
}
colNameStr := colName.Name.String()

if comparisonExpr.Operator != sqlparser.EqualStr && comparisonExpr.Operator != sqlparser.NotEqualStr {
if _, ok := timeSystemKeys[colNameStr]; ok {
sqlVal, ok := comparisonExpr.Right.(*sqlparser.SQLVal)
if !ok {
return "", fmt.Errorf("error: Failed to convert val")
return "", fmt.Errorf("right comparison is invalid: %v", comparisonExpr.Right)
}
trimmed, err := trimTimeFieldValueFromNanoToMilliSeconds(sqlVal)
if err != nil {
return "", err
return "", fmt.Errorf("trim time feild %s got error: %w", colNameStr, err)
}
comparisonExpr.Right = trimmed
}
Expand All @@ -265,13 +265,13 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin
if !ok { // this means, the value is a string, and not surrounded by single qoute, which means, val = missing
colVal, ok := comparisonExpr.Right.(*sqlparser.ColName)
if !ok {
return "", fmt.Errorf("error: Failed to convert val")
return "", fmt.Errorf("right comparison is invalid: %v", comparisonExpr.Right)
}
colValStr := colVal.Name.String()

// double check if val is not missing
if colValStr != "missing" {
return "", fmt.Errorf("error: failed to convert val")
return "", fmt.Errorf("right comparison is invalid string value: %s", colValStr)
}

var newColVal string
Expand All @@ -288,11 +288,11 @@ func (qv *VisibilityQueryValidator) processSystemKey(expr sqlparser.Expr) (strin
if _, ok := timeSystemKeys[colNameStr]; ok {
sqlVal, ok := comparisonExpr.Right.(*sqlparser.SQLVal)
if !ok {
return "", fmt.Errorf("error: Failed to convert val %s", colNameStr)
return "", fmt.Errorf("right comparison is invalid/missing. key %s, right expr %v", colNameStr, comparisonExpr.Right)
}
trimmed, err := trimTimeFieldValueFromNanoToMilliSeconds(sqlVal)
if err != nil {
return "", err
return "", fmt.Errorf("trim time feild %s got error: %w", colNameStr, err)
}
comparisonExpr.Right = trimmed
}
Expand Down

0 comments on commit 353c5f4

Please sign in to comment.