Skip to content

Pre-aggregation with Time Dimension Generates Invalid DATETIME Cast #9958

@itestyoy

Description

@itestyoy

Hello,

When we use a model with pre-aggregation by a time dimension, Cube stores the created_at column in the pre-aggregated table as a timestamp. However, when we query this pre-aggregated table, Cube generates a native SQL query that casts the placeholder to DATETIME, which causes the database to throw an error.

No matching signature for operator >= for argument types: TIMESTAMP, DATETIME Signature: T1 >= T1 Unable to find common supertype for templated argument <T1> Input types for <T1>: {TIMESTAMP, DATETIME} at [1:143]
{
  "timeDimensions": [
    {
      "dimension": "users.created_at",
      "granularity": "day",
      "dateRange": "this week"
    }
  ]
}
SELECT
  `users__created_at_day` `users__created_at_day`
FROM
  bi_dev_cube.users_main AS `users__main`
WHERE
  (
    `users__created_at_day` >= DATETIME(TIMESTAMP(?))
    AND `users__created_at_day` <= DATETIME(TIMESTAMP(?))
  )
GROUP BY
  1
ORDER BY
  1 ASC
LIMIT
  1000
cubes:
  - name: users
    sql: (select 1 as id, current_timestamp as created_at, current_timestamp as
      last_activity_at, 'BY' as country)

    dimensions:
      - name: id
        sql: id
        type: number
        primary_key: true
      - name: created_at
        sql: created_at
        type: time
      - name: last_activity_at
        sql: last_activity_at
        type: time
      - name: country
        sql: country
        type: string

    measures:
      - name: active_users
        type: count_distinct
        sql: id

    pre_aggregations:
      - name: main
        external: false
        measures:
          - users.active_users
        dimensions:
          - users.country
        refreshKey:
          every: 1 hour
        time_dimension: created_at
        granularity: day
        partition_granularity: month

Cube: 1.3.66
Database: BigQuery

Metadata

Metadata

Assignees

No one assigned

    Labels

    driver:bigqueryIssues related to the BigQuery driverpre-aggregationsIssues related to pre-aggregations

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions