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

SDK should provide a native query builder #568

Open
OpeOnikute opened this issue Dec 16, 2024 · 4 comments
Open

SDK should provide a native query builder #568

OpeOnikute opened this issue Dec 16, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@OpeOnikute
Copy link

OpeOnikute commented Dec 16, 2024

Is your feature request related to a problem? Please describe.
The visibility API provides powerful query functionality, but in the Golang SDK to create a query, the only option is to build your query by concatenating strings. This is brittle and is an opportunity to provide a nice query builder, like we have with SQL builders: https://github.com/huandu/go-sqlbuilder.

Describe the solution you'd like
A simple to use query builder that supports all the defined logical operators and list filters. I currently have a custom one that looks like this:

q := temporal.QueryBuilder{}
// temporal is an internal package with re-usable constants
q.StartQuery(temporal.SearchAttrExecutionStatus, '=', temporal.ExecStatusRunning)
q.And(temporal.SearchAttrWorkflowType, '=', workflowName)
// Look for a running workflow with the name
// q.Encode() returns something like: "WorkflowType='TestMe' AND ExecutionStatus='Running'"
request := &workflowservice.ListWorkflowExecutionsRequest{Query: q.Encode()}

Describe alternatives you've considered
Previously built queries using custom formatting

query = fmt.Sprintf("ExecutionStatus = 'Running' AND WorkflowType = '%s' AND (StartTime between '%s' and '%s')", workflowName, startTimeBoundary, currentTime.Format(time.RFC3339))

Additional context

@OpeOnikute OpeOnikute added the enhancement New feature or request label Dec 16, 2024
@Quinn-With-Two-Ns
Copy link
Contributor

Moving to features since this is a cross SDK feature ask, nothing specific to the Go SDK

@Quinn-With-Two-Ns Quinn-With-Two-Ns transferred this issue from temporalio/sdk-go Dec 17, 2024
@OpeOnikute
Copy link
Author

OpeOnikute commented Dec 23, 2024

While it can be implemented in every SDK, it's not particularly a cross-SDK ask because we just need methods to build strings. But to be fair, I use the Golang so I only care that it's present there. If other SDKs want it, separate discussion.

I have open-sourced my implementation of this here - https://github.com/OpeOnikute/temporal-go-querybuilder. It was trivial to write.

If it makes sense, I can try to make a PR to the Golang SDK.

@Quinn-With-Two-Ns
Copy link
Contributor

I understand you only require it on the Go, but Temporal tries to maintain parity and consistency across all the SDKs we own. Unless the feature request is inherently language specific, If we are to add this to one SDK we would need add it to all SDKs and any design would need to consider across all SDKs.

That being said I don't think there is any reason this query builder would need to live in the SDK so you may consider just packaging your query builder as its own Go module and share it the community.

@OpeOnikute
Copy link
Author

OpeOnikute commented Dec 23, 2024

While I'm happy to share it as a Go module in my repository (I have done so already), I believe it should live on one of the official Temporal repositories for ease of discovery, support, and documentation going forward. But none of that matters if no one needs it.

I'll leave you to decide what to do with this issue. If other members of the community start to want this as the Visibility API becomes more mature, it can be revisited.

For now, https://github.com/OpeOnikute/temporal-go-querybuilder remains available for anyone who needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants