skydb/sky — pull request #149 by boourns (2013-10-15 01:06:29+00:00)
Title: Timezone & Bucketing support

@benbjohnson please review

This adds `SELECT count() by year(), month(), day()`, where year, month, day are functions of the current event's timestamp.

The functionality is also exposed in expressions, so you can do `WHEN year() == 2012` for example.

In order to convert an epoch timestamp to a year / month / day, we need to know the timezone, so this adds support for timezones as well.

I'd consider this an early PR, so I'm interested in your thoughts. There's some nastiness where I try to upconvert the dimension list from an Expression to a Function in order to change the codegen, and I didn't think twice about names or anything as I wrote this over canadian thanksgiving. I also probably broke some conventions in where I use String() vs Codegen() or similar.

Other TODO:

- add hour, minute
- I'd like to add 'week' as in week number into the year, but amazingly go doesn't have support for that in the `time.Format` :/. I am considering writing a raw method that will do the calculation with the parsed time object.
- backfill some unit tests

Amazing fact I didn't know until I did this PR: in C stdlib, there is no threadsafe way to do timezone manipulation. You have to manipulate the TZ environment variable and then parse the timestamps into 'local time'.