Skip to content

Fix aggregate count mapping when alias collides with traversal#49

Merged
flyon merged 1 commit intodevfrom
claude/fix-count-aggregate-tests
Apr 3, 2026
Merged

Fix aggregate count mapping when alias collides with traversal#49
flyon merged 1 commit intodevfrom
claude/fix-count-aggregate-tests

Conversation

@flyon
Copy link
Copy Markdown
Contributor

@flyon flyon commented Apr 3, 2026

Summary

Fixes countNestedFriends and countLabel Fuseki tests returning undefined for aggregate count values.

Root cause

irToAlgebra renames aggregate aliases that collide with traversal aliases (e.g., a1a1_agg) and updates resultMap, but not the projection. When buildNestingDescriptor in resultMapping.ts looks up the projection by entry.alias (a1_agg), it finds nothing because the projection still has a1. The aggregate field is silently dropped — no count value appears on the result row.

Fix

When a resultMap entry has no matching projection entry (indicating an irToAlgebra rename), create a flat field descriptor using the resultMap alias directly as the SPARQL variable name, with maxCount: 1 (aggregates always produce single scalar values).

Test plan

  • 913 unit tests pass (1 new test for renamed aggregate alias scenario)
  • New test simulates exact alias collision: projection has a1, resultMap has a1_agg, Fuseki bindings have a1_agg → result correctly maps to count values (p1=2, p2=0)

https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1

Root cause: irToAlgebra renames aggregate aliases that collide with
traversal aliases (e.g. a1 → a1_agg) and updates resultMap, but not
the projection. buildNestingDescriptor then fails to find the projection
entry for the renamed alias, silently dropping the aggregate field.

Fix: when a resultMap entry has no matching projection (renamed by
irToAlgebra), create a flat field descriptor using the resultMap alias
directly as the SPARQL variable name, with maxCount: 1.

Adds unit test simulating the exact alias rename scenario.

https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

⚠️ No changeset found. If this PR should trigger a release, run npx changeset and commit the generated file.

If this change doesn't need a release (docs, CI config, etc.), you can ignore this message.

@flyon flyon merged commit ee83aa5 into dev Apr 3, 2026
3 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