Skip to content
This repository has been archived by the owner. It is now read-only.
Serialization and partitioning strategies for using Thrift with clj-pail.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test/pail_thrift
.gitignore
.travis.yml
LICENSE
README.md
project.clj

README.md

pail-thrift

Build Status

Serialization and partitioning strategies for using Thrift with clj-pail. Makes defining PailStructure classes for Thrift schemas easier.

Usage

Add pail-thrift to your project's dependencies. If you're using Leiningen, your project.clj should look something like this:

(defproject ...
  :dependencies [[pail-thrift VERSION]])

Where VERSION is the latest version on Clojars.

Defining a PailStructure

PailStructure classes are defined with the gen-structure macro from clj-pail. pail-thrift provides serializers and partitioners that can be used with the gen-structure macro.

(ns example.pail
  (:require [clj-pail.structure :refer [gen-structure]]
            [pail-thrift.serializer :as s]
            [pail-thrift.partitioner :as p])
  (:import (example.thrift MyUnion))
  (:gen-class))

(gen-structure example.pail.PailStructure
               :type MyUnion
               :serializer (s/thrift-serializer MyUnion)
               :partitioner (p/union-partitioner MyUnion))

In the above example, we define a PailStructure that serializes the example.thrift.MyUnion type using the default Thrift serialization protocol. The PailStructure will also be vertically partitioned by the active field of each union.

Controlling the Serialization Protocol

The previous example uses the default Thrift serialization protocol. The protocol can be specified as an additional argument to the thrift-serializer function. The protocols are defined in clj-thrift:

(require '[clj-thrift.protocol.factory :as protocol])

(s/thrift-serializer MyUnion (protocol/compact))

Vertical Partitioning

A PailStructure is vertically partitioned according to the partitioner supplied as the :partitioner keyword argument of gen-structure. pail-thrift provides generic partitioners, but you may want the partitioner to be specific to your application. For this reason, the generalized partitioners are designed to be composed by application-specific ones.

Generalized partitioners are defined in pail-thrift.partitioner. Currently, there are 2 partitioners. Both partition data based on the fields in a union. One partitioner uses field ids the other uses field names.

License

Copyright © 2013 David Cuddeback

Distributed under the MIT License.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.