Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codec not found for requested operation: [timestamp <-> java.lang.Long]

I wrote this simple program in scala to query 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)
}

However this code fails with error

[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)
like image 875
Knows Not Much Avatar asked Feb 05 '23 23:02

Knows Not Much


1 Answers

With driver v4.0, timestamp is mapped to java.time.Instant, so: stmt.bind(Instant.ofEpochSecond(start), Instant.ofEpochSecond(end))

like image 97
Kuba Wenta Avatar answered Apr 27 '23 02:04

Kuba Wenta