Knows Not Much
Knows Not Much

Reputation: 31556

Can't find an implicit `SchemaMeta` for type

I wrote this simple application using Quill library to query 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

This returns a compile time error

Error:(14, 12) Can't find an implicit `SchemaMeta` for type `com.abhi.Movies`
      query[Movies]

Based on the documentation given here

https://github.com/getquill/quill/blob/master/CASSANDRA.md

I am not sure of what other code is needed to satisfy the missing implicit.

Upvotes: 4

Views: 2187

Answers (2)

mixel
mixel

Reputation: 25866

Quill does not yet support Scala 2.12. Track this PR for the progress.

Change scalaVersion:

scalaVersion := "2.11.8"

Also you have to use snapshot dependency because of this fix that was made after 1.0.0 release:

resolvers ++= Seq(
  Resolver.sonatypeRepo("snapshots")
)

libraryDependencies ++= Seq(
  "io.getquill" %% "quill-cassandra" % "1.0.2-SNAPSHOT"
)

Next you have to implement custom encoder and decoder for 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)
}

And mix it in your context:

lazy val ctx = new CassandraSyncContext[SnakeCase]("ctx") with Encoders with Decoders

Possibly you will get a warning:

Class javax.annotation.Nullable not found - continuing with a stub.

To fix it add following dependency:

libraryDependencies ++= Seq(
  "com.google.code.findbugs" % "jsr305" % "3.0.1"
)

Upvotes: 5

DevZer0
DevZer0

Reputation: 13535

so looks like you don't have a SchemaMeta that is capable of constructing com.abhi.Movies so you need to specify one explicitly

implicit val movieSchemaMeta = schemaMeta[com.abhi.Movies](....)

Upvotes: -1

Related Questions