Open
Description
Describe the bug
Some databases don't support aliases in SQL queries that are longer than certain number of symbols (it's 64 in case of Postgres). The sql_alias
parameter can help work around that limitation.
However, the SQL that Cube generates for subquery dimensions does not respect sql_alias
.
It results in queries that Postgres fails to understand and raises the following error:
table name "[redacted]" specified more than once
To Reproduce
Steps to reproduce the behavior:
- Take this data model:
cubes:
- name: my_auxiliary_cube
sql: SELECT 1 AS id, 123 AS value
dimensions:
- name: id
sql: id
type: number
primary_key: true
measures:
- name: count
type: count
- name: my_cube_with_a_very_long_name_xxxxxxxxxxxx
sql: SELECT 1 AS id, 123 AS value
sql_alias: x
joins:
- name: my_auxiliary_cube
relationship: one_to_one
sql: "{CUBE.id} = {my_auxiliary_cube.id}"
dimensions:
- name: id
sql: id
type: number
primary_key: true
- name: aux_count
sql: "{my_auxiliary_cube.count}"
type: number
sub_query: true
- Run the following query:
{
"dimensions": [
"my_cube_with_a_very_long_name_xxxxxxxxxxxx.aux_count"
]
}
- See the error.
Expected behavior
sql_alias
is respected by subquery dimensions. Shorter aliases are generated.
Version:
0.35.67
Additional context
Reported in Slack: https://cube-js.slack.com/archives/C04NYBJP7RQ/p1722447253496259