1
votes

I am following the tutorial here: http://blog.websudos.com/2015/04/04/a-series-on-phantom-part-1-getting-started-with-phantom/

Cassandra version: 2.1.8

PhatomVersion 1.10.1

Scala version: 2.11.2

sbt-version: 0.13.8

In addition to the code given in the article I have the following:

object App {
  def main(args: Array[String]) {
    val user = new User(UUID.fromString("00000000-0000-0000-0000-000000000000"), "[email protected]", "Dan", DateTime.now)
   val resultSetFuture = Users.store(user)
   Await.result(resultSetFuture, Duration.Inf)
  }
}

When I run the program from sbt I get the following error (here is the head of the stack trace):

[error] (run-main-0) com.datastax.driver.core.exceptions.SyntaxError: line 1:157 no viable alternative at input 'CONSISTENCY' (..., 'Dan', 1437914728864) USING [CONSISTENCY]...)
com.datastax.driver.core.exceptions.SyntaxError: line 1:157 no viable alternative at input 'CONSISTENCY' (..., 'Dan', 1437914728864) USING [CONSISTENCY]...)

I have checked the csqlsh and the namespace has been created but no table has been created.

Any help much appreciated.

Here is the build.sbt in case it is useful:

name := "Something"

organization := "danmisun.github.com"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.2"

crossScalaVersions := Seq("2.10.4", "2.11.2")

val PhantomVersion = "1.10.1"

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "2.2.1" % "test",
  "org.scalacheck" %% "scalacheck" % "1.11.5" % "test",
  "com.websudos" % "phantom_2.11" % PhantomVersion,
  "com.websudos" % "phantom-dsl_2.11" % PhantomVersion,
  "com.websudos" % "phantom-testkit_2.11" % PhantomVersion % "test,   provided"
)

resolvers ++= Seq(
  "Typesafe repository snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
  "Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
  "Sonatype repo"                    at "https://oss.sonatype.org/content/groups/scala-tools/",
  "Sonatype releases"                at "https://oss.sonatype.org/content/repositories/releases",
  "Sonatype snapshots"               at "https://oss.sonatype.org/content/repositories/snapshots",
  "Sonatype staging"                 at "http://oss.sonatype.org/content/repositories/staging",
  "Java.net Maven2 Repository"       at "http://download.java.net/maven/2/",
  "Twitter Repository"               at "http://maven.twttr.com",
  Resolver.bintrayRepo("websudos", "oss-releases")
)

initialCommands := "import something._"
2
The query level consistency level has been removed in more recent versions of the CQL protocol(3.1+) but I wrote that blog post quite a while ago, so it's a bit outdated. Simply remove the consistency level definition and everything should return to normal. Now you have to specify consistency with USE CONSISTENCY bla and then run queries, in the past every query could specify a custom level. - flavian
Support for consistency levels has been re-added in phantom 1.12.x releases. It's a big internal change which now specifies consistency levels at protocol level instead of query level. - flavian
@flavian is there an example on how to setup the consistency level at protocol level as you said? - Thiago Pereira
Hi @ThiagoPereira there is no change with respect to how you achieve this at DSL level, the change is internal to how the underlying session will specify the consistency level at query time. One problem we've seen is that Cassandra advertises all Protocol.V3 versions of Cassandra will do this properly, however not all of them do, so some Cassandra versions incorrectly claim to support versions they don't or the exclusion logic may not be good enough. - flavian
Hi @flavian yeah, I have updated my test project on github, if you can, take a look on that please, but anyway, I'm setting consistency level from statement, the old style consistency level directly from inserts give an error complaining about no viable alternative for that. I'm using cassandra 2.2 and statement seems to work fine running with the 1.16 phantom-dsl version. - Thiago Pereira

2 Answers

1
votes

What does Users.store return? If it's returning Future[ResultSet], then wait for the future to complete. Try putting the await and check.

import scala.concurrent.{ Await, Future }
import scala.concurrent.duration.Duration

val resultSetFuture = Users.store(user)
Await.result(resultSetFuture, Duration.Inf) 
1
votes

First you need to create table: (comment after first run or you will receive "table already exists exception :P)

Await.result(Users.create.future(), 5000 millis)

Then remove .consistencyLevel_=(ConsistencyLevel.ALL) as phantom library seems to be very behind changes in cassandra which say that ConsistencyLevel is now defined per session not per request.

Now that should work but this library doesn't look too promising I would say.