michelin / snowflake-grafana-datasource

Snowflake Grafana datasource plugin enables the visual representation of Snowflake data within Grafana dashboards and manages alerts.
Apache License 2.0
67 stars 33 forks source link

Bug: plugin requires `TIMESTAMP_TYPE_MAPPING = TIMESTAMP_NTZ` #54

Closed rumbin closed 9 months ago

rumbin commented 9 months ago

Description

Currently this connector uses the generic to_timestamp() functions which depend on the account/user/session parameter TIMESTAMP_TYPE_MAPPING.

This is an issue, if this mapping is defined as, e.g., TIMESTAMP_TYPE_MAPPING = TIMESTAMP_LTZ for the whole Snowflake account:

SQL compilation error: Function TIME_SLICE does not support TIMESTAMP_LTZ(9) argument type

Suggested solutions

Solution 1

The connector issues the following query after initializing the session, before running charts' queries:

alter session set TIMESTAMP_TYPE_MAPPING = TIMESTAMP_NTZ;

Solution 2

We replace all to_timestamp() (and related) function calls by explicitly using the timestamp_ntz versions, e.g. to_timestamp_ntz(), try_to_timestamp_ntz()...