Last active
May 1, 2018 13:26
-
-
Save therako/1056f95c46442034c4b8fb1bace4215c 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
def SSTableWriter(it: Iterator[Row], createTableStatement: String, insertStatement: String, cassHosts: String): Unit = { | |
val uuid = UUID.randomUUID().toString | |
val dir = "/tmp/" + uuid | |
new File(dir).mkdirs() | |
val writer = CQLSSTableWriter.builder().inDirectory(dir).forTable(createTableStatement) | |
.using(insertStatement).withPartitioner(new Murmur3Partitioner()).build() | |
while (it.hasNext) { | |
val row = it.next() | |
val rowValues = new java.util.ArrayList[AnyRef](row.length) | |
row.schema.fields.indices.foreach(i => rowValues.add(row.get(i).asInstanceOf[AnyRef])) | |
writer.addRow(rowValues) | |
} | |
writer.close() | |
flushSSTableToCassandra(cassHosts, dir) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment