druid/docs/content/Granularities.md

57 lines
2.7 KiB
Markdown
Raw Normal View History

---
2013-09-26 19:22:28 -04:00
layout: doc_page
---
2014-01-16 18:37:07 -05:00
# Aggregation Granularity
The granularity field determines how data gets bucketed across the time dimension, or how it gets aggregated by hour, day, minute, etc.
2013-09-13 18:20:39 -04:00
It can be specified either as a string for simple granularities or as an object for arbitrary granularities.
### Simple Granularities
Simple granularities are specified as a string and bucket timestamps by their UTC time (e.g., days start at 00:00 UTC).
2013-09-13 18:20:39 -04:00
Supported granularity strings are: `all`, `none`, `minute`, `fifteen_minute`, `thirty_minute`, `hour` and `day`
* `all` buckets everything into a single bucket
2015-03-31 18:19:24 -04:00
* `none` does not bucket data (it actually uses the granularity of the index - minimum here is `none` which means millisecond granularity). Using `none` in a [TimeseriesQuery](TimeSeriesQuery.html) is currently not recommended (the system will try to generate 0 values for all milliseconds that didnt exist, which is often a lot).
2013-09-13 18:20:39 -04:00
### Duration Granularities
2014-11-14 16:25:21 -05:00
Duration granularities are specified as an exact duration in milliseconds and timestamps are returned as UTC. Duration granularity values are in millis.
2013-09-13 18:20:39 -04:00
They also support specifying an optional origin, which defines where to start counting time buckets from (defaults to 1970-01-01T00:00:00Z).
2013-09-13 18:20:39 -04:00
2014-10-19 21:38:20 -04:00
```javascript
2014-11-14 16:25:21 -05:00
{"type": "duration", "duration": 7200000}
```
2013-09-13 18:20:39 -04:00
This chunks up every 2 hours.
2014-10-19 21:38:20 -04:00
```javascript
2014-11-14 16:25:21 -05:00
{"type": "duration", "duration": 3600000, "origin": "2012-01-01T00:30:00Z"}
```
2013-09-13 18:20:39 -04:00
This chunks up every hour on the half-hour.
### Period Granularities
2014-10-23 14:38:01 -04:00
Period granularities are specified as arbitrary period combinations of years, months, weeks, hours, minutes and seconds (e.g. P2W, P3M, PT1H30M, PT0.750S) in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) format. They support specifying a time zone which determines where period boundaries start as well as the timezone of the returned timestamps. By default, years start on the first of January, months start on the first of the month and weeks start on Mondays unless an origin is specified.
2013-09-13 18:20:39 -04:00
Time zone is optional (defaults to UTC). Origin is optional (defaults to 1970-01-01T00:00:00 in the given time zone).
2013-09-13 18:20:39 -04:00
2014-10-19 21:38:20 -04:00
```javascript
{"type": "period", "period": "P2D", "timeZone": "America/Los_Angeles"}
```
2013-09-13 18:20:39 -04:00
This will bucket by two-day chunks in the Pacific timezone.
2013-09-13 18:20:39 -04:00
2014-10-19 21:38:20 -04:00
```javascript
{"type": "period", "period": "P3M", "timeZone": "America/Los_Angeles", "origin": "2012-02-01T00:00:00-08:00"}
```
2013-09-13 18:20:39 -04:00
This will bucket by 3-month chunks in the Pacific timezone where the three-month quarters are defined as starting from February.
2013-09-13 18:20:39 -04:00
#### Supported Time Zones
Timezone support is provided by the [Joda Time library](http://www.joda.org), which uses the standard IANA time zones. See the [Joda Time supported timezones](http://joda-time.sourceforge.net/timezones.html).