druid icon indicating copy to clipboard operation
druid copied to clipboard

Full ISO 8601 compatibility in query intervals

Open sascha-coenen opened this issue 8 years ago • 14 comments

The current Druid documentation states in several places that queries have a mandatory "intervals" or "interval" attribute which can contain ISO-8601 compatible intervals.

For instance the documentation on the groupby query (http://druid.io/docs/latest/querying/groupbyquery.html) states: "intervals : A JSON Object representing ISO-8601 Intervals. This defines the time ranges to run the query over"

According to the following wikipedia source (https://en.wikipedia.org/wiki/ISO_8601#Time_intervals), there are four valid forms of ISO-8601 intervals:

 <start>/<end>
 <start>/<duration>
 <duration>/<end>
 <duration>

It seems that Druid only supports the first three variants. When specifying a duration only, e.g. "P2D", then Druid returns an exception saying that the "/" character is required within each interval.

I believe that supporting the last interval format which is a duration relative to the current time (or latest data present in Druid) would be a very useful addition. Most queries involve relative dateranges. If forcing people to use absolute dates, every query needs to be templated such that the timeintervals gets computed by some external logic and then inserted into the query. If the relative duration format was supported, many queries could work without the need of templated injections of external metadata.

sascha-coenen avatar Jul 19 '18 09:07 sascha-coenen

Just wanted to note here that this is possible in DSQL:

You can issue a query like:

SELECT "channel", COUNT(*) AS "Count"
FROM "wikipedia"
WHERE "__time" >= CURRENT_TIMESTAMP - INTERVAL '1' DAY
GROUP BY "channel"
ORDER BY "Count" DESC

for example to get the last day of data. In general doing computations with CURRENT_TIMESTAMP can be very powerful.

vogievetsky avatar Aug 02 '18 04:08 vogievetsky

This issue has been marked as stale due to 280 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

stale[bot] avatar Jun 20 '19 23:06 stale[bot]

This issue has been marked as stale due to 280 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

stale[bot] avatar Apr 09 '20 21:04 stale[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

stale[bot] avatar May 07 '20 22:05 stale[bot]

I found this issue which relates to a problem that I am facing. Metabase (and potentially other dashboard-building software) does not support DruidSQL, and therefore we can't write native queries for data from purely relative time intervals (such as "P2D"). This is partly a Metabase problem, of course. But, rather than relying on software that connects to Druid to support DSQL, it would be very helpful to have relative time intervals supported in all query languages that Druid uses.

rmorris708 avatar Mar 22 '21 22:03 rmorris708

AFAIK this problem still exists and it should get fixed. @vogievetsky can you perhaps reopen the ticket and give it some attention?

Using DSQL is not an option when visualizing druid data with metabase.

snrbrnjna avatar Nov 25 '22 09:11 snrbrnjna

That makes sense. I will re-open this issue. However this is likely very hard to implement. I am not an expert on this but I think Druid uses the native query interval for the cache key and since a naked duration represents a different interval every second it might mess up the caching strategy.

vogievetsky avatar Dec 02 '22 18:12 vogievetsky

This issue is no longer marked as stale.

stale[bot] avatar Dec 02 '22 18:12 stale[bot]

This issue is no longer marked as stale.

stale[bot] avatar Dec 02 '22 18:12 stale[bot]

Hi, do we've any update on this feature? Do we've plans to pick this up?

saketbairoliya2 avatar Jul 13 '23 14:07 saketbairoliya2

There are no plans to pick this up since you can do it through SQL. The best way to workaround is to modify the client application so they can resolve the relative duration on their own end and send Druid the absolute duration. Supporting druid sql queries might be too much work in Metabase but maybe resolving a relative duration to an absolute interval is not? I can't say for sure but that direction is worth exploring.

abhishekagarwal87 avatar Jul 14 '23 06:07 abhishekagarwal87

Thanks @abhishekagarwal87 for the response. Have few questions:

  1. Do SQL based queries have better coverage in terms of features (in-build) functions accessibility? Why do we've a difference in support across native and SQL based queries?
  2. We're using an alert engine as a client - where it is not practical to pass relative time when submitting the alert rule.

saketbairoliya2 avatar Jul 14 '23 06:07 saketbairoliya2

This issue has been marked as stale due to 280 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Apr 20 '24 00:04 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar May 18 '24 00:05 github-actions[bot]