Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support STARTS_WITH in visibility queries #5094

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

rodrigozhou
Copy link
Contributor

What changed?
Parse STARTS_WITH queries to visibility, and build queries to Elasticsearch and SQL.

Why?
Support prefix search in visibility queries.

How did you test it?
Added unit tests, and integration tests.

Potential risks
No.

Is hotfix candidate?
No.

@rodrigozhou rodrigozhou requested a review from alexshtin November 9, 2023 05:34
@rodrigozhou rodrigozhou requested a review from a team as a code owner November 9, 2023 05:34
@rodrigozhou rodrigozhou force-pushed the vis-support-starts-with branch 4 times, most recently from 52d4557 to 5ebdd3c Compare November 9, 2023 22:52
if !ok {
return nil, NewConverterError("right-hand side of '%v' must be a string", comparisonExpr.Operator)
}
query = elastic.NewBoolQuery().MustNot(elastic.NewPrefixQuery(colName, v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to enable index_prefixes for this to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. index_prefixes would make search faster, but not required.

@rodrigozhou rodrigozhou force-pushed the vis-support-starts-with branch 2 times, most recently from c578ab2 to fb28633 Compare November 12, 2023 21:38
tests/advanced_visibility_test.go Show resolved Hide resolved
}
resp, err := s.engine.ListWorkflowExecutions(NewContext(), listRequest)
s.NoError(err)
s.Len(resp.GetExecutions(), 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Please ensure we get the expected record, not just any record

Copy link
Contributor Author

@rodrigozhou rodrigozhou Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are old tests, just moved around, and also soon to be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see new tests that verify this functionality works as expected, are you planning to add them?

@rodrigozhou rodrigozhou force-pushed the vis-support-starts-with branch from fb28633 to d4938fb Compare November 15, 2023 22:25
Comment on lines +331 to +362
{
name: "starts_with expression",
input: "AliasForKeyword01 starts_with 'foo_bar%'",
output: `Keyword01 like 'foo!_bar!%%' escape '!'`,
err: nil,
},
{
name: "not starts_with expression",
input: "AliasForKeyword01 not starts_with 'foo_bar%'",
output: `Keyword01 not like 'foo!_bar!%%' escape '!'`,
err: nil,
},
{
name: "starts_with expression error",
input: "AliasForKeyword01 starts_with 123",
output: "",
err: query.NewConverterError(
"%s: right-hand side of '%s' must be a literal string (got: 123)",
query.InvalidExpressionErrMessage,
sqlparser.StartsWithStr,
),
},
{
name: "not starts_with expression error",
input: "AliasForKeyword01 not starts_with 123",
output: "",
err: query.NewConverterError(
"%s: right-hand side of '%s' must be a literal string (got: 123)",
query.InvalidExpressionErrMessage,
sqlparser.NotStartsWithStr,
),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdeebswihart New tests.

Copy link
Contributor

@tdeebswihart tdeebswihart Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd seen the unit tests. So we don't have useful functional tests for this functionality? The only ones are what I called out earlier which don't bother to check whether the records we expect are the ones returned, and I've seen a test like that hide bugs in the past.

Comment on lines +96 to +97
"value starts_with 'prefix'": `{"bool":{"filter":{"prefix":{"value":"prefix"}}}}`,
"value not starts_with 'prefix'": `{"bool":{"must_not":{"prefix":{"value":"prefix"}}}}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdeebswihart New tests.

@rodrigozhou rodrigozhou force-pushed the vis-support-starts-with branch from d4938fb to 51abcc0 Compare November 16, 2023 17:09
Comment on lines 546 to 566
// Prefix search
listRequest = &workflowservice.ListWorkflowExecutionsRequest{
Namespace: s.namespace,
PageSize: defaultPageSize,
Query: `CustomKeywordField STARTS_WITH "justice"`,
}
resp, err = s.engine.ListWorkflowExecutions(NewContext(), listRequest)
s.NoError(err)
s.Len(resp.GetExecutions(), 1)
s.Equal(id, resp.Executions[0].GetExecution().GetWorkflowId())
s.Equal(wt, resp.Executions[0].GetType().GetName())
s.Equal(searchAttr, resp.Executions[0].GetSearchAttributes())

// LIKE exact match on Keyword (supported)
listRequest = &workflowservice.ListWorkflowExecutionsRequest{
Namespace: s.namespace,
PageSize: defaultPageSize,
Query: `CustomKeywordField LIKE "%justice for all%"`,
}
resp, err = s.engine.ListWorkflowExecutions(NewContext(), listRequest)
s.NoError(err)
s.Len(resp.GetExecutions(), 1)
listRequest = &workflowservice.ListWorkflowExecutionsRequest{
Namespace: s.namespace,
PageSize: defaultPageSize,
Query: `CustomKeywordField NOT STARTS_WITH "justice"`,
}
resp, err = s.engine.ListWorkflowExecutions(NewContext(), listRequest)
s.NoError(err)
s.Len(resp.GetExecutions(), 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdeebswihart These are functional tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the ones I raise an issue about earlier. These tests look for the presence of a record (or no records) but do not verify that the returned record is what we expect.

Can you update these to ensure the returned execution actually matches the filter?I've seen tests like this (that look for the presence of a record) hide bugs where the incorrect record was returned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already added checks. See L555-557.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, thank you

@rodrigozhou rodrigozhou force-pushed the vis-support-starts-with branch from 51abcc0 to dd72876 Compare November 16, 2023 20:17
@rodrigozhou rodrigozhou merged commit 50b9805 into temporalio:main Nov 16, 2023
8 checks passed
@rodrigozhou rodrigozhou deleted the vis-support-starts-with branch November 16, 2023 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants