Skip to content

Instantly share code, notes, and snippets.

@amitrathore
Created February 2, 2010 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitrathore/292512 to your computer and use it in GitHub Desktop.
Save amitrathore/292512 to your computer and use it in GitHub Desktop.
(defn capjure-insert
([object-to-save hbase-table-name row-id]
(capjure-insert object-to-save hbase-table-name row-id nil))
([object-to-save hbase-table-name row-id version-timestamp]
(let [#^HTable table (hbase-table hbase-table-name)
put (Put. (Bytes/toBytes row-id))
flattened (flatten object-to-save)]
(if version-timestamp
(do
(println "going to insert at:" version-timestamp " which is:" (class version-timestamp))
(.setTimeStamp put version-timestamp)
(println "ts from put:" (.getTimeStamp put))))
(add-to-insert-batch put flattened version-timestamp)
(.put table put)
(println "after insert at:" version-timestamp))))
(defn add-to-insert-batch [put flattened-list version-timestamp]
(doseq [[column value] flattened-list]
(let [[family qualifier] (.split column ":")]
(.add put (Bytes/toBytes family) (Bytes/toBytes (or qualifier "")) version-timestamp (Bytes/toBytes (str value))))))
;; (defn capjure-insert
;; ([object-to-save hbase-table-name row-id]
;; (capjure-insert object-to-save hbase-table-name row-id nil))
;; ([object-to-save hbase-table-name row-id version-timestamp]
;; (let [#^HTable table (hbase-table hbase-table-name)
;; ;; put (Put. (Bytes/toBytes row-id))
;; flattened (flatten object-to-save)]
;; (.put table (doto (Put. (.getBytes row-id))
;; (add-timestamp-if-exists version-timestamp)
;; (add-to-insert-batch flattened)))
;; ;; (if version-timestamp
;; ;; (do
;; ;; (println "going to insert at:" version-timestamp " which is:" (class version-timestamp))
;; ;; ;; (.setTimeStamp put version-timestamp)
;; ;; (println "ts from put:" (.getTimeStamp put))))
;; ;; (add-to-insert-batch put flattened)
;; ;; (.put table put)
;; (println "after insert at:" version-timestamp))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment