我使用Quill库编写了这个简单的应用程序来查询Cassandra
QuillSample.scala
import java.util.UUID
import io.getquill._
import scala.concurrent.ExecutionContext.Implicits.global
object QuillSample extends App {
lazy val ctx = new CassandraSyncContext[SnakeCase]("ctx")
import ctx._
val getAllRows = quote {
query[Movies]
}
val result = ctx.run(getAllRows)
println(result)
}
case class Movies(uUID: UUID,
avgRating: Float,
genres: Set[String],
name: String,
releaseDate: java.util.Date,
videoReleaseDate: java.util.Date)
build.sbt
name := "QuillSample"
version := "1.0"
scalaVersion := "2.12.0"
libraryDependencies ++= Seq(
"io.getquill" % "quill-cassandra_2.11" % "1.0.0"
)
application.properties
ctx.keyspace=movielens_small
ctx.preparedStatementCacheSize=1000
ctx.session.contactPoint=192.168.1.169
ctx.session.withPort=9042
ctx.session.queryOptions.consistencyLevel=LOCAL_QUORUM
ctx.session.withoutMetrics=true
ctx.session.withoutJMXReporting=false
ctx.session.maxSchemaAgreementWaitSeconds=1
ctx.session.addressTranslater=com.datastax.driver.core.policies.IdentityTranslator
这将返回编译时错误
Error:(14, 12) Can't find an implicit `SchemaMeta` for type `com.abhi.Movies`
query[Movies]
基于此处提供的文件
https://github.com/getquill/quill/blob/master/CASSANDRA.md
我不确定需要哪些其他代码来满足缺少的隐式。
答案 0 :(得分:4)
Quill尚不支持Scala 2.12。跟踪this PR进度。
更改scalaVersion
:
scalaVersion := "2.11.8"
此外,由于在1.0.0版本之后生成的this fix,您必须使用快照依赖性:
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)
libraryDependencies ++= Seq(
"io.getquill" %% "quill-cassandra" % "1.0.2-SNAPSHOT"
)
接下来,您必须为scala.collection.Set[T]
实现自定义编码器和解码器:
trait Encoders {
this: CassandraSessionContext[_] =>
implicit def setEncoder[T](implicit t: ClassTag[T]): Encoder[Set[T]] =
encoder((index, value, row) => row.setSet(index, value.asJava, t.runtimeClass.asInstanceOf[Class[T]]))
}
trait Decoders {
this: CassandraSessionContext[_] =>
implicit def setDecoder[T](implicit t: ClassTag[T]): Decoder[Set[T]] =
decoder((index, row) => row.getSet(index, t.runtimeClass.asInstanceOf[Class[T]]).asScala.toSet)
}
并在你的背景下混合:
lazy val ctx = new CassandraSyncContext[SnakeCase]("ctx") with Encoders with Decoders
可能会收到警告:
找不到类javax.annotation.Nullable - 继续存根。
要修复它,请添加以下依赖项:
libraryDependencies ++= Seq(
"com.google.code.findbugs" % "jsr305" % "3.0.1"
)
答案 1 :(得分:-1)
所以看起来你没有能够构建com.abhi.Movies
的SchemaMeta所以你需要明确指定一个
implicit val movieSchemaMeta = schemaMeta[com.abhi.Movies](....)