使用Datastax Cassandra驱动程序时出现无效的类型错误 [英] Invalid type error when using Datastax Cassandra Driver

查看:107
本文介绍了使用Datastax Cassandra驱动程序时出现无效的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 case类,它代表分区键值。

I have a case class which represents partition key values.

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

我创建查询克劳斯如下:

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

并按如下所示使用查询

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

我遇到以下错误。

com.datastax.driver.core.exceptions.InvalidTypeException:类别为com.datastax.driver.core.querybuilder.Clause $的值0 SimpleClause不对应任何CQL3类型

问题1 -我在做什么错?
查询适用于 cqlsh

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

我要查询的表是

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

问题2 -是否可以打印包含查询子句的 List ?我得到了这个难以理解的文本。

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)

推荐答案

我不好,我在用查询子句错误。而不是

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

我需要做

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

因为列表已经具有 QueryBuilder.eq( bucket,id.bucket)部分

这篇关于使用Datastax Cassandra驱动程序时出现无效的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆