Created
August 9, 2015 09:19
-
-
Save Arnonrgo/19d97403ef18c39f62ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn extract-dataframe-schema | |
[rec] | |
(let [fields (reduce (fn [lst schema-line] | |
(let [k (first schema-line) | |
t (if (= (count schema-line) 3) (last schema-line) DataTypes/StringType) ] | |
(conj lst (DataTypes/createStructField (name k) t NULLABLE)))) [] rec) | |
arr (ArrayList. fields)] | |
(DataTypes/createStructType arr))) | |
(defn as-rows | |
[rec] | |
(let [values (object-array (reduce (fn [lst v] (conj lst v)) [] rec))] | |
(RowFactory/create values))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment