Describe the bug
When CUBEJS_TESSERACT_SQL_PLANNER=true, Pinot-backed cubes can generate invalid SQL with an empty FROM subquery:
This appears to be caused by PinotQuery.sqlTemplates() overriding statements.select with a template that reads {{ from }} / {{ from_alias }}, while the Tesseract planner passes the source through from_prepared. The base query template handles from_prepared, but the Pinot override does not.
To Reproduce
Steps to reproduce the behavior:
- Configure a Cube project with the Pinot driver.
- Define a cube using sql_table.
- Enable Tesseract with CUBEJS_TESSERACT_SQL_PLANNER=true.
- Generate SQL for a query against the Pinot cube.
- Observe that the generated SQL contains an empty FROM ( ) AS clause.
Example generated SQL shape:
SELECT
"events".id "events__id",
sum("events".amount) "events__total_amount"
FROM (
) AS
GROUP BY 1
Expected behavior
The generated SQL should include the Pinot table reference from sql_table, for example:
SELECT
"events".id "events__id",
sum("events".amount) "events__total_amount"
FROM events AS "events"
GROUP BY 1
More generally, Pinot’s statements.select template should support the same Tesseract-facing variables as the base select template, including from_prepared.
Screenshots
NA
Minimally reproducible Cube Schema
In case your bug report is data modelling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.
cube(`Events`, {
sql_table: `events`,
measures: {
totalAmount: {
sql: `amount`,
type: `sum`,
},
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primary_key: true,
},
},
});
Version:
Observed on Cube 1.6.52.
Additional context
The likely source is packages/cubejs-pinot-driver/src/PinotQuery.ts.
PinotQuery.sqlTemplates() currently overrides templates.statements.select and references {{ from }}:
templates.statements.select = 'SELECT ... \n' +
'FROM (\n {{ from }}\n) AS {{ from_alias }} \n' +
...
However, Tesseract renders select statements with from_prepared:
context! {
from_prepared => from,
...
}
The base BaseQuery select template handles this via:
{% if from %}
FROM (
{{ from | indent(2, true) }}
) AS {{ from_alias }}{% elif from_prepared %}
FROM {{ from_prepared }}
{% endif %}
Pinot’s override likely needs to preserve that branch. It may also need to preserve other base-template variables used by Tesseract, such as ctes, distinct, joins, filter, and having.
Describe the bug
When
CUBEJS_TESSERACT_SQL_PLANNER=true, Pinot-backed cubes can generate invalid SQL with an empty FROM subquery:This appears to be caused by PinotQuery.sqlTemplates() overriding statements.select with a template that reads
{{ from }} / {{ from_alias }}, while the Tesseract planner passes the source throughfrom_prepared. The base query template handlesfrom_prepared, but the Pinot override does not.To Reproduce
Steps to reproduce the behavior:
Example generated SQL shape:
Expected behavior
The generated SQL should include the Pinot table reference from sql_table, for example:
More generally, Pinot’s statements.select template should support the same Tesseract-facing variables as the base select template, including from_prepared.
Screenshots
NA
Minimally reproducible Cube Schema
In case your bug report is data modelling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.
Version:
Observed on Cube 1.6.52.
Additional context
The likely source is packages/cubejs-pinot-driver/src/PinotQuery.ts.
PinotQuery.sqlTemplates() currently overrides
templates.statements.selectand references{{ from }}:However, Tesseract renders select statements with
from_prepared:The base BaseQuery select template handles this via:
Pinot’s override likely needs to preserve that branch. It may also need to preserve other base-template variables used by Tesseract, such as ctes, distinct, joins, filter, and having.