Skip to content

fix(schema-compiler): Avoid ambiguous dimension column mappings for ClickHouse queries #9674

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

Merged

Conversation

dragosrep
Copy link
Contributor

@dragosrep dragosrep commented Jun 12, 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

This fixes #9383

The root cause of this issue is the ClickHouse server that sometimes includes the table prefix in the column name when returning the result set. For example, the query:

SELECT
    q_0.id,
    q_0.cat,
    value_0,
    value_1
FROM  (
    SELECT 1 as id, 'a' as cat, 100 as value_0
) q_0
INNER JOIN (
    SELECT 1 as id, 'b' as cat, 200 as value_1
) q_1 ON q_0.id=q_1.id

returns:
image
,while:

SELECT
    q_0.id,
    q_0.cat,
    value_0,
    value_1
FROM  (
    SELECT 1 as id, 'a' as cat, 100 as value_0
) q_0
INNER JOIN (
    SELECT 1 as id, 'b' as cat, 200 as value_1
) q_1 ON q_0.id=q_1.id
INNER JOIN (
    SELECT 1 as id, 'c' as cat, 300 as value_2
) q_2 ON q_0.id=q_2.id

has the following result set:
image

Similarly, SQL result sets from complex analytics queries with cube joins sometimes end up with column names having the q_0 prefix, leading to an error when trying to map them to a dimension.

The overriden dimensionColumns explicitly sets the column name to avoid this problem. Without it, one of the two provided integration tests fails.

@dragosrep dragosrep requested a review from a team as a code owner June 12, 2025 01:35
@github-actions github-actions bot added the pr:community Contribution from Cube.js community members. label Jun 12, 2025
@KSDaemon KSDaemon self-assigned this Jun 18, 2025
@KSDaemon KSDaemon added driver:clickhouse Issues related to the ClickHouse driver data source driver labels Jun 18, 2025
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.

👍🏻 @dragosrep thnx for the clarifications! It seems to be good. Let's merge!

@KSDaemon KSDaemon merged commit ea2a59f into cube-js:master Jul 7, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data source driver driver:clickhouse Issues related to the ClickHouse driver pr:community Contribution from Cube.js community members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error mapping Clickhouse result set when using joins
2 participants