How to select fields from SetColumn[String] in Phantom

516 views Asked by At

I have a Cassandra table Department with columns name_list extends SetColumn[String] with PartitionKey and id extends StringColumn with PartitionKey.

I want to fetch id where the requested name is present in name_list.

I tried using this code below but not getting any results

abstract class Departments extends Table[Departments, Department] with RootConnector {

  object id extends StringColumn with PartitionKey

  object dep_type extends StringColumn

  object name_list extends SetColumn[String] with Index

      def getByName(name: String) = {
        select(_.id, _.name_list)
          .where(_.name_list.contains(name))
          .allowFiltering()
          .one()
      }
}

Is there any way to solve this!!

2

There are 2 answers

0
Charmy Garg On BEST ANSWER

I think we do not need to extend Index for it. It is working fine with this too:-

object name_list extends SetColumn[String]

Now, I am getting id and name_list by using the same method as above:-

def getByName(name: String) = {
    select(_.id, _.name_list)
      .where(_.name_list.contains(name))
      .allowFiltering()
      .one()
  }
6
flavian On

Your schema has to be:

object name_list extends SetColumn[String] with Index

Without secondary indexing Cassandra does not support collection operations.