Skip to content

Commit

Permalink
fixed bug where CQL queries with no results were causing exceptions b…
Browse files Browse the repository at this point in the history
…ecause the to-clojure protocol couldn't deal with a null value from QueryResultImpl
  • Loading branch information
Matt Stump committed Jun 12, 2012
1 parent ba91837 commit 63fdf6a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/clj_hector/serialize.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@
(extend-protocol ToClojure
ColumnDefinition
(to-clojure [c _] {:name (.getName c)
:index (.getIndexName c)
:index-type (.getIndexType c)
:validation-class (.getValidationClass c)})
:index (.getIndexName c)
:index-type (.getIndexType c)
:validation-class (.getValidationClass c)})

ColumnFamilyDefinition
(to-clojure [c opts] {:name (.getName c)
:comment (.getComment c)
:column-type (.getColumnType c)
:comparator-type (.getComparatorType c)
:sub-comparator-type (.getSubComparatorType c)
:columns (map (partial> to-clojure opts) (.getColumnMetadata c))})
:comment (.getComment c)
:column-type (.getColumnType c)
:comparator-type (.getComparatorType c)
:sub-comparator-type (.getSubComparatorType c)
:columns (map (partial> to-clojure opts) (.getColumnMetadata c))})

KeyspaceDefinition
(to-clojure [k opts] {(.getName k) {:strategy (.getStrategyClass k)
:replication (.getReplicationFactor k)
:column-families (map (partial> to-clojure opts) (.getCfDefs k))}})
:replication (.getReplicationFactor k)
:column-families (map (partial> to-clojure opts) (.getCfDefs k))}})
CounterRowsImpl
(to-clojure [s opts]
(into (sorted-map) (partial> to-clojure opts) (iterator-seq (.iterator s))))
Expand Down Expand Up @@ -139,5 +139,9 @@
(into [] (map #(.getValue %1) (.getComponents s))))))
QueryResultImpl
(to-clojure [s opts]
(with-meta (to-clojure (.get s) opts) {:exec_us (.getExecutionTimeMicro s)
:host (.getHostUsed s)})))
(with-meta
(if-let [result (.get s)]
(to-clojure result opts)
{})
{:exec_us (.getExecutionTimeMicro s)
:host (.getHostUsed s)})))
18 changes: 18 additions & 0 deletions test/clj_hector/test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@
(is (= {"row-key" {"k" "v"}}
(first (apply get-rows-cql-query keyspace "select * from A" opts)))))))

(deftest empty-result
(with-test-keyspace keyspace [{:name "A"}]
(let [column-family "A"
opts [:v-serializer :string
:n-serializer :string
:k-serializer :string]]
(is (= [{"row-key" {}}]
(apply get-rows keyspace column-family ["row-key"] opts))))))

(deftest empty-result-via-cql-query
(with-test-keyspace keyspace [{:name "A"}]
(let [column-family "A"
opts [:v-serializer :string
:n-serializer :string
:k-serializer :string]]
(is (= {}
(apply get-rows-cql-query keyspace "select * from A" opts))))))

(deftest dynamic-composite-column-ranges
(with-test-keyspace keyspace [{:name "A"}]
(let [column-family "A"
Expand Down

0 comments on commit 63fdf6a

Please sign in to comment.