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

feature: add $__dateTimeFilter() macro #872

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

SpencerTorres
Copy link
Collaborator

TL;DR

Adds a $__dateTimeFilter(dateColumn, timeColumn) that expands into:

WHERE
  (dateColumn >= toDate('2022-10-21') AND dateColumn <= toDate('2022-10-23'))
  AND
  (timeColumn >= toDateTime(1415792726) AND timeColumn <= toDateTime(1447328726))

Why?

A common pattern in ClickHouse is having an ORDER BY that looks like this:

PARTITION BY toYYYYMM(TimestampDate)
ORDER BY (TimestampDate, TimestampTime)

Where TimestampDate is a Date and TimestampTime is a DateTime.

When querying this, it is common to do $__dateFilter(TimestampDate) AND $__timeFilter(TimestampTime). This macro makes it shorter to type, by being able to do $__dateTimeFilter(TimestampDate, TimestampTime).

With this macro it is faster and more efficient to query tables that have this pattern of partitioning, since it references both time columns.

@SpencerTorres SpencerTorres requested a review from a team as a code owner June 21, 2024 02:10
Copy link
Contributor

@asimpson asimpson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 🚀

@asimpson asimpson merged commit 61d1e7d into grafana:main Jun 27, 2024
16 checks passed
@SpencerTorres SpencerTorres mentioned this pull request Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants