pingles / clj-hector

Simple Cassandra client for Clojure
42 stars 19 forks source link

Retain column order by using an array map. #38

Closed ryfow closed 11 years ago

ryfow commented 12 years ago

For indexing purposes, clj-hector should return columns in the order Cassandra provides them.

pingles commented 11 years ago

Thanks- I've pushed this on to Clojars as the 0.2.4 release.

ryfow commented 11 years ago

Want to see something awesome?

user> (.getClass (into (array-map) [{"a" "b"} {"c" "d"} {"e" "f"} {"g" "h"} {"i" "j"} {"k" "l"} {"m" "n"} {"o" "p"}]))
clojure.lang.PersistentArrayMap

user> (.getClass (into (array-map) [{"a" "b"} {"c" "d"} {"e" "f"} {"g" "h"} {"i" "j"} {"k" "l"} {"m" "n"} {"o" "p"} {"q" "r"}]))
clojure.lang.PersistentHashMap

It turns out that this fix helps my problem occasionally, but not when it matters.

I can fix my current problem with the code below, but I wonder if we should revert to using sorted-map and provide an option to get the sequence of maps that the for loop returns. A map makes sense for static column families, but a list might make more sense with dynamic ones.

Have a preference?

  ColumnSliceImpl
  (to-clojure [s opts]
    (apply array-map
     (mapcat 
      first
      (for [c (.getColumns s)] 
        (to-clojure c opts)))))