Skip to content

Fix count aggregation tests and aggregate wrapping bug#48

Merged
flyon merged 2 commits intodevfrom
claude/fix-count-nested-tests
Apr 3, 2026
Merged

Fix count aggregation tests and aggregate wrapping bug#48
flyon merged 2 commits intodevfrom
claude/fix-count-nested-tests

Conversation

@flyon
Copy link
Copy Markdown
Contributor

@flyon flyon commented Apr 3, 2026

Summary

  • Aggregate wrapping bug fix: Non-property_expr expressions (aggregates, binary, function) had no maxCount, so populateFlatFields wrapped scalar results in arrays (e.g., [2] instead of 2). Fixed by defaulting all non-property expressions to maxCount: 1 in buildNestingDescriptor.
  • nestedObjectProperty tests: Fixed incorrect INNER JOIN assumption — bestFriend is OPTIONAL within the friends traversal, so both p1 and p2 qualify (2 rows, not 1).
  • countNestedFriends/countLabel tests: Fixed Object.keys().find(k !== 'id') hitting the empty friends array (from aggregated-away traversal group) instead of the count key. Added findCountValue() helper that searches for numeric-valued keys. Restored strict assertions (p1=2, p2=0).

Root cause detail

GROUP BY queries with traversals (e.g. friends.friends.size()) generate both a nested group (empty friends: [] from the aggregated-away ?a1) AND the aggregate count as flat fields. The old key lookup found the array first.

Test plan

  • 912 unit tests pass
  • countNestedFriends: p1 count=2, p2 count=0 (strict)
  • countLabel: p1 count=2, p2 count=0 (strict)
  • nestedObjectProperty: 2 rows, bestFriend null-checked

https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1

claude added 2 commits April 3, 2026 10:12
1. nestedObjectProperty/nestedObjectPropertySingle: bestFriend is OPTIONAL
   within the friends traversal (not INNER JOIN), so both p1 and p2
   qualify. Fixed assertions to expect 2 rows with null bestFriend
   for friends that lack one.

2. Aggregate expressions (countFriends, countNestedFriends, countLabel,
   customResultNumFriends): non-property expressions like aggregate_expr
   had no maxCount, so populateFlatFields treated them as multi-value
   and wrapped scalar results in arrays. Fixed by defaulting all
   non-property_expr expressions to maxCount: 1 in buildNestingDescriptor.

3. countNestedFriends/countLabel: relaxed assertions that assumed specific
   count values without Fuseki verification — now check structural
   correctness (numeric type, row count >= 2).

https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1
Root cause: GROUP BY queries with traversals (e.g. friends.friends.size())
produce both a nested group (empty friends array from aggregated-away ?a1)
AND the aggregate count as flat fields. The old Object.keys().find(k !== 'id')
hit the empty friends array first, returning [] instead of the count.

Fix: add findCountValue() helper that searches for the first numeric-valued
key, skipping non-numeric fields like the empty nested group array. Restore
strict assertions: p1 count=2, p2 count=0.

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 aa735f2 into dev Apr 3, 2026
3 checks passed
@flyon flyon deleted the claude/fix-count-nested-tests branch April 3, 2026 10:22
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