Select Distinct support in JSON query - #103
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the query system to support more advanced distinct operations by replacing the simple string-based distinct field with a structured approach. The changes enable specifying both the columns to apply distinct on and the columns to select, providing greater flexibility for distinct queries.
- Introduced a new
Distinctstruct withonandselectfields to replace the simpleVec<String>distinct field - Updated query planning logic to handle the new distinct structure using
distinct_onoperations - Cleaned up unused imports and fixed schema parameter passing consistency
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| beacon-query/src/lib.rs | Introduces the new Distinct struct and updates QueryBody to use it instead of Vec<String> |
| beacon-query/src/parser.rs | Updates query planning logic to handle the new distinct structure, removes unused imports, and fixes schema parameter passing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let on_exprs = distinct | ||
| .on | ||
| .iter() | ||
| .map(|s| s.to_expr(&session.state())) | ||
| .collect::<anyhow::Result<Vec<_>>>()?; | ||
|
|
||
| let select_exprs = distinct | ||
| .select | ||
| .iter() | ||
| .map(|s| s.to_expr(&session.state())) | ||
| .collect::<anyhow::Result<Vec<_>>>()?; |
There was a problem hiding this comment.
[nitpick] The repeated pattern of mapping to_expr(&session.state()) and collecting results could be extracted into a helper function to reduce code duplication and improve maintainability.
This pull request updates the handling of the
distinctfield in query requests, enabling support for more advanced distinct queries by introducing a newDistinctstruct. The changes also update the query planning logic to use this new structure, allowing for distinct operations on specific columns with custom select expressions.Distinct query support:
distinctfield inQueryBodyfrom anOption<Vec<String>>to anOption<Distinct>, and introduced a newDistinctstruct withonandselectfields to specify which columns to apply distinct on and which columns to select. (beacon-query/src/lib.rs)Distinctstruct: now, if a distinct clause is present, the planner builds expressions for both theonandselectfields, and applies them usingdistinct_on. (beacon-query/src/parser.rs)Code cleanup:
beacon-query/src/parser.rsfor clarity and maintainability.Minor fix:
beacon-query/src/parser.rs)