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

Update ListAllWorkflowExecutions pinot endpoint #6160

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions common/persistence/pinot/pinot_visibility_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,20 +720,19 @@

func (s *PinotQuerySearchField) addEqual(obj string, val interface{}) {
s.checkFirstSearchField()
if _, ok := val.(string); ok {
val = fmt.Sprintf("'%s'", val)
} else {
val = fmt.Sprintf("%v", val)
switch val.(type) {
case string:
s.string += fmt.Sprintf("%s = '%s'\n", obj, val)
Copy link
Contributor

Choose a reason for hiding this comment

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

The whole thing with += of strings is extremely error-prone and inefficient.

I suggest revisiting this and building a set of filters to groups with "()" around them and then joining them together in one go.

But that would be a separate problem/PR.

cc @neil-xie

case int32:
s.string += fmt.Sprintf("%s = %d\n", obj, val)
default:
s.string += fmt.Sprintf("%s = %v\n", obj, val)

Check warning on line 729 in common/persistence/pinot/pinot_visibility_store.go

View check run for this annotation

Codecov / codecov/patch

common/persistence/pinot/pinot_visibility_store.go#L728-L729

Added lines #L728 - L729 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

A test for this case is missing (according to codecov).

}

quotedVal := fmt.Sprintf("%s", val)
s.string += fmt.Sprintf("%s = %s\n", obj, quotedVal)
}

func (s *PinotQuerySearchField) addMatch(obj string, val interface{}) {
s.checkFirstSearchField()

s.string += fmt.Sprintf("text_match(%s, '\"%s\"')\n", obj, val)
s.string += fmt.Sprintf("REGEXP_LIKE(%s, '^.*%s.*$')\n", obj, val)
Copy link
Member

Choose a reason for hiding this comment

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

Once we add the text index, we should use Text_Match for partial match.
Btw, for regexp like query, partial match can timeout for large cluster, it can work with prefix match which is REGEXP_LIKE(%s, '^%s.*$')

Copy link
Member

Choose a reason for hiding this comment

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

We can update and test after Pinot team enable text index for us.

}

func NewPinotQuery(tableName string) PinotQuery {
Expand Down Expand Up @@ -778,7 +777,7 @@

func (q *PinotQuery) addStatusFilters(status []types.WorkflowExecutionCloseStatus) {
for _, s := range status {
q.search.addEqual(CloseStatus, s.String())
q.search.addEqual(CloseStatus, int32(s))
}

q.search.lastSearchField()
Expand Down Expand Up @@ -1094,13 +1093,13 @@

if request.WorkflowSearchValue != "" {
if request.PartialMatch {
query.search.addMatch(WorkflowID, request.WorkflowSearchValue)
query.search.addMatch(WorkflowType, request.WorkflowSearchValue)
query.search.addMatch(RunID, request.WorkflowSearchValue)
query.search.addMatch(WfIDTextSearch, request.WorkflowSearchValue)
query.search.addMatch(WfTypeTextSearch, request.WorkflowSearchValue)
query.search.addMatch(RunIDTextSearch, request.WorkflowSearchValue)
} else {
query.search.addEqual(WorkflowID, request.WorkflowSearchValue)
query.search.addEqual(WorkflowType, request.WorkflowSearchValue)
query.search.addEqual(RunID, request.WorkflowSearchValue)
query.search.addEqual(WfIDTextSearch, request.WorkflowSearchValue)
query.search.addEqual(WfTypeTextSearch, request.WorkflowSearchValue)
query.search.addEqual(RunIDTextSearch, request.WorkflowSearchValue)
}

query.search.lastSearchField()
Expand Down
30 changes: 15 additions & 15 deletions common/persistence/pinot/pinot_visibility_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1776,12 +1776,12 @@ FROM %s
WHERE DomainID = 'bfd5c907-f899-4baf-a7b2-2ab85e623ebd'
AND IsDeleted = false
AND StartTime BETWEEN 1547596871371 AND 2547596873371
AND ( CloseStatus = 'COMPLETED'
OR CloseStatus = 'TIMED_OUT'
AND ( CloseStatus = 0
OR CloseStatus = 5
)
AND ( WorkflowID = '123'
OR WorkflowType = '123'
OR RunID = '123'
AND ( WorkflowIDTextSearch = '123'
OR WorkflowTypeTextSearch = '123'
OR RunIDTextSearch = '123'
)
Order BY StartTime DESC
LIMIT 0, 10
Expand Down Expand Up @@ -1809,11 +1809,11 @@ FROM %s
WHERE DomainID = 'bfd5c907-f899-4baf-a7b2-2ab85e623ebd'
AND IsDeleted = false
AND StartTime BETWEEN 1547596871371 AND 2547596873371
AND ( CloseStatus = 'TERMINATED'
AND ( CloseStatus = 3
)
AND ( WorkflowID = '123'
OR WorkflowType = '123'
OR RunID = '123'
AND ( WorkflowIDTextSearch = '123'
OR WorkflowTypeTextSearch = '123'
OR RunIDTextSearch = '123'
)
Order BY CloseTime ASC
LIMIT 0, 10
Expand All @@ -1840,9 +1840,9 @@ FROM %s
WHERE DomainID = 'bfd5c907-f899-4baf-a7b2-2ab85e623ebd'
AND IsDeleted = false
AND StartTime BETWEEN 1547596871371 AND 2547596873371
AND ( WorkflowID = '123'
OR WorkflowType = '123'
OR RunID = '123'
AND ( WorkflowIDTextSearch = '123'
OR WorkflowTypeTextSearch = '123'
OR RunIDTextSearch = '123'
)
Order BY StartTime DESC
LIMIT 0, 10
Expand All @@ -1867,9 +1867,9 @@ FROM %s
WHERE DomainID = 'bfd5c907-f899-4baf-a7b2-2ab85e623ebd'
AND IsDeleted = false
AND StartTime BETWEEN 1547596871371 AND 2547596873371
AND ( text_match(WorkflowID, '"123"')
OR text_match(WorkflowType, '"123"')
OR text_match(RunID, '"123"')
AND ( REGEXP_LIKE(WorkflowIDTextSearch, '^.*123.*$')
OR REGEXP_LIKE(WorkflowTypeTextSearch, '^.*123.*$')
OR REGEXP_LIKE(RunIDTextSearch, '^.*123.*$')
)
Order BY StartTime DESC
LIMIT 0, 10
Expand Down
Loading