0

Using casssandra 2.28, java-connector3, sparks2.0.

I am trying to write a simple query with multiple select params- unable to get the syntax right. Single param works

CassandraJavaRDD<CassandraRow> rdd = javaFunc 
                .cassandraTable("test", "tests").where("ID= ?", "1");

How do I do multiple params, tried multiple ways all fail:

javaFunc.cassandraTable("tests", "test").where("ID= ?", "1").and("Name= ?", "John");

javaFunc.cassandraTable("tests", "test").where("ID= ?", "1"+ " and "+ "Name= ?", "John");

Tried build statement, gives error - does not like "eq":

Statement s = QueryBuilder.select().all()
            .from("tableName")
            .where(eq("column_1", 1))
            .and(eq("column_2", 9))
            .and(eq("column_3", 50));

Seems like a basic 101 query, but simply cant find any suitable example code.

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Sam-T
  • 1,877
  • 6
  • 23
  • 51
  • What error do you get back? The CQL generated by your query builder looks valid to me: SELECT * FROM tableName WHERE column_1=1 AND column_2=9 AND column_3=50; – Andy Tolbert Dec 14 '16 at 20:33
  • If the issue is a compiler error, you may need to import eq from QueryBuilder, i.e. 'import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;' – Andy Tolbert Dec 14 '16 at 20:34
  • @Andy Thanks, com.datastax.driver.core.querybuilder.QueryBuilder.eq was the trick. But how do I convert this Resultset into an RDD- seems a a multistep process? Also is there no way for does my original multi-param query- it returns a RDD and I can simply do a cassandracount on it (that is what I need for this current problem) – Sam-T Dec 14 '16 at 21:06

1 Answers1

1

So the syntax that finally worked is .where( ).where( ) (no .and )

javaFunc.cassandraTable("tests", "test").where("ID= ?", "1").where("Name= ?", "John");

Not sure if this is the only way or the most optimal way

Sam-T
  • 1,877
  • 6
  • 23
  • 51