All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scray.cassandra.tools.CassandraIndexStatementGeneratorImpl.scala Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
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
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy