Skip to content

Wrong databricks time range filters. #9628

@hienphdev

Description

@hienphdev

Describe the bug

Cube.js is emitting an inclusive, UTC-conversion-wrapped end-date filter that doesn’t match the user’s configured range. Instead of generating a clean half-open or matching inclusive bound, it always wraps both ends in from_utc_timestamp(replace(…),'UTC') and uses an inclusive <= on the last millisecond of the next period.


To Reproduce

  1. Define a Cube.js measure over a time dimension:
   cube(`Orders`, {
     sql: `
       SELECT
         id,
         amount,
         status,
         transaction_timestamp
       FROM some_table
     `,
     measures: {
       netSales: { sql: `amount`, type: `sum` }
     },
     dimensions: {
       transactionTimestamp: { sql: `transaction_timestamp`, type: `time` }
     }
   });
  1. Issue a query for January 2023:
SELECT
  DATE_TRUNC('MONTH', transaction_timestamp) AS dt,
  MEASURE(Orders.netSales)              AS "Net Sales"
FROM Orders
WHERE Orders.transactionTimestamp >= '2023-01-01'
  AND Orders.transactionTimestamp <  '2023-02-01'
GROUP BY 1
ORDER BY 1 DESC;
  1. Inspect the generated SQL in the query inspector or logs. You’ll see:
SELECT
      date_trunc('month',
        from_utc_timestamp(`Orders`.transaction_timestamp,'UTC')
      )                             AS Orders__transaction_timestamp_month,
      SUM(net_sales)                AS Orders__net_sales
FROM <CATALOG>.<DATASET>.<TABLE> AS `Orders`
WHERE (
  Orders.transaction_timestamp >=
    from_utc_timestamp(
      replace(replace('2023-01-01T00:00:00.000Z','T',' '),'Z',''),
      'UTC'
    )
  AND Orders.transaction_timestamp <=
    from_utc_timestamp(
      replace(replace('2023-02-01T23:59:59.999Z','T',' '),'Z',''),
      'UTC'
    )
)
GROUP BY 1
ORDER BY 1 DESC
LIMIT 50000
  1. Note that the upper bound includes February 1st 23:59:59.999Z (the next period) rather than ending at January 31st.

Cube Version

v1.3.18

Metadata

Metadata

Assignees

Labels

api:sqlIssues related to SQL API

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions