cube icon indicating copy to clipboard operation
cube copied to clipboard

Pre-aggregations with elasticsearch as datasource are not timezone aware

Open ernriveron opened this issue 1 year ago • 1 comments

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;
}

ernriveron avatar Jan 29 '24 17:01 ernriveron

If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.

github-actions[bot] avatar Feb 05 '24 19:02 github-actions[bot]

Hi @ernriveron 👋

Thanks for the suggestion! Would you be open to create a PR with these changes?

igorlukanin avatar Feb 20 '24 12:02 igorlukanin