Skip to content

Commit

Permalink
Better error message in ES query converter (#4112)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou committed Mar 28, 2023
1 parent 939eefa commit 47424c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -678,7 +678,7 @@ func (s *ESVisibilitySuite) Test_convertQuery_Mapper() {
_, _, err = s.visibilityStore.convertQuery(testNamespace, testNamespaceID, query)
s.Error(err)
s.ErrorAs(err, &invalidArgumentErr)
s.EqualError(err, "invalid query: unable to convert filter expression: unable to convert left part of comparison expression: invalid search attribute: AliasForUnknownField")
s.EqualError(err, "invalid query: unable to convert filter expression: unable to convert left side of \"AliasForUnknownField = 'pid'\": invalid search attribute: AliasForUnknownField")

query = `order by ExecutionTime`
qry, srt, err = s.visibilityStore.convertQuery(testNamespace, testNamespaceID, query)
Expand Down
16 changes: 13 additions & 3 deletions common/persistence/visibility/store/query/converter.go
Expand Up @@ -420,12 +420,18 @@ func (c *comparisonExprConverter) Convert(expr sqlparser.Expr) (elastic.Query, e

colName, err := convertColName(c.fnInterceptor, comparisonExpr.Left, FieldNameFilter)
if err != nil {
return nil, wrapConverterError("unable to convert left part of comparison expression", err)
return nil, wrapConverterError(
fmt.Sprintf("unable to convert left side of %q", sqlparser.String(expr)),
err,
)
}

colValue, err := convertComparisonExprValue(comparisonExpr.Right)
if err != nil {
return nil, wrapConverterError("unable to convert right part of comparison expression", err)
return nil, wrapConverterError(
fmt.Sprintf("unable to convert right side of %q", sqlparser.String(expr)),
err,
)
}

if comparisonExpr.Operator == "like" || comparisonExpr.Operator == "not like" {
Expand Down Expand Up @@ -502,7 +508,11 @@ func convertComparisonExprValue(expr sqlparser.Expr) (interface{}, error) {
case *sqlparser.FuncExpr:
return nil, NewConverterError("%s: nested func", NotSupportedErrMessage)
case *sqlparser.ColName:
return nil, NewConverterError("%s: column name on the right side of comparison expression", NotSupportedErrMessage)
return nil, NewConverterError(
"%s: column name on the right side of comparison expression (did you forget to quote %q?)",
NotSupportedErrMessage,
sqlparser.String(expr),
)
default:
return nil, NewConverterError("%s: unexpected value type %T", InvalidExpressionErrMessage, expr)
}
Expand Down

0 comments on commit 47424c0

Please sign in to comment.