Last active
May 1, 2018 13:20
-
-
Save therako/c1966cfca165c20bf00c007d4d985f16 to your computer and use it in GitHub Desktop.
Revisions
-
therako revised this gist
May 1, 2018 . 1 changed file with 1 addition and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,6 @@ private def getCreateTableStatement(keyspace: String, tableName: String, df: DataFrame, keys: Array[String]) = { val primaryKey = keys.mkString(",") val fields = df.schema.map(field => field.name + " " + field.dataType.simpleString.trim()) val fieldsDesc = fields.mkString(", ") "CREATE TABLE if not exists " + keyspace + "." + tableName + " (" + fieldsDesc + ", PRIMARY KEY (" + primaryKey + "))" } -
therako created this gist
May 1, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ private def getCreateTableStatement(keyspace: String, tableName: String, df: DataFrame, keys: Array[String]) = { val primaryKey = keys.mkString(",") val fields = df.schema.map(field => field.name + " " + (field.dataType.simpleString.trim() match { case "array<array<string>>" => "LIST<frozen<LIST<text>>>" case "array<string>" => "list<text>" case "string" => "text" case _ => field.dataType.simpleString.trim() })) val fieldsDesc = fields.mkString(", ") "CREATE TABLE if not exists " + keyspace + "." + tableName + " (" + fieldsDesc + ", PRIMARY KEY (" + primaryKey + "))" } private def getInsertStatement(keyspace: String, tableName: String, df: DataFrame) = { val fieldsDesc = df.schema.fields.map(f => f.name).mkString(",") val valuesHolder = df.schema.fields.map(_ => "?").mkString(",") "insert into " + keyspace + "." + tableName + " (" + fieldsDesc + ") values (" + valuesHolder + ")" }