Repository navigation
fix(memory): avoid identifier columns in aggregation seed queries - #2358
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR prevents SUM aggregation over identifier columns by parsing relationship.condition expressions for join keys, normalizing model primary keys (including composites), applying id-name heuristics, and excluding those columns when selecting numeric aggregation candidates during seed query generation. ChangesIdentifier-Aware Seed Query Generation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels: Suggested reviewers:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 `@core/wren/src/wren/memory/seed_queries.py`:
- Around line 45-46: The membership checks against relationship_keys are
case-sensitive and allow mismatches; update the code that builds and queries
relationship_keys (refer to the use of relationship_keys and the
_model_seeds(...) call, and any checks like model["name"] or column identifiers)
to normalize identifiers (e.g., .lower() or a consistent canonical form) both
when inserting keys into relationship_keys and when performing membership checks
inside _model_seeds and related functions so comparisons are case-insensitive
and consistent across model and relationship names.
🪄 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: 5648bf84-9e92-43b6-a4c7-d6336d3990d5
📒 Files selected for processing (2)
core/wren/src/wren/memory/seed_queries.pycore/wren/tests/unit/test_seed_queries.py
|
Thanks for the suggestion and example. I agree this is a better fit since the relationship condition is an SQL expression. I’ve updated the implementation to use sqlglot to parse the condition and collect qualified columns from the AST, instead of relying on regex. I also added regression coverage for quoted identifiers and invalid relationship conditions. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Problem
wren memory indexgenerates seed NL-SQL pairs from the MDL manifest. Theaggregation template picks the first numeric column and applies
SUM(),previously excluding only a string
primaryKey. Identifier columns that arenumeric — foreign keys, join keys, composite-PK members — were treated as
measures, producing semantically meaningless seeds such as:
These pollute the memory index and dilute
wren memory recallquality.Fix
In
seed_queries.py, exclude identifier columns from the aggregation target.A column is an identifier if it is any of:
primaryKey(aligned with the schema change in feat(wren-core): support composite (multi-column) primary keys #2345).
relationships[].condition; both sidesof the join (and every column of an
AND-joined composite condition) areexcluded. This catches FKs whose name does not end in
_id(e.g.created_by).id/*_idby name — a case-insensitive fallback for identifiers thatare not declared via a relationship (covers upper-case warehouses like
Snowflake/Oracle).
Scope is intentionally narrow:
to avoid widening behavior.
*_idheuristic also drops a would-be metric literally named*_id(e.g.
household_id) — a deliberate, documented trade-off; real metricsshould avoid the
_idsuffix.No new MDL fields required — all signals already exist in the manifest.
Smoke test
Expected: prints the seeds, ends with
smoke test passed.On
mainit raisesAssertionError: identifier noise leaked: ['SUM(customer_id)', ...].Validation
Known limitations (out of scope)
grouped seed (
amount by customer_uuid). Left for a follow-up.model.columnrefs (whatWren emits); three-part schema-qualified refs are not parsed.
Summary by CodeRabbit
Bug Fixes
Tests