reddmetrics/forma-clj — pull request #50 by eightysteele (2012-06-18 21:24:47+00:00)
Title: Add Thrift API

This pull request rides on Sam's Thrift refactor in f4249ab9c06326acf02eb3dd47d73c16fec1e355. It basically just adds a `forma.thrift` namespace with a very simple API for creating, accessing, and unpacking our Thrift objects (defined in the `dev/forma.thrift` IDL). See docs in the `forma.thrift` namespace for usage examples. Tests are in `test/forma/thrift_test.clj`

Here's a quick overview of the API. We have functions for creating Thrift objects:

```clojure
NeighborValue*
FireValue*
ModisChunkLocation*
ModisPixelLocation*
TimeSeries*
FormaValue*
DataChunk*
```

Here's creating a `TimeSeries`:

```clojure
(TimeSeries* 0 1 [1.0 2.0 3.0])
;; #)>
```

To unpack Thrift objects, use the `unpack` function which returns a vector of Thrift object field values in the order specified in the IDL. Here's unpacking a `TimeSeries`:

```clojure
(def ts (TimeSeries* 0 1 [1.0 2.0 3.0]))
(unpack ts)
;; [0 1 #>]
```

Here's unpacking the `TimeSeries` series field:

```clojure
(unpack (get-series ts)
;; [1.0 2.0 3.0]
```

Finally, in a Cascalog query, sometimes you want to wrap the results of `unpack` in a vector. For that just use the `unpack*` function which wraps results in a vector.