Charmy Garg
Charmy Garg

Reputation: 291

How to select fields from SetColumn[String] in Phantom

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!!

Upvotes: 2

Views: 504

Answers (2)

Charmy Garg
Charmy Garg

Reputation: 291

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()
  }

Upvotes: 2

flavian
flavian

Reputation: 28511

Your schema has to be:

object name_list extends SetColumn[String] with Index

Without secondary indexing Cassandra does not support collection operations.

Upvotes: 0

Related Questions