Skip to content

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
Frank-TXS pushed a commit to Helge-TXS/cube that referenced this pull request Aug 5, 2025
…lickHouse queries (cube-js#9674)

* Set alias for dimension columns in ClickHouse queries

* Apply suggestion from @KSDaemon

---------

Co-authored-by: Konstantin Burkalev <[email protected]>
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