scala - 未找到请求的操作 : [timestamp <-> java. lang.Long] 的编解码器

标签 scala cassandra

我在 Scala 中编写了这个简单的程序来查询 cassandra

val session = cass.session
lazy val stmt = cass.session.prepare(
   """
     |select token(id), id, date, rId, tt
     | from foo
     | where token(id) > ?
     | and token(id) <= ?;
   """.stripMargin
)

lazy val statement = stmt.bind().setLong(0, start).setLong(1, end)

def fromRow(row: Row): Foo = {
   val token = row.getLong(0)
   val id = row.getLong(1)
   val date = row.getLong(2)
   val rId = row.getLong(3)
   val tt = row.getInt(4)
   Foo(id, date, rId, tt)
}

但是此代码失败并出现错误
[error] (run-main-4) com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> java.lang.Long]
com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> java.lang.Long]
    at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:679)
    at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:526)
    at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:506)
    at com.datastax.driver.core.CodecRegistry.access$200(CodecRegistry.java:140)
    at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:211)
    at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:208)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)

最佳答案

使用驱动程序 v4.0,timestamp映射到 java.time.Instant , 所以:stmt.bind(Instant.ofEpochSecond(start), Instant.ofEpochSecond(end))

关于scala - 未找到请求的操作 : [timestamp <-> java. lang.Long] 的编解码器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39926022/

相关文章:

scala - "code: => Unit"在 Scala 中是什么意思?

scala - OptionT的笛卡尔生成器

cassandra - Cassandra 是否会阻止现有数据中心在重新加入集群时为读取请求提供服务?

cassandra - storm - 处理 bolt.execute 中的异常

scala - 使用 Scala 和 logback 配置 Apache Spark 日志记录

scala - 如何解决Scala中的导入冲突?

cassandra - 完全复制的 Cassandra 集群上非主键查询的性能

cassandra - 如果我将 RF 从 5 个减少到 3 个,然后停用 5 个节点中的 2 个,会发生什么情况?

Cassandra 同时清理多台服务器

java - 如何测试 Java 对象是否是 scala 中的枚举?