thurstonsand / scala-cass

a wrapper for the Java Cassandra driver that allows extraction from a Row with Scala types, or directly into a case class. Also has utility functions for the Session to read/write to Cassandra directly to/from a case class.
MIT License
21 stars 10 forks source link

Could not find implicit value for evidence parameter of type #36

Closed AkhilGNair closed 7 years ago

AkhilGNair commented 7 years ago

Hi,

I'm trying to run a select statement from the README and I'm hitting an error. I'm very new to scala, so I'm not certain what it means - is this something easily recifiable?

The whole error contains some other fluff as I'm compiling this as an R extension, but the root is this compile time error

error: could not find implicit value for evidence parameter of type com.weather.scalacass.CCCassFormatEncoder[Query]
    val selectRes: Iterator[Row] = sSession.select("mytable", Query("asdf", 123))

This is pretty much all the code I have which hits the compile error.

import com.weather.scalacass._
import com.datastax.driver.core.{ Cluster, Row }

object thing {

 implicit val cluster = Cluster.builder.addContactPoint("localhost").build()
  implicit val session = cluster.connect()

 val sSession = ScalaSession("spark")(session) // if mykeyspace already exists

 def test( a:Any* ) : Iterator[Row] = {
    // given the table and query definition
    case class MyTable(s: String, i: Int, l: Option[Long])
    case class Query(s: String, i: Int)

   val selectRes: Iterator[Row] = sSession.select("mytable", Query("asdf", 123), false, Option(1L))
  }

}

This package looks great btw, I hope I'll be able to use it!

Thanks very much, Akhil

thurstonsand commented 7 years ago

hey Akhil. I'm not sure what it really means to define a case class inside a function, but I suspect that's your problem. Try this code block:

object thing {
  implicit val cluster = Cluster.builder.addContactPoint("localhost").build()
  implicit val session = cluster.connect()
  val sSession = ScalaSession("spark")(session) // if mykeyspace already exists

  case class MyTable(s: String, i: Int, l: Option[Long])
  case class Query(s: String, i: Int)
  def test( a:Any* ) : Iterator[Row] = sSession.select("mytable", Query("asdf", 123), false, Option(1L))
}

and let me know how it goes!

thurstonsand commented 7 years ago

oh and just so you know, you've sort of stumbled on a generic error regarding implicits that could mean a myriad of things...and the compiler won't tell you anything more specific than that. It's not the friendliest error to run into, and you're definitely not the only one to have run into it. But hopefully doing the above will resolve your problem

AkhilGNair commented 7 years ago

Ahh it worked! Thank you! I think the main error was that I was using the wrong version of your code - the latest on bintray was 2.0.0, but I was following the readme for 0.6.14.

Awesome, I'm sure this will be super useful to me :)

thurstonsand commented 7 years ago

oh yeah, that would do it. Sorry, that 2.0.0-M1 is not production ready, which is why I hadn't referenced it in the readme