cube-js / cube-js/cube

pre-aggregation not happening for many to one cube join on other cube measures

Open
#9,280 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

This is can be reproduced with following test cubes,cquery is becoming non-compatible for pre-aggregations even have the same query
```
cube("custom_agg_variant", {
data_source: "custom_source",
sql: `SELECT * from invoice_variant where deleted_at is null`,
joins: {
custom_agg: {
sql: `${CUBE}.invoice_id = ${custom_agg}.id`,
relationship: `many_to_one`,
},
},
dimensions: {
id: {
sql: `${CUBE}.id`,
type: "number",
primary_key: true,
},
},
measures: {
cost_of_goods: {
sql: `CASE when ${custom_agg.is_return} = 0 then ${CUBE}.cost * ${CUBE}.quantity else -(${CUBE}.cost * ${CUBE}.quantity) end`,
type: "sum",
},
},
pre_aggregations: {
main: {
type: `rollup`,
dimensions: [
custom_agg.stock_location_id,
],
measures: [
cost_of_goods,
custom_agg.sales_exclusive,
],
partitionGranularity: `month`,
timeDimension: custom_agg.complete_date,
granularity: `hour`,
build_range_start: { sql: `SELECT DATE('2024-01-01')` },
build_range_end: { sql: `SELECT NOW()` },
},
},
});

cube("custom_agg", {
data_source: "custom_source",
sql: `SELECT total, is_return, completion_date, stock_location_id, id, tax
from invoice i where AND deleted_at is null`,
dimensions: {
complete_date: {
sql: `${CUBE}.completion_date`,
type: "time",
},
stock_location_id: {
sql: `${CUBE}.stock_location_id`,
type: "number",
},
invoice_id: {
sql: `${CUBE}.id`,
type: "number",
primary_key: true,
},
is_return: {
sql: `${CUBE}.is_return`,
type: "number"
}
},
measures: {
sales_exclusive: {
sql: `CASE WHEN ${CUBE}.is_return = 0 THEN ${CUBE}.total - ${CUBE}.tax ELSE -(${CUBE}.total - ${CUBE}.tax) END`,
type: `sum`,
},
},
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.