-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(tesseract): Prevent raw cube refs leaking into multi-stage pre-agg queries #10948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,15 @@ impl PreAggregationOptimizer { | |
| return Ok(None); | ||
| } | ||
|
|
||
| // Multi-stage rewrite is only safe when the outer source is a | ||
| // FullKeyAggregate: it references its dependent CTEs by name, so once | ||
| // each multistage member has been rewritten the outer SELECT contains | ||
| // no raw cube references. A LogicalJoin source would carry raw | ||
| // `cube.table` identifiers into the rewritten plan; combined with | ||
| // `is_external` becoming true (multi-stage pre-agg usages collected), | ||
| // the resulting SQL would be rendered with CubeStore templates and | ||
| // routed to CubeStore, which has no such table — surfacing as | ||
| // `Table <cube.table> was not found`. | ||
| let source = if let QuerySource::FullKeyAggregate(full_key_aggregate) = query.source() { | ||
| let result = FullKeyAggregate::builder() | ||
| .schema(full_key_aggregate.schema().clone()) | ||
|
|
@@ -262,7 +271,9 @@ impl PreAggregationOptimizer { | |
| .build(); | ||
| Rc::new(result).into() | ||
| } else { | ||
| query.source().clone() | ||
| self.usages.truncate(saved_usages_len); | ||
| self.usage_counter = saved_counter; | ||
| return Ok(None); | ||
| }; | ||
|
Comment on lines
273
to
277
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good fix. The previous code fell through with |
||
|
|
||
| // Reject mixed external/non-external pre-aggregation usages | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observation (non-blocking): The
.unwrap()calls on lines 53–54 are safe here because theelsebranch guaranteespre_aggregation_overrideisNone, which means the unpacker always setskeys_subquery,source, anddimension_subqueriestoSome. The logic is sound, but worth noting for future maintainers — the safety depends on thepack/unpackinvariant staying in sync.