Skip to content

Instantly share code, notes, and snippets.

@making
Created March 9, 2010 23:22
Show Gist options
  • Save making/327281 to your computer and use it in GitHub Desktop.
Save making/327281 to your computer and use it in GitHub Desktop.
(ns org.clojars.making.cloudure.conv
(:import (org.apache.hadoop.io IntWritable LongWritable DoubleWritable Text))
)
(defmulti conv class)
(defmethod conv :default [x]
x)
(defmacro defconv [conv-map]
`(do
~@(for [c conv-map]
`(defmethod conv ~(first c) [x#]
(new ~(second c) x#)))))
(defn conv-write [key value context]
(.write context (conv key) (conv value)))
(defconv {Integer IntWritable,
Double DoubleWritable,
Long LongWritable,
String Text
;; and more
})
(comment
(do
(defmethod
conv
Integer
[x__4915__auto__]
(new IntWritable x__4915__auto__))
(defmethod
conv
Double
[x__4915__auto__]
(new DoubleWritable x__4915__auto__))
(defmethod
conv
Long
[x__4915__auto__]
(new LongWritable x__4915__auto__))
(defmethod conv String [x__4915__auto__] (new Text x__4915__auto__)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment