<commit_before>(ns clojurewerkz.cassaforte.query.types
  (:import [com.datastax.driver.core TupleType DataType]))

;;
;; Types
;;

(def primitive-types
  {:ascii     (DataType/ascii)
   :bigint    (DataType/bigint)
   :blob      (DataType/blob)
   :boolean   (DataType/cboolean)
   :counter   (DataType/counter)
   :decimal   (DataType/decimal)
   :double    (DataType/cdouble)
   :float     (DataType/cfloat)
   :inet      (DataType/inet)
   :int       (DataType/cint)
   :text      (DataType/text)
   :timestamp (DataType/timestamp)
   :uuid      (DataType/uuid)
   :varchar   (DataType/varchar)
   :varint    (DataType/varint)
   :timeuuid  (DataType/timeuuid)})

(defn resolve-primitive-type
  [type-or-name]
  (if (keyword? type-or-name)
    (if-let [res (get primitive-types type-or-name)]
      res
      (throw (IllegalArgumentException. (str "Column name "
                                             (name type-or-name)
                                             " was not found, pick one of ("
                                             (clojure.string/join "," (keys primitive-types))
                                             ")"))))
    type-or-name))

(defn list-type
  [primitive-type]
  (DataType/list (get primitive-types primitive-type)))

(defn set-type
  [primitive-type]
  (DataType/set (get primitive-types primitive-type)))

(defn map-type
  [key-type value-type]
  (DataType/map (get primitive-types key-type)
                (get primitive-types value-type)))

(defn tuple-of
  [types values]
  (.newValue (TupleType/of (into-array (map #(get primitive-types %) types)))
             (object-array values)))<commit_msg>Fix tuple-of<commit_after>(ns clojurewerkz.cassaforte.query.types
  (:import [com.datastax.driver.core TupleType DataType ProtocolVersion CodecRegistry]))

;;
;; Types
;;

(def primitive-types
  {:ascii     (DataType/ascii)
   :bigint    (DataType/bigint)
   :blob      (DataType/blob)
   :boolean   (DataType/cboolean)
   :counter   (DataType/counter)
   :decimal   (DataType/decimal)
   :double    (DataType/cdouble)
   :float     (DataType/cfloat)
   :inet      (DataType/inet)
   :int       (DataType/cint)
   :text      (DataType/text)
   :timestamp (DataType/timestamp)
   :uuid      (DataType/uuid)
   :varchar   (DataType/varchar)
   :varint    (DataType/varint)
   :timeuuid  (DataType/timeuuid)})

(defn resolve-primitive-type
  [type-or-name]
  (if (keyword? type-or-name)
    (if-let [res (get primitive-types type-or-name)]
      res
      (throw (IllegalArgumentException. (str "Column name "
                                             (name type-or-name)
                                             " was not found, pick one of ("
                                             (clojure.string/join "," (keys primitive-types))
                                             ")"))))
    type-or-name))

(defn list-type
  [primitive-type]
  (DataType/list (get primitive-types primitive-type)))

(defn set-type
  [primitive-type]
  (DataType/set (get primitive-types primitive-type)))

(defn map-type
  [key-type value-type]
  (DataType/map (get primitive-types key-type)
                (get primitive-types value-type)))

;; FIXME should be using cluster instance and cluster.metadata.newTupleType instead
(defn tuple-of
  [^ProtocolVersion protocol-version types values]
  (.newValue (TupleType/of protocol-version CodecRegistry/DEFAULT_INSTANCE ((into-array (map #(get primitive-types %) types))))
             (object-array values)))
{'fraction_non_alphanumeric': 0.12646303168712533, 'fraction_numerical': 0.0, 'mean_word_length': 2.1854545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623212', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1090, 'n_words': 231}