Skip to content

fix: counts api response structure change#1616

Merged
nikhilsinhaparseable merged 1 commit intoparseablehq:mainfrom
nikhilsinhaparseable:counts-fix
Apr 8, 2026
Merged

fix: counts api response structure change#1616
nikhilsinhaparseable merged 1 commit intoparseablehq:mainfrom
nikhilsinhaparseable:counts-fix

Conversation

@nikhilsinhaparseable
Copy link
Copy Markdown
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Apr 8, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved timestamp formatting in count responses with timezone information, ensuring consistency across all queries.
    • Enhanced handling of grouped count queries with proper column value mapping and data normalization.
    • Standardized response field names from camelCase to snake_case for improved API consistency and predictability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

Walkthrough

The get_counts handler is refactored to handle group-by columns in filtered queries. It normalizes timestamp formatting in SQL results, reconstructs Arrow record batches with standardized timestamps, and enriches count records with corresponding group-by column values. The non-filtered code path also updates field naming for consistency.

Changes

Cohort / File(s) Summary
Count Handler Query Logic
src/handlers/http/query.rs
Modified get_counts to detect group-by columns, normalize timestamps by appending +00:00 to start_time/end_time fields via CountsRecord conversion, reconstruct Arrow RecordBatch with normalized values, and enrich results with group-by column values from original JSON records. Also updated non-filtered path field names from endTime to end_time.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as HTTP Handler
    participant SQL as SQL Engine
    participant Convert as JSON/Record Converter
    participant Process as Record Post-Processor
    
    Client->>Handler: GET counts (with group_by, conditions)
    Handler->>SQL: Execute counts query (includes group_by columns)
    SQL-->>Handler: Return RecordBatch with results
    
    Handler->>Convert: Convert RecordBatch to JSON
    Convert-->>Handler: JSON records
    
    Handler->>Process: Parse records to CountsRecord objects
    Process->>Process: Normalize timestamps (+00:00)
    Process-->>Handler: Normalized CountsRecord objects
    
    Handler->>Convert: Construct new RecordBatch<br/>(start_time, end_time, count)
    Convert-->>Handler: Normalized RecordBatch
    
    Handler->>Convert: Convert back to JSON
    Convert-->>Handler: Normalized JSON records
    
    alt group_by columns present
        Handler->>Process: Enrich records with group-by values<br/>(copy from original JSON)
        Process-->>Handler: Enriched count records
    end
    
    Handler-->>Client: Return counts response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #1601: Adds selection and grouping of group_by columns in counts SQL queries, which this PR consumes by enriching results with group-by column values.

Suggested reviewers

  • parmesant

Poem

🐰 Hop, hop, timestamps align!
Group-by treasures now entwine,
Arrow records dance and glow,
Enriched counts steal the show!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, missing required sections including Description, rationale, key changes, and testing/documentation checkboxes. Add a comprehensive description explaining what the counts API response structure change fixes, why it was needed, how it impacts consumers, and confirm the required testing and documentation checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing the counts API response structure, which aligns with the modifications to response field names and record structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/handlers/http/query.rs`:
- Around line 390-396: The code currently allows group_by columns (group_by_cols
/ body.conditions.group_by) to include reserved synthesized keys ("start_time",
"end_time", "count", "end_time") which later causes rec.insert(...) to clobber
normalized count payload and duplicate keys in fields; add validation after
constructing group_by_cols (before using has_groups/rec.insert) to detect any
intersection with the reserved set {"start_time","end_time","count"} and return
a clear BadRequest/validation error rejecting the request (or alternatively
alias those names) so collisions cannot reach rec.insert; reference
group_by_cols, body.conditions.group_by, has_groups, rec.insert and fields when
implementing the check and error path.
- Around line 424-446: The serde_json::from_value(...) and
RecordBatch::try_from_iter(...) error paths should be mapped to a 5xx internal
error instead of client errors; change the serde_json::from_value(...) call
(producing CountsRecord) to map_err into the QueryError variant used for
server/internal failures (e.g., QueryError::InternalError) and likewise change
the .map_err on RecordBatch::try_from_iter(...) to the same 5xx-mapped
QueryError variant, preserving the original error text in the message; update
the two call sites (serde_json::from_value and RecordBatch::try_from_iter) to
use the internal-error QueryError variant rather than QueryError::SerdeJsonError
or QueryError::CustomError so server-side transform failures return 5xx.
🪄 Autofix (Beta)

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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f04d7a6a-a3c4-4dd0-b041-eebffc40795a

📥 Commits

Reviewing files that changed from the base of the PR and between 79656f6 and 417f1de.

📒 Files selected for processing (1)
  • src/handlers/http/query.rs

@nikhilsinhaparseable nikhilsinhaparseable merged commit 2469862 into parseablehq:main Apr 8, 2026
12 checks passed
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.

2 participants