Skip to content

fix: VLP aggregation JOIN rewriting and start/end swap for UNION branches#207

Merged
genezhang merged 4 commits intomainfrom
fix/vlp-aggregation-join-rewriting
Mar 11, 2026
Merged

fix: VLP aggregation JOIN rewriting and start/end swap for UNION branches#207
genezhang merged 4 commits intomainfrom
fix/vlp-aggregation-join-rewriting

Conversation

@genezhang
Copy link
Copy Markdown
Owner

Summary

  • Fixes JOIN condition rewriting in VLP UNION branches — post-VLP relationship JOINs (e.g., -[:AUTHORED]->(p:Post) after VLP) now correctly reference VLP CTE columns instead of original Cypher aliases
  • Fixes reverse UNION branch inner SELECT for aggregation queries — t.start_id/t.end_id are now correctly swapped per branch direction
  • Fixes aggregate argument extraction to include VLP-rewritten Column/TableAlias expressions in inner UNION SELECT

Test plan

🤖 Generated with Claude Code

genezhang and others added 2 commits March 10, 2026 23:46
…ches

Three fixes for VLP queries with post-VLP relationships and aggregations:

1. Rewrite JOIN conditions in VLP UNION branches: JOIN ON conditions
   referenced original Cypher aliases (e.g., u2.user_id) instead of
   VLP CTE columns (e.g., t.end_id). Added JOIN condition rewriting
   in rewrite_vlp_branch_select() and dependency-based JOIN sorting.

2. Swap start/end columns in reverse UNION branch inner SELECT: For
   aggregation+UNION queries, the inner SELECT was shared across all
   branches. Reverse branches need t.start_id where forward uses
   t.end_id. Added per-branch direction detection and swap_vlp_start_end().

3. Include VLP column references in aggregate argument extraction:
   collect_property_access_sql() now handles Column and TableAlias
   expressions (produced by VLP rewriting), ensuring aggregate arguments
   like COUNT(DISTINCT t.end_id) are included in inner UNION SELECT.

Fixes 6 of 10 VLP aggregation xfail tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove xfail from 5 tests now passing after JOIN rewriting fix:
- test_vlp_with_count_distinct_basic
- test_vlp_with_multiple_aggregates
- test_vlp_with_order_by_aggregate
- test_vlp_with_nested_property_aggregate
- test_vlp_only_vlp_nodes_in_aggregate

Update remaining xfail reasons with specific root causes:
- test_vlp_with_sum_aggregate: needs VLP property columns (PR #206)
- test_vlp_no_aggregation: needs VLP property columns (PR #206)
- test_vlp_bidirectional_with_aggregate: CTE column resolution
- test_vlp_with_having_equivalent: CTE column resolution
- test_vlp_different_hop_counts: *1..3 timeout on test data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes SQL rendering for variable-length path (VLP) queries that combine UNION branches with aggregation, ensuring JOIN conditions and aggregate inputs are correctly rewritten against VLP CTE output columns.

Changes:

  • Rewrite JOIN ON/pre_filter expressions inside VLP UNION branches to reference VLP CTE columns (e.g., t.end_id) instead of original Cypher aliases.
  • Improve aggregate argument column collection for UNION+aggregation so outer aggregates can reference inner projections after VLP rewriting.
  • Update integration tests by removing/adjusting xfail markers to reflect newly passing cases and remaining known limitations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/clickhouse_query_generator/to_sql_query.rs Adds VLP UNION-branch JOIN rewriting, aggregate arg extraction updates, and start/end swap logic for reverse UNION branches under aggregation.
tests/integration/test_vlp_aggregation.py Updates xfail usage/reasons for VLP+aggregation integration tests based on the fixes and known remaining gaps.

Comment thread src/clickhouse_query_generator/to_sql_query.rs Outdated
Comment thread src/clickhouse_query_generator/to_sql_query.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@genezhang genezhang merged commit 4d5607b into main Mar 11, 2026
4 checks passed
@genezhang genezhang deleted the fix/vlp-aggregation-join-rewriting branch March 11, 2026 18:21
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