Skip to content

Conversation

@mcheshkov
Copy link
Contributor

Check List

  • Tests have been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made (if issue reference is not provided)

This allows to keep join structure in some cases. Consider query like this:

SELECT cube2.dim, cube3.dim
FROM cube1
JOIN cube2 ON cube1.__cubeJoinField = cube2.__cubeJoinField
JOIN cube3 ON cube1.__cubeJoinField = cube3.__cubeJoinField
GROUP BY 1, 2

It references members only from cube2 and cube3, but join structure actually has cube1 as root, and it is completely missing from query.

Now every join will generate separate join hint during rewrite, and then they will get to JS side as a query-level join hints.

@codecov
Copy link

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 95.74468% with 16 lines in your changes missing coverage. Please review.

Project coverage is 84.10%. Comparing base (801fbe5) to head (6943d50).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...sql/cubesql/src/compile/rewrite/rules/old_split.rs 0.00% 10 Missing ⚠️
...besql/cubesql/src/compile/rewrite/rules/members.rs 97.79% 5 Missing ⚠️
rust/cubesql/cubesql/src/compile/builder.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9561      +/-   ##
==========================================
+ Coverage   84.09%   84.10%   +0.01%     
==========================================
  Files         230      230              
  Lines       84395    84409      +14     
==========================================
+ Hits        70969    70991      +22     
+ Misses      13426    13418       -8     
Flag Coverage Δ
cubesql 84.10% <95.74%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcheshkov mcheshkov marked this pull request as ready for review May 9, 2025 23:07
@mcheshkov mcheshkov requested review from a team as code owners May 9, 2025 23:07
Copy link
Member

@igorlukanin igorlukanin left a comment

Choose a reason for hiding this comment

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

Let's disallow to run "external" queries that contain join hints. Join hints should only be accepted for queries that have an "internal" origin, i.e., initiated by Cube as part of the SQL API processing. Consequently, a REST API query with join hints should always fail with a clear error message.

You can discuss this with @ovr.

@mcheshkov mcheshkov force-pushed the rewrite-keep-join-hints branch from 529d615 to 6943d50 Compare May 13, 2025 06:41
@mcheshkov
Copy link
Contributor Author

Let's disallow to run "external" queries that contain join hints. Join hints should only be accepted for queries that have an "internal" origin, i.e., initiated by Cube as part of the SQL API processing. Consequently, a REST API query with join hints should always fail with a clear error message.

You can discuss this with @ovr.

We discussed it with @paveltiunov, and decided that it’s ok to land it like this, and decide how to properly expose it in public API later

@mcheshkov mcheshkov merged commit 2b2ac1c into master May 13, 2025
82 checks passed
@mcheshkov mcheshkov deleted the rewrite-keep-join-hints branch May 13, 2025 08:27
marianore-muttdata pushed a commit to MuttData/cube that referenced this pull request Jun 17, 2025
This allows to keep join structure in some cases. Consider query like this:
```
SELECT cube2.dim, cube3.dim
FROM cube1
JOIN cube2 ON cube1.__cubeJoinField = cube2.__cubeJoinField
JOIN cube3 ON cube1.__cubeJoinField = cube3.__cubeJoinField
GROUP BY 1, 2
```
It references members only from `cube2` and `cube3`, but join structure actually has `cube1` as root, and it is completely missing from query.

Now every join will generate separate join hint during rewrite, and then they will get to JS side as a query-level join hints.


Supporting changes:
* Remove unused MergedMembersReplacer

* Remove unused rewrite for CrossJoin on empty CubeScan
CubeScan with empty members just should not manifest during rewrites: either it's `AllMembers`, or specific members, but never empty

* Simplify CrossJoin to CubeScan rewrite

* Drop ordering from CubeScan during CrossJoin rewrite
CROSS JOIN does not guarantee same ordering as inputs

* Rewrite join on `__cubeJoinField` directly to CubeScan, without intermediate CrossJoin
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.

6 participants