Invalid type error when using Datastax Cassandra D

2019-08-17 12:53发布

I have a case class which represents partition key values.

case class UserKeys (bucket:Int,
                    email: String)

I create query Clauses as follows:

def conditions(id: UserKeys):List[Clauses] = List(
    QueryBuilder.eq("bucket", id.bucket), //TODOM - pick table description from config/env file.
    QueryBuilder.eq("email", id.email)
  )

And use the query as follows

val selectStmt =
      select()
        .from(tablename)
        .where(QueryBuilder.eq(partitionKeyColumns(0), whereClauseList(0))).and(QueryBuilder.eq(partitionKeyColumns(1), whereClauseList(1))) 
        .limit(1)

I am getting following error.

com.datastax.driver.core.exceptions.InvalidTypeException: Value 0 of type class com.datastax.driver.core.querybuilder.Clause$SimpleClause does not correspond to any CQL3 type

Question 1 - What am I doing wrong? The query works on cqlsh

The table I am querying is

CREATE TABLE users (
    bucket int,
    email text,
    firstname text,
    lastname text,
    authprovider text,
    password text,
    PRIMARY KEY ((bucket, email), firstname, lastname)

Question 2 - Is there a way to print the List which contains the query clauses? I tried it but I get this incomprehensible text.

List(com.datastax.driver.core.querybuilder.Clause$SimpleClause@2389b3ee, com.datastax.driver.core.querybuilder.Clause$SimpleClause@927f81)

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-17 13:19

My bad, I was using the query clauses incorrectly. Rather than

.where(QueryBuilder.eq(partitionKeyColumns(0), whereClauseList(0))).and(QueryBuilder.eq(partitionKeyColumns(1), whereClauseList(1)))

I needed to do

.where(whereClauseList(0)).and(whereClauseList(1)) 

because the List already has QueryBuilder.eq("bucket", id.bucket) part

查看更多
登录 后发表回答