Skip to content

refactor(query): let unit descriptors own executor metadata (#2006) - #2234

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/query-unit-descriptor-2006
Jun 20, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/query-unit-descriptor-2006

Conversation

@Sinity

@Sinity Sinity commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Moves query-unit executor method names and aggregate grouping fields into QueryUnitDescriptor, so parser validation and result execution read from the same unit registry.

Problem

The aggregate pipeline work left two small but important parallel truths: expression.py owned aggregate group-field support, while unit_results.py owned SQL executor method names. That made each new terminal unit require another scattered wiring edit, which is exactly the #2006 descriptor-drift problem.

Solution

QueryUnitDescriptor now carries sql_query_method and aggregate_group_fields. The pipeline parser validates group by against the descriptor, and SQL unit-result execution dispatches through descriptor.sql_query_method. The descriptor metadata test now checks the live ArchiveStore method instead of a separate _SQL_QUERY_METHODS map.

Verification

  • nix develop --command devtools test tests/unit/cli/test_query_unit_renderer_metadata.py tests/unit/cli/test_query_expression.py -k "pipeline_group_by_count or aggregate_on_runtime" -> 3 passed
  • nix develop --command devtools verify --quick -> exit_code 0
  • nix develop --command devtools verify --seed-testmon --skip-slow -> 11688 passed, diagnosis pytest_passed, peak pytest tree RSS 3212.5 MiB
  • nix develop --command devtools verify -> 7 passed, diagnosis pytest_passed, peak pytest tree RSS 581.5 MiB

Ref #2006

Summary by CodeRabbit

  • Refactor
    • Centralized query unit configuration by consolidating internal mappings into unit descriptor definitions, improving maintainability and reducing code duplication.
    • Restructured validation logic to derive supported fields from unit metadata rather than hardcoded allowlists, making the system more flexible for future extensions.

Move SQL executor method names and aggregate grouping fields onto QueryUnitDescriptor so the parser and unit-result executor read from the same registry. This removes parallel maps added during the aggregate pipeline work and keeps #2006 query-unit wiring concentrated in one descriptor surface.

Ref #2006
@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: dcfa9964-cf8e-4ba3-98a4-4cdb330d69fa

📥 Commits

Reviewing files that changed from the base of the PR and between 6503340 and 1aa58d4.

📒 Files selected for processing (4)
  • polylogue/archive/query/expression.py
  • polylogue/archive/query/metadata.py
  • polylogue/archive/query/unit_results.py
  • tests/unit/cli/test_query_unit_renderer_metadata.py

📝 Walkthrough

Walkthrough

Two hardcoded module-level dicts (_SQL_QUERY_METHODS in unit_results.py and _AGGREGATE_GROUP_FIELDS in expression.py) are removed. Their data is relocated into two new fields on QueryUnitDescriptor (sql_query_method, aggregate_group_fields), populated for the four terminal units in QUERY_UNIT_DESCRIPTORS. Both consuming call sites are updated to read from the descriptor, and tests are updated to assert against descriptor fields.

Changes

Descriptor-driven SQL method and group-by field centralization

Layer / File(s) Summary
QueryUnitDescriptor contract and unit data
polylogue/archive/query/metadata.py
Adds sql_query_method: str | None = None and aggregate_group_fields: tuple[str, ...] = () to QueryUnitDescriptor. Populates both fields for the "message", "action", "block", and "assertion" entries in QUERY_UNIT_DESCRIPTORS.
Remove hardcoded dicts and read from descriptor
polylogue/archive/query/unit_results.py, polylogue/archive/query/expression.py
Deletes _SQL_QUERY_METHODS and _AGGREGATE_GROUP_FIELDS. Updates _build_sql_envelope to read descriptor.sql_query_method and _validate_aggregate_group_field to read descriptor.aggregate_group_fields.
Test assertions updated to descriptor fields
tests/unit/cli/test_query_unit_renderer_metadata.py
Adds ArchiveStore import, removes _SQL_QUERY_METHODS reference, and replaces it with field-level descriptor assertions (sql_query_method, aggregate_group_fields, hasattr on ArchiveStore).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Sinity/polylogue#2049: Adds the ArchiveStore.query_messages/query_actions/query_blocks methods that descriptor.sql_query_method now references, directly connecting to the SQL-method integration layer removed here.
  • Sinity/polylogue#2198: Also refactors metadata.py and expression.py to derive terminal behavior from QueryUnitDescriptor, making it a direct predecessor to this PR's descriptor-field extension.

Poem

🐇 Two dicts once hardcoded, now swept away,
The descriptor holds what they used to say.
sql_query_method and aggregate_group_fields too,
All gathered in one place, tidy and true.
No more scattered maps for this little bunny—
Centralized metadata? Now that's the money! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main refactoring: moving executor metadata ownership from scattered modules into QueryUnitDescriptor for centralized management.
Description check ✅ Passed The description covers all required sections: summary of changes, problem statement, solution details, comprehensive verification with specific commands and test results, and changelog guidance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/query-unit-descriptor-2006

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.

❤️ Share

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

@Sinity
Sinity merged commit 538c999 into master Jun 20, 2026
13 checks passed
@Sinity
Sinity deleted the feature/refactor/query-unit-descriptor-2006 branch June 20, 2026 11:51
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