Skip to content

Instantly share code, notes, and snippets.

@therako
Last active May 1, 2018 13:26
Show Gist options
  • Save therako/1056f95c46442034c4b8fb1bace4215c to your computer and use it in GitHub Desktop.
Save therako/1056f95c46442034c4b8fb1bace4215c to your computer and use it in GitHub Desktop.
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