Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bug where CQL queries with no results were causing exceptions b…

…ecause the to-clojure protocol couldn't deal with a null value from QueryResultImpl
  • Loading branch information...
commit 63fdf6a07b5981e21b6027d26b62b947be293f44 1 parent ba91837
@mstump authored
Showing with 34 additions and 12 deletions.
  1. +16 −12 src/clj_hector/serialize.clj
  2. +18 −0 test/clj_hector/test/core.clj
View
28 src/clj_hector/serialize.clj
@@ -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))))
@@ -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)})))
View
18 test/clj_hector/test/core.clj
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.