cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.51k stars 1.74k forks source link

SQL API: Error with subquery, but only when there is no SQL LIMIT #8345

Open sarchila opened 4 weeks ago

sarchila commented 4 weeks ago

Failed SQL Found an odd discrepancy when testing generated queries against our test Cube instance. This one was interesting because it only failed when there was no SQL LIMIT in the query, but simply adding a SQL LIMIT produced the expected result.

Queries

=> SELECT
  DISTINCT status
FROM
  (
    SELECT
      id,
      status,
      created_at,
      line_items_id,
      line_items_product_id,
      name,
      product_category,
      completed_count
    FROM
      orders_cube
  ) AS anon_1
ORDER BY
  1;

ERROR:  Error during planning: No field named 'anon_1.status'. Valid fields are 'orders_cube.status'.

=> SELECT
  DISTINCT status
FROM
  (
    SELECT
      id,
      status,
      created_at,
      line_items_id,
      line_items_product_id,
      name,
      product_category,
      completed_count
    FROM
      orders_cube
  ) AS anon_1
ORDER BY
  1
LIMIT
  50;

   status
------------
 completed
 processing
 shipped
(3 rows)

Version: 0.35.47

Additional context CUBESQL_SQL_PUSH_DOWN = true here

igorlukanin commented 2 weeks ago

Hi @sarchila 👋 Thanks for reporting this! I've tested this with v0.35.50 (CUBESQL_SQL_PUSH_DOWN=true) and was able to reproduce—however, it also does not work even when LIMIT is added. I suspect this might be a regression, I'd love to hear what @paveltiunov thinks.