Skip to content

Clickhouse times always truncated to secondsΒ #9051

@mzealey

Description

@mzealey

In anything marked as a type: time, the following code causes Clickhouse DateTime64() columns to be truncated to per-second:

public convertTz(field) {
//
// field yields a Date or a DateTime so add in the extra toDateTime64 to support the Date case
//
// https://clickhouse.yandex/docs/en/data_types/datetime/
// https://clickhouse.yandex/docs/en/query_language/functions/date_time_functions/
//
//
return `toTimeZone(toDateTime64(${field}, 0), '${this.timezone}')`;
}

In our case we are wanting to pull logs from the server (with ungrouped: true) and get them ordered according to millisecond/microsecond timestamps which are in the database.

In order to work around this issue I've had to resort to the following hack:

        - name: created    
          sql: created     
          type: time       
          primary_key: true

        - name: timestamp
          description: The unix epoch timestamp of the message
          sql: "toFloat64({CUBE}.created)"
          type: number

Metadata

Metadata

Assignees

No one assigned

    Labels

    driver:clickhouseIssues related to the ClickHouse driver

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions