Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a comprehensive SQL query builder system for the Nexus service, enabling type-safe construction of PostgreSQL queries from rule definitions. The implementation supports user attribute filtering, event-based rules, frequency conditions, and complex JSONB path navigation with proper type casting.
Key Changes
- Added a rule model with type definitions, operators, and tree navigation methods
- Implemented a query builder that recursively constructs SQL from rule trees
- Added support for nested JSONB paths using dot and bracket notation
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
services/nexus/internal/rules/rules.go |
Defines core rule types, operators, and period configurations with SQL mapping methods |
services/nexus/internal/rules/query/query.go |
Implements the QueryBuilder for generating SELECT queries and WHERE clauses |
services/nexus/internal/rules/query/rule.go |
Handles recursive rule parsing and JSONB path resolution for nested attributes |
services/nexus/internal/rules/query/event.go |
Builds event-based SQL with frequency conditions and time window logic |
services/nexus/internal/rules/query/comparison.go |
Constructs SQL comparison expressions for various operators and types |
services/nexus/internal/rules/query/query_test.go |
Comprehensive test coverage for all query builder functionality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new SQL query builder system for user and event segmentation rules in the Nexus service. The changes add a robust, type-safe way to define, compose, and generate PostgreSQL queries from a tree of rule definitions, supporting complex user and event attribute filtering, frequency/event-based rules, and JSONB path access. The system is modular, with clear separation for rule types, operators, and query construction logic.
Core Rule Model and Types:
rulespackage definingRule,RuleSet,Frequency,Period, and all supported operators, types, and groups, with methods for SQL type mapping and rule tree navigation.Query Builder Architecture:
QueryBuilderstruct with methods to generate SQL and arguments from aRuleSet, supporting both full SELECT queries and WHERE clause fragments.Rule Parsing and SQL Construction:
rule.go, including logic for logical wrappers (AND/OR), user attribute rules, and flexible JSONB/dot/bracket path resolution for nested attributes, with correct PostgreSQL type casting.Comparison and Event Rule Handling:
These changes lay the foundation for advanced, composable rule-based segmentation with strong type safety and SQL correctness.
References:
[1] [2] [3] [4] [5]