-
Notifications
You must be signed in to change notification settings - Fork 0
/
partitioner.clj
54 lines (42 loc) · 1.48 KB
/
partitioner.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(ns pail-fressian.partitioner
"Defines a Pail partitioner for Thrift unions."
(:require [clj-pail.partitioner :as p]))
(defrecord ^{:doc "A pail partitioner for Fressian objects.
The partitioner will partition based on the first key in the object.
all objects with that same first keyword will go in that same directory."}
FressianPartitioner
[]
p/VerticalPartitioner
(p/make-partition
[this object]
(vector (name (first (keys object)))))
; Anything is ok for now.
(p/validate
[this dirs]
[true (rest dirs)]))
(defn fressian-partitioner
"Returns a `FressianPartitioner`."
[]
(FressianPartitioner.))
(defrecord ^{:doc "A pail partitioner for Fressian objects.
This partitioner will partition based on datatype. If the name of the datatype
ends in [Pp]roperty the partitioner will look at the type found in that data type's
:property field, and add that name to the path as well."}
FressianPropertyPartitioner
[]
p/VerticalPartitioner
(p/make-partition
[this object]
(let [res (vector (name (type object)))]
(if (re-find #"^.*[Pp]roperty$" (first res))
(let [prop (name (type (:property object)))]
(conj res prop))
res)))
; Anything is ok for now.
(p/validate
[this dirs]
[true (rest dirs)]))
(defn fressian-property-partitioner
"Returns a `FressianPropertyPartitioner`."
[]
(FressianPropertyPartitioner.))