Description
Description
It's common when dealing with date grouping/histograms to perform date truncation and formatting at the same time - for example, assume I want to group by month AND format the date to something else:
The natural way to do that is :
FROM mydata
| STATS my_sum = SUM(fieldtosum) BY month = DATE_FORMAT("yyyy-MM", @timestamp)
However a more efficient way to do this would be:
FROM mydata
// group on date trunction first
| STATS my_sum = SUM(fieldtosum) BY month= DATE_TRUNC(1 month, @timestamp)
// then perform the formatting
| EVAL group = DATE_FORMAT("yyyy-MM", month)
That is, we'd like to first group on the date (using truncation) - potentially by applying filters and apply the formatting just on the results.
P.S. Since at the moment DATE_TRUNC is not optimized, there's not much difference between the two.