fix(partition): support map keys in put_newer#21
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 `@lib/partitioned_buffer/partition.ex`:
- Around line 520-538: The current implementation of replace_match_spec uses a
guard-based key equality check with key: :"$3", which prevents ETS from using
its O(1) keyed lookup optimization on :set tables and forces a full table scan
instead. To fix this, implement a conditional match spec that uses the original
literal-key approach in the match head for non-map keys (which enables the fast
lookup), and only falls back to the guard-based approach with ms_literal(key)
for keys that contain maps (which would otherwise cause ETS to reject the match
spec). This way, the fast path is preserved for the common case while still
handling map-containing keys correctly.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6d511c27-ffd9-4e7b-89b2-7cca28c7c652
📒 Files selected for processing (3)
CHANGELOG.mdlib/partitioned_buffer/partition.extest/partitioned_buffer/map_test.exs
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Split the match spec so non-map keys keep the literal-key head (single keyed lookup on the set table), and only keys that actually contain a map fall back to the $3 guard form that avoids the ETS ArgumentError. Added a regression test for a map nested inside a list key; full suite is green. |
Closes #18.
put_newer/5raisedArgumentError("not a valid match specification") whenever the key contained a map, because ETS rejects a raw map at the key position of aselect_replace/2match head. This binds the key to a match variable and compares it in the guard instead, which works for any key shape. Added a regression test alongside the existing tuple/list-key cases and updated the changelog.Summary by CodeRabbit
Bug Fixes
put_newer/5andput_all_newer/3could raise anArgumentErrorwhen entry keys contained maps.Tests
put_newer/5.