REST Commands : Aggregate Query Command : Special Grouping Functions : TRUNCATE Function

TRUNCATE Function
The TRUNCATE function truncates a timestamp field to a given granularity, yielding a value that can be used as a grouping field. Before the timestamp field is truncated, the TRUNCATE function can optionally shift the value to another time first. The syntax for the function is:
TRUNCATE(<timestamp field>, <precision> [, <time shift>])
For example:
GET /LogDepot/AppLogs/_aggregate?m=COUNT(*)&f=TRUNCATE(Timestamp,DAY,GMT-2)
This query counts all AppLogs objects. For each one, it subtracts 2 hours from the Timestamp value and then truncates (“rounds down”) to the nearest day. The count of all objects for each truncated timestamp is computed in a separate group.
The <precision> value must be one of the following mnemonics:
The optional <time shift> parameter adds or subtracts a specific amount to each object’s timestamp value before truncating it to the requested granularity. Optionally, the parameter can be quoted in single or double quotes. The syntax of the <time shift> parameter is:
<timezone> | <GMT offset>
Where <GMT offset> uses the same format as the NOW function:
GMT<sign><hours>[:<minutes>]
The meaning of each format is summarized below:
<timezone>: A timezone abbreviation (e.g., "PST") or name (e.g., "America/Los_Angeles") can be given. Each object’s timestamp value is assumed to be in GMT (UTC) time and adjusted by the necessary amount to reflect the equivalent value in the given timezone. The allowable values for a <timezone> abbreviation or name are those recognized by the Java function java.util.TimeZone.getAvailableIDs().
GMT+<hour> or GMT-<hour>: The term GMT followed by a plus or minus signed followed by an integer hour value adjust each object’s timestamp up or down by the given number of hours.
GMT+<hour>:<minute> or GMT-<hour>:<minute>: This is the same as the previous format except that each object’s timestamp is adjusted up or down by the given hour and minute value.
Note that in the GMT versions, the sign (‘+’ or ‘-‘) is required, and in URIs, the ‘+’ sign must be escaped as %2B.
When a grouping field uses the TRUNCATE function, the truncated value is used for the field value within each group. An example is shown below:
{"results": {
"aggregate": {
"metric": "COUNT(*)",
"query": "*",
"group": "TRUNCATE(Timestamp,DAY,GMT-2)"},
"totalobjects": "2000090", "summary": "2000090",
"totalgroups": "3",
"groups": [
{"group": {
"metric": "105457",
"field": {"TRUNCATE(Timestamp,DAY,GMT-2)": "2006-01-12"}
}},
{"group": {
"metric": "605818",
"field": {"TRUNCATE(Timestamp,DAY,GMT-2)": "2006-01-13"}
}},
{"group": {
"metric": "288770",
"field": {"TRUNCATE(Timestamp,DAY,GMT-2)":"2006-01-13"}
}}
]
}}