0

I'm trying to query a Cassandra table using the IN clause and the @Query annotation from Spring Data

My query in init method-

     session = cassandraSessionFactory.getSession();
     statementmyList = session.prepare("select * from my_file_content where my_content IN (?);");

Tried to bind the query with boundStatement-

  final BoundStatement boundStatement = DaoConstants.getBoundStatement(statementmyList);

  try
  {
   List<Row> rowList =
      session
          .execute(
              boundStatement
                  .bind(myList))
          .all();

          // myList = "'04748558-0eb3','531aaf2bf6b782f95e2e','6fc98ac2'"     

}

rowList returns empty Array. What am i doing wrong here?

Andy Tolbert
  • 11,418
  • 1
  • 30
  • 45
saurav
  • 219
  • 1
  • 13

1 Answers1

0

The problem is you don't need the parenthesis if you are binding a full list, so it should be:

session = cassandraSessionFactory.getSession();
statementmyList = session.prepare("select * from my_file_content where my_content IN ?;");

(?) would work if you were providing a single value, but you want ? if you are providing a collection.

Andy Tolbert
  • 11,418
  • 1
  • 30
  • 45
  • This is quite certain that okla wants to use a collection passed as param. Now I am querious to know if it works this way or not. – Naresh Kumar Jul 11 '16 at 15:09
  • You can use a collection as a parameter, but you shouldn't have parenthesis around the bind marker, otherwise it will get interpreted as an element on a collection, instead of a collection itself. – Andy Tolbert Jul 11 '16 at 15:12
  • 1
    Great, its a learning for me. I will try this out today. – Naresh Kumar Jul 11 '16 at 15:13