Skip to content

Tesseract interval arithmetic on Pinot emits invalid fromEpoch<unit> function names #11237

Description

@0eu

Describe the bug
When CUBEJS_TESSERACT_SQL_PLANNER=true, any Pinot-backed feature that shifts or offsets a timestamp -- time_shift and rolling_window -- generates calls to functions that Pinot does not have.

addInterval / subtractInterval build the expression as:

`${timeStampCast(date)} + fromEpoch${intervalUnit}(${intervalValue})`

intervalUnit is taken verbatim from the interval string ("1 year" -> year, "7 day" -> day), producing fromEpochyear(1), fromEpochday(7), fromEpochminute(30), etc. Pinot has neither the lowercase-singular spellings nor any year/month/week variant.

Generated SQL for a time_shift measure:

CAST("airline".ts as TIMESTAMP) + fromEpochyear(1)

Pinot errors:

QueryValidationError: No match found for function signature fromEpochyear(<NUMERIC>)

Generated SQL for a rolling_window uses fromEpochday(7), which fails the same way.

To Reproduce

  1. Configure a Cube project with the Pinot driver.
  2. Define a cube with a type: time dimension over a TIMESTAMP/epoch-millis column.
  3. Add a multi_stage time_shift measure and/or a trailing rolling_window measure.
  4. Enable Tesseract with CUBEJS_TESSERACT_SQL_PLANNER=true.
  5. Query the measure across the time dimension.
  6. Observe No match found for function signature fromEpoch<unit> from Pinot.

Expected behavior
The driver should emit interval arithmetic Pinot supports.

Expression Result
ts - fromEpochday(7) (driver output) error -- no such function
ts - fromEpochyear(1) / fromEpochmonth / fromEpochweek (driver output) error -- no such function
ts - fromEpochminute(30) (driver output) error -- no such function
ts - fromEpochDays(7) (correct fixed-unit name) OK
ts - fromEpochMinutes(30) (correct fixed-unit name) OK
TIMESTAMPADD(YEAR, 1, ts) OK
CAST(ts AS TIMESTAMP) + INTERVAL '7' DAY (on a column) error -- Unsupported ColumnDataType: OBJECT

Minimally reproducible Cube Schema

cubes:
  - name: airline
    sql_table: airlineStats  

    dimensions:
      - name: flight_num
        sql: FlightNum
        type: number
        primary_key: true
      - name: created_at
        sql: "{CUBE}.ts" # ts is a TIMESTAMP column
        type: time

    measures:
      - name: total_distance
        sql: Distance
        type: sum

      - name: distance_prior_year
        sql: "{CUBE.total_distance}"
        type: number
        multi_stage: true
        time_shift:
          - time_dimension: "{CUBE.created_at}"
            interval: 1 year
            type: prior

      - name: distance_rolling_7d
        sql: Distance
        type: sum
        rolling_window:
          trailing: 7 day

Query:

{
  "measures": ["airline.total_distance", "airline.distance_prior_year"],
  "timeDimensions": [
    { "dimension": "airline.created_at", "granularity": "month",
      "dateRange": ["2013-01-01", "2014-12-31"] }
  ]
}

Version:

  • Cube 1.7.1
  • Pinot 1.6.0

Additional context
I cherry-picked this diff first: #11001

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions