fix(schema-compiler): use ClickHouse String type in Tesseract casts (#10316)#11053
Open
igorlukanin wants to merge 1 commit into
Open
fix(schema-compiler): use ClickHouse String type in Tesseract casts (#10316)#11053igorlukanin wants to merge 1 commit into
igorlukanin wants to merge 1 commit into
Conversation
|
Hi @igorlukanin - we've found that we get a different issue when Using Here's a repro test case: Clickhouse CREATE TABLE buyer (id String, first_name String, last_name String, email_addresses Array(String)) ENGINE = MergeTree() ORDER BY id;
CREATE TABLE purchase (id String, buyer_id String) ENGINE = MergeTree() ORDER BY id;
INSERT INTO buyer VALUES ('1', 'Alice', 'Smith', ['alice@example.com', 'alice.smith@example.com']);
INSERT INTO purchase VALUES ('1', '1');Cube # purchases.yml
cubes:
- name: purchases
sql: SELECT id, buyer_id FROM purchase
joins:
- name: buyers
sql: "{purchases}.buyer_id = {buyers}.id"
relationship: many_to_one
dimensions:
- name: id
sql: id
type: string
primary_key: true# buyers.yml
cubes:
- name: buyers
sql: SELECT id, first_name, last_name FROM buyer
joins:
- name: purchases
sql: "{buyers}.id = {purchases}.buyer_id"
relationship: one_to_many
- name: buyer_email_addresses
sql: "{buyers}.id = {buyer_email_addresses}.buyer_id"
relationship: one_to_many
dimensions:
- name: id
sql: id
type: string
primary_key: true
- name: first_name
sql: first_name
type: string# buyer_email_addresses.yml
cubes:
- name: buyer_email_addresses
sql: |
SELECT id AS buyer_id, arrayJoin(email_addresses) AS email_address
FROM buyer
joins:
- name: buyers
sql: "{buyer_email_addresses}.buyer_id = {buyers}.id"
relationship: many_to_one
dimensions:
- name: id
sql: buyer_id
type: string
primary_key: true
public: false
- name: email_address
sql: email_address
type: string
measures: []Cube SQL API query SELECT
purchases.id,
buyers.first_name,
array_agg(buyer_email_addresses.email_address) AS email_addresses
FROM purchases
CROSS JOIN buyers
CROSS JOIN buyer_email_addresses
WHERE purchases.id = '1'
GROUP BY purchases.id, buyers.first_nameEdit: this was also reported by another user in #10415 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes the ClickHouse string-cast casing bug reported in #10316.
When the Tesseract SQL planner (
CUBEJS_TESSERACT_SQL_PLANNER=true) renders a string cast on ClickHouse — e.g. the composite-primary-key concatenation behind acountmeasure queried through a join — it emitsCAST(x AS STRING).STRINGis not a valid ClickHouse type name (ClickHouse usesString, case-sensitive), so the query is rejected.Root cause
BaseQuerydefinestypes.string = 'STRING'. The legacy ClickHouse path never hits it becauseClickHouseQuery.castToString()is overridden to emitString. Tesseract, however, renders thetypes.stringtemplate directly, andClickHouseQuery.sqlTemplates()overridesboolean/timestampbut notstring— so the baseSTRINGleaks through.Fix
Override
templates.types.string = 'String'inClickHouseQuery.sqlTemplates(), mirroring the existingboolean/timestampoverrides.Note: #10316 also reported a null-safe
IS NULLjoin-key bug, which was already fixed in v1.6.24 (#10494). This PR addresses the remaining string-cast-casing symptom.