Skip to content

Cube SQL API fails rewriting Tableau-generated CASE expression query #10462

@japsdeleon

Description

@japsdeleon

Failed SQL

SELECT
  (
    CASE
      WHEN CAST("xxxx_actuals_goc"."franchise_name" AS TEXT) IN ('<REDACTED_STR_1>', '<REDACTED_STR_2>')
      THEN '<REDACTED_STR_1>'
      ELSE CAST("xxxx_actuals_goc"."franchise_name" AS TEXT)
    END
  ) AS "Franchise"
FROM "public"."xxxx_actuals_goc" "xxxx_actuals_goc"
GROUP BY 1;

SET TIMEZONE TO '<REDACTED_TZ>';

Logical Plan

Initial Plan:
Projection: CASE WHEN CAST(xxxx_actuals_goc.franchise_name AS Utf8)
IN (Map { iter: Iter([Utf8("<REDACTED_STR_1>"), Utf8("<REDACTED_STR_2>")]) })
THEN Utf8("<REDACTED_STR_1>")
ELSE CAST(xxxx_actuals_goc.franchise_name AS Utf8)
END AS Franchise

Aggregate:
groupBy=[
  CASE WHEN CAST(#xxxx_actuals_goc.franchise_name AS Utf8)
  IN ([Utf8("<REDACTED_STR_1>"), Utf8("<REDACTED_STR_2>")])
  THEN Utf8("<REDACTED_STR_1>")
  ELSE CAST(#xxxx_actuals_goc.franchise_name AS Utf8)
  END
]
aggr=[[]]

Filter:
CASE WHEN strpos(
  CAST(upper(CAST(CAST(#xxxx_actuals_goc.franchise_name AS Utf8) AS Utf8)) AS Utf8),
  CAST(Utf8("<REDACTED_STR_3>") AS Utf8)
) > Int64(0)
THEN Utf8("<REDACTED_STR_3>")
ELSE CAST(#xxxx_actuals_goc.rls_group_name AS Utf8)
END
IN ([Utf8("<REDACTED_STR_4>"), Utf8("<REDACTED_STR_5>"), Utf8("<REDACTED_STR_6>")])

TableScan: xxxx_actuals_goc projection=None


Iterations: stop_reason: Some(Saturated)

Best cost: CubePlanCost {
  non_detected_cube_scans: 1,
  ungrouped_aggregates: 1,
  filters: 1,
  cube_scan_nodes: 1
}

Tool

The SQL query was generated automatically by Tableau, not written manually.

Connection details:
Tableau connects to Cube using the PostgreSQL connector
Queries are sent to Cube SQL API

Query was triggered when building a visualization in Tableau

Version:

Cube: 1.6.19
Tableau Server: 2026.1.0 (20261.26.0211.1127)
Platform: 64-bit Linux
Tableau Pod: eu-west-1a

Additional context

Tableau generates SQL that includes:

CASE WHEN ... IN (...) THEN ... ELSE ... END
GROUP BY 1 on the computed dimension
complex filters with mixed AND / OR
IS NULL checks

Tableau also sends session commands such as SET TIMEZONE.

Moreover, here's some important behavior observed:

- Tableau generates **multiple SQL queries in parallel** for a single dashboard render.
- Additional queries are also generated for:
  - dimension labels
  - filter controls
  - table layout calculations
  - formatting calculations (e.g., `TO_CHAR`, `COALESCE`, etc.)

Because of this behavior, it is difficult to correlate a specific failing SQL statement with the exact visualization element in the dashboard.

I have this SQL shown by Tableau UI but unfortunately can't find this exact query in the cube logs. I just picked a sample sql from those multiple parallel queries fired by Tableau and picked logs that I think associated with it.
QUERY: SELECT ((((((((COALESCE(TO_CHAR("xxxx_actuals_goc"."month_date", 'FMMonth'), 'Null') || ' ') || '') || ' ') || '') || ' ') || '') || ' ') || '') AS "Calculation_1453536791074545665", TO_CHAR("xxxx_actuals_goc"."month_date", 'FMMonth') AS "Calculation_6929139934857101322", (CAST('' AS TEXT)) AS "Dimension 1 (copy)_3396558551842734083", (CAST('' AS TEXT)) AS "Dimension 2 (copy)_3396558551842955271", (CAST('' AS TEXT)) AS "Dimension 3 (copy)_3396558551843049480", (CAST('' AS TEXT)) AS "Dimension 4 (copy)_3396558551843119113", SUM(1) AS "cnt:xxxx_actuals_goc_C3E2AFA2A4B04DB8A1DBB083E4E498B6:ok", SUM("xxxx_actuals_goc"."ARPU") AS "sum:ARPU:ok", SUM("xxxx_actuals_goc"."ATPU") AS "sum:ATPU:ok", SUM("xxxx_actuals_goc"."turnover") AS "sum:Calculation_3540392257877426185:ok", SUM(CAST("<>_actuals_goc"."active_players" AS DOUBLE)) AS "sum:Select metric - value (copy)_11413816573129
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:sqlIssues related to SQL API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions