Skip to content

Conversation

@ArchishmanSengupta
Copy link

@ArchishmanSengupta ArchishmanSengupta commented Nov 5, 2025

What was changed

Add support for CONTAINS and NOT CONTAINS operators to enable substring matching in SQL queries.

Changes:

  • token.go: Register contains as a reserved keyword
  • ast.go: Add ContainsStr and NotContainsStr operator constants
  • sql.y: Add CONTAINS to operator precedence and grammar rules
  • sql.go: Regenerate parser from updated grammar using goyacc

Example usage:

SELECT * FROM workflows WHERE WorkflowId CONTAINS 'azure-ad'
SELECT * FROM workflows WHERE WorkflowType NOT CONTAINS 'test'

Why?

Currently, the parser only supports prefix matching via STARTS_WITH. This limitation makes it difficult to perform substring searches within field values, which is a common filtering use case.

Use case: Users need to find all workflows containing a specific substring in their WorkflowId or WorkflowType. For example:

  • Finding workflows: atom-agent-azure-ad-1, service-azure-ad-sync, azure-ad-integration-v2 by searching for substring "azure-ad"
  • This is not possible with STARTS_WITH alone since the substring may appear anywhere in the value

The CONTAINS operator complements STARTS_WITH by enabling substring matching at any position, providing more flexible filtering capabilities.

Related Changes

This PR is part of a feature implementation across multiple repositories:

  1. sqlparser (this PR): Add CONTAINS operator to SQL grammar
  2. Temporal Server (PR Link): Use CONTAINS in visibility query converters
    • Convert CONTAINS → SQL LIKE '%value%' for SQL databases
    • Convert CONTAINS → Elasticsearch WildcardQuery("*value*")
  3. Temporal UI (PR Link): Add "Contains" filter option in workflow search UI

All three PRs need to be merged together for the feature to work end-to-end.

Checklist

  1. Closes #[issue number if exists]

  2. How was this tested:

    • ✅ Parser correctly tokenizes CONTAINS keyword
    • ✅ AST properly represents CONTAINS and NOT CONTAINS expressions
    • ✅ Operator precedence works as expected
    • ✅ Grammar rules parse both CONTAINS and NOT CONTAINS variants
    • ✅ Tested with Temporal Server integration - queries execute successfully
    • ✅ Manual testing: WorkflowId CONTAINS "azure-ad" returns correct results
  3. Any docs updates needed?

    • No documentation exists for this library currently
    • Usage will be documented in Temporal Server docs as part of visibility query syntax

Implementation Notes

  • Added as a separate precedence line and at the end of grammar rules for minimal diff
  • Follows the same pattern as STARTS_WITH operator
  • Only 13 lines added to source files (token.go, ast.go, sql.y)
  • The large diff in sql.go is auto-generated by goyacc and is expected

- Add 'contains' keyword to token.go
- Add ContainsStr and NotContainsStr constants to ast.go
- Add CONTAINS operator precedence and grammar rules to sql.y
- Regenerate sql.go from updated grammar

Enables substring matching: WorkflowId CONTAINS 'azure-ad'
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.

1 participant