cube-js/cube

Pre-aggregations with elasticsearch as datasource are not timezone aware

开放

#7,700 创建于 2024年1月29日

 (2 条评论) (0 个反应) (0 位负责人)Rust (1,965 个派生)batch import
driver:elasticsearchhelp wanted

仓库指标

星标
 (19,563 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

When creating pre-aggregations with different time zones and elasticsearch as a data source, the time dimension of the results is not converted to each applicable time zone because 'convertTz' is not implemented in the "ElasticSearchQuery" adapter. The convertTz function code can be as follows:

public convertTz(field: string): string {
    const tz = moment().tz(this.timezone);
    // TODO respect day light saving
    const [hour, minute] = tz.format('Z').split(':');
    const [hourInt, minuteInt] = [parseInt(hour, 10), parseInt(minute, 10) * Math.sign(parseInt(hour, 10))];
    let result = field;
    if (hourInt !== 0) {
      result = `TIMESTAMPADD('hour', ${hourInt}, ${result})`;
    }
    if (minuteInt !== 0) {
      result = `TIMESTAMPADD('minute', ${minuteInt}, ${result})`;
    }
    return result;
}

贡献者指南