Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime64 Support #292

Closed
chr-istoph opened this issue Sep 21, 2020 · 15 comments · Fixed by #298, #300, #302 or grafana/grafana-plugin-repository#803
Closed

DateTime64 Support #292

chr-istoph opened this issue Sep 21, 2020 · 15 comments · Fixed by #298, #300, #302 or grafana/grafana-plugin-repository#803

Comments

@chr-istoph
Copy link

Thanks for this great plugin!

DateTime64 is the preferred Clickhouse data type for sub-second precision timestamps:
https://clickhouse.tech/docs/en/sql-reference/data-types/datetime64/

Is DateTime64 support on the horizon for this plugin?

Namely

  • Time range selection in the query builder (e.g. WHERE Timestamp BETWEEN toDateTime64(1598007073,3) AND toDateTime64(1598028056,3))
  • Display of sub-second precision return time series (e.g. sensor values logged at 10 Hz)
@Slach
Copy link
Collaborator

Slach commented Sep 21, 2020

@chr-istoph
according to grafana/grafana#3035
grafana itself supports only milliseconds resolution right now

so, for quick workaround you can try to use something like that
SELECT intDiv(toUInt64(datetime64_precision_3_field),$__interval_ms) AS t ... and
WHERE t BETWEEN toDateTime64($__from,3) AND toDateTime64($__to,3))
with grafana-clickhouse

@chr-istoph
Copy link
Author

@Slach
Thanks for the pointer 👍
This works a treat:

  • intDiv(toFloat64(datetime64_field)*1000, $__interval_ms) * $__interval_ms) as t

  • WHERE t BETWEEN toDateTime64($__from,3) AND toDateTime64($__to,3))

@mikhno-s
Copy link

Hey, similar ussue.

I have changed timestamp column type to DateTime64 and found out that my dashboard stopped to work.
Is it complex task to add DateTime64 as allowed column type to search?

it should be interpolated in row query into workaround as in upper messages.

Or if it is already done - how can I chose my DateTime64 field as a timestamp column?

@kakvablyat
Copy link

+1

@Slach
Copy link
Collaborator

Slach commented Nov 3, 2020

@chr-istoph @kakvablyat @mikhno-s could you check latest master version?

@Slach
Copy link
Collaborator

Slach commented Nov 3, 2020

@chr-istoph @kakvablyat @mikhno-s
you should change datetime column type to Column:DateTime64 in your queries

image

@mikhno-s
Copy link

mikhno-s commented Nov 3, 2020

Cannot save that parameter. It returns to DateTime.

However, this does not work for me:

...
intDiv(toFloat64(datetime64_field)*1000, $__interval_ms) * $__interval_ms) as t
...
WHERE t BETWEEN toDateTime64($__from,3) AND toDateTime64($__to,3)) ❌ 
...

The only way I made it work:

WHERE $dateTimeCol BETWEEN toDateTime64($__from/1000, 3) AND toDateTime64($__to/1000,3) ✅ 

UPD:
plugin - v2.1.0
grafana -v7.1.5
clickhouse - v20.3.16

I've not tried last plugin ver, but I see that without /1000 it does not work anyway.
The cause, for example $__to transforms to 1604267999000, that becomes 1604267999000.000 after toDateTime64 transformation.

SELECT toDateTime64(1604267999000, 3)
┌─toDateTime64(1604267999000, 3)─┐
│          2028-02-15 :43:20.000 │
└────────────────────────────────┘

@Slach Slach reopened this Nov 3, 2020
@mikhno-s
Copy link

mikhno-s commented Nov 3, 2020

Also, possible solution for grafana > v7.1.2

WHERE $dateTimeCol BETWEEN toDateTime64(${__from:date:seconds}, 3) AND toDateTime64(${__to:date:seconds},3)

@Slach
Copy link
Collaborator

Slach commented Nov 4, 2020

@mikhno-s @chr-istoph @kakvablyat could you check latest master again?
I added support DateTime64 to $timeFilter and $timeSeries
please look to https://github.com/Vertamedia/clickhouse-grafana/blob/master/docker/grafana/dashboards/test_datetime64_support.json for dashboard example

@Slach
Copy link
Collaborator

Slach commented Nov 5, 2020

@mikhno-s could please try to use latest master version
image
and look to ClickHouse/ClickHouse#16655

@vbichov
Copy link
Contributor

vbichov commented Nov 10, 2020

@Slach doesn't work:
the generated sql for $timeSeries with min step of 60s is:
(intDiv(toFloat32(timestamp) * 1000, 60) * 60) as t

while it should be:
(intDiv(toFloat32(timestamp) * 1000, 60000) * 60000) as t

@Slach Slach reopened this Nov 10, 2020
@Slach
Copy link
Collaborator

Slach commented Nov 10, 2020

@vbichov which DateTime64 type do you use? DateTime64(3) or DateTime64(6) ?

@mikhno-s
Copy link

@Slach DateTime64(3)

@Slach
Copy link
Collaborator

Slach commented Nov 11, 2020

@mikhno-s , @vbichov could you try latest master again?

@vbichov
Copy link
Contributor

vbichov commented Nov 11, 2020

Works for me - thanks.

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Nov 30, 2020
# 2.2.0 (2020-11-30)
## Enhancement:

* add region support to annotation query, try to fix wrong column orders for table format, fix Altinity/clickhouse-grafana#303
* add plugin sign process, fix Altinity/clickhouse-grafana#212
* add `DateTime64` support, fix Altinity/clickhouse-grafana#292
* add `linux\arm64` backend plugin build
* improve ARRAY JOIN parsing, fix Altinity/clickhouse-grafana#284
* improve `docker-compose.yaml` add ability to redefine `GRAFANA_VERSION` and `CLICKHOUSE_VERSION` via environment variables `latest` by default

## Fixes:
* add `*.js.map` and `*.js` from src and spec folder to .gitignore
* don't apply adhoc filters twice when used $adhoc macros, fix Altinity/clickhouse-grafana#282
* fix corner case for table format with wrong columns order between meta and data response section, fix Altinity/clickhouse-grafana#281
* add trickster to docker-compose environment
* actualize links in README.md

Signed-off-by: Eugene Klimov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants