scray.cassandra.tools.CassandraIndexStatementGeneratorImpl.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-cassandra Show documentation
Show all versions of scray-cassandra Show documentation
scray adapter to r/w Cassandra column families
package scray.cassandra.tools
import scray.cassandra.tools.api.CassandraIndexStatementGenerator
import scray.querying.description.TableIdentifier
class CassandraIndexStatementGeneratorImpl extends CassandraIndexStatementGenerator {
/**
* Create cassandra index statement
* All elements are case sensitive.
*/
def getIndexString(ti: TableIdentifier, column: List[String]): String = {
val concatColumns = (acc: String, column: String) => {
if (acc.endsWith("(")) {
acc + "\"" + column + "\""
} else {
acc + ", \"" + column + "\""
}
}
val indexString = s"""CREATE INDEX ON "${ti.dbId}"."${ti.tableId}" ${column.foldLeft("(")(concatColumns)} );"""
indexString
}
}