refactor: JSON_VALUE in clickhouse query - #4852
Conversation
📝 WalkthroughWalkthroughThis PR changes ClickHouse meter queries to bind JSON value and group-by paths as query parameters. It adds recursive ChangesJSON path parameterization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant toSQL
participant QueryBuilder
participant FilterStringHelpers
toSQL->>QueryBuilder: Initialize builder
toSQL->>QueryBuilder: Bind JSON paths
toSQL->>FilterStringHelpers: Build filter expression
FilterStringHelpers->>QueryBuilder: Bind filter paths and values
QueryBuilder-->>toSQL: Return SQL and arguments
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/streaming/clickhouse/meter_query.go`:
- Around line 406-417: Update joinStringFilterWhereExprs and its callers to
recursively remove no-op filter children before building logical expressions, so
empty groups and mixed empty children produce no placeholders or malformed
predicates. Ensure the string-filter query path skips query.Where when filtering
yields no predicate, and add regression coverage for empty FilterGroupBy logical
lists and mixed no-op children.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2a2c7bd9-9310-4d0d-8a69-384dfd1dae24
📒 Files selected for processing (3)
openmeter/streaming/clickhouse/connector_test.goopenmeter/streaming/clickhouse/meter_query.goopenmeter/streaming/clickhouse/meter_query_test.go
Overview
Bind meter value-property and group-by JSONPaths as ClickHouse query parameters instead of interpolating them into SQL. This prevents crafted meter configuration from altering generated queries while preserving aggregation, grouping, and filtering behavior. Tests now verify injection-shaped JSONPaths remain bound values.
Summary by CodeRabbit
Bug Fixes
Tests
Greptile Summary
The PR hardens ClickHouse meter queries by binding value-property and group-by JSONPaths rather than interpolating them into SQL.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR M[Meter configuration] --> Q[queryMeter.toSQL] Q --> S[SELECT aggregation and grouping] Q --> F[Group-by filter expressions] S --> P[Bound JSONPath parameters] F --> P P --> CH[ClickHouse query execution]Reviews (2): Last reviewed commit: "fix: empty filters" | Re-trigger Greptile
Context used: