Skip to content

feat(tesseract): Basic pre-aggregations support #9434

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

waralexrom
Copy link
Member

@waralexrom waralexrom commented Apr 7, 2025

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

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 19.35484% with 50 lines in your changes missing coverage. Please review.

Project coverage is 80.27%. Comparing base (183c35a) to head (d5fd502).

Files with missing lines Patch % Lines
...es/cubejs-schema-compiler/src/adapter/BaseQuery.js 18.75% 39 Missing ⚠️
...ejs-schema-compiler/src/adapter/PreAggregations.js 23.07% 10 Missing ⚠️
...bejs-schema-compiler/src/compiler/CubeEvaluator.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9434      +/-   ##
==========================================
- Coverage   83.96%   80.27%   -3.70%     
==========================================
  Files         230      395     +165     
  Lines       84004    97550   +13546     
  Branches        0     2278    +2278     
==========================================
+ Hits        70536    78309    +7773     
- Misses      13468    18933    +5465     
- Partials        0      308     +308     
Flag Coverage Δ
cube-backend 57.38% <19.35%> (?)
cubesql 83.96% <ø> (ø)

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.

@waralexrom waralexrom force-pushed the tesseract-basic-pre-aggregations branch from be6e357 to ccf4c02 Compare April 21, 2025 18:11
@waralexrom waralexrom changed the base branch from master to tesseract-logical-plan April 21, 2025 18:12
@waralexrom waralexrom force-pushed the tesseract-logical-plan branch from 2d7ac7e to 37e2479 Compare April 28, 2025 08:37
Base automatically changed from tesseract-logical-plan to master April 28, 2025 09:33
@waralexrom waralexrom force-pushed the tesseract-basic-pre-aggregations branch from ccf4c02 to 09309d0 Compare April 28, 2025 18:43
@waralexrom waralexrom marked this pull request as ready for review May 1, 2025 14:20
@waralexrom waralexrom requested a review from a team as a code owner May 1, 2025 14:20
@waralexrom waralexrom force-pushed the tesseract-basic-pre-aggregations branch from 995c326 to 335c2ed Compare May 1, 2025 14:51
@waralexrom waralexrom requested a review from KSDaemon May 1, 2025 16:56
Copy link
Member

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

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

🚀 This is great!

const hasMultiStageMeasures = this.fullKeyQueryAggregateMeasures({ hasMultipliedForPreAggregation: true }).multiStageMembers.length > 0;
this.canUseNativeSqlPlannerPreAggregation = hasMultiStageMeasures;
} else {
this.useNativePreAggregations = false;
Copy link
Member

Choose a reason for hiding this comment

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

Is this property set in other cases? It's a class property and should be initialized in the constructor or at least defined. I know, this is JS which never complains, but let's follow a more right approach.

@@ -289,6 +289,12 @@ export class BaseQuery {
}).filter(R.identity).map(this.newTimeDimension.bind(this));
this.allFilters = this.timeDimensions.concat(this.segments).concat(this.filters);
this.useNativeSqlPlanner = this.options.useNativeSqlPlanner ?? getEnv('nativeSqlPlanner');
if (this.useNativeSqlPlanner) {
const hasMultiStageMeasures = this.fullKeyQueryAggregateMeasures({ hasMultipliedForPreAggregation: true }).multiStageMembers.length > 0;
this.canUseNativeSqlPlannerPreAggregation = hasMultiStageMeasures;
Copy link
Member

Choose a reason for hiding this comment

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

Is this property set in other cases? It's a class property and should be initialized in the constructor or at least defined. I know, this is JS which never complains, but let's follow a more right approach.

@@ -471,6 +477,19 @@ export class BaseQuery {
}

newDimension(dimensionPath) {
if (dimensionPath instanceof String || typeof dimensionPath === 'string') {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (dimensionPath instanceof String || typeof dimensionPath === 'string') {
if (typeof dimensionPath === 'string') {

There is no need in instanceof check. Because instanceof String catches only objects created as new String('abc'), and such objects are almost never used in practice.

@@ -471,6 +477,19 @@ export class BaseQuery {
}

newDimension(dimensionPath) {
if (dimensionPath instanceof String || typeof dimensionPath === 'string') {
const memberArr = Array.isArray(dimensionPath) ? dimensionPath : dimensionPath.split('.');
Copy link
Member

Choose a reason for hiding this comment

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

dimensionPath will never be an Array here, because you just checked it for a string! %)

this.cubeEvaluator.isDimension(memberArr.slice(0, -2))) {
return this.newTimeDimension(
{
dimension: this.cubeEvaluator.pathFromArray(memberArr.slice(0, -2)),
Copy link
Member

Choose a reason for hiding this comment

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

I think you don't need to call cubeEvaluator.pathFromArray here as you already have a dimensionPath as an array. it's a useless turnaround.

rewrited_multistage: &mut HashMap<String, bool>,
pre_aggregation: &Rc<CompiledPreAggregation>,
) -> Result<(), CubeError> {
if let Some(rewrited) =
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if let Some(rewrited) =
if let Some(rewritten) =

}
}

fn is_schema_and_filters_match(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn is_schema_and_filters_match(
fn do_schema_and_filters_match(

@@ -76,3 +76,13 @@ pub fn collect_cube_names(node: &Rc<MemberSymbol>) -> Result<Vec<String>, CubeEr
visitor.apply(node, &())?;
Ok(visitor.extract_result())
}

pub fn collect_cube_names_from_vec(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn collect_cube_names_from_vec(
pub fn collect_cube_names_from_members(

definition: Rc<dyn DimensionDefinition>,
is_reference: bool, // Is symbol is direct reference to another symbol without any calculations
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
is_reference: bool, // Is symbol is direct reference to another symbol without any calculations
is_reference: bool, // Symbol is a direct reference to another symbol without any calculations

@@ -241,6 +247,13 @@ impl SymbolFactory for DimensionSymbolFactory {
} else {
None
};

let is_sql_is_direct_ref = if let Some(sql) = &sql {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let is_sql_is_direct_ref = if let Some(sql) = &sql {
let is_sql_direct_ref = if let Some(sql) = &sql {

Copy link
Member

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

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

🚀 This is great! However there are some places need fixing

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