Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Yeshwanth Kumar
    @morpheyesh
    Is troy compatible with cql 3.4.4?
    Yeshwanth Kumar
    @morpheyesh
    i am getting a Failure during parsing the schema error. - Error ()' expected but (' found) near line 6, column 15
    @tabdulradi
    i am just trying it out.. using cql 3.4.4 and my schema is
    CREATE KEYSPACE platform WITH replication = {'class': 'SimpleStrategy' , 'replication_factor': '1'};
    
    
    CREATE TABLE platform.users (
      user_id text,
      first_name text,
      second_name text,
      PRIMARY KEY ((user_id), first_name)
    );
    Eman Shaaban
    @Eman-Shaaban
    @morpheyesh : https://github.com/schemasafe/troy/blob/master/README.md
    Troy targets (but not fully implements) CQL v3.4.3
    Yeshwanth Kumar
    @morpheyesh
    Yeah, I did see that. ok, thanks :) @Eman-Shaaban
    Tamer Abdulradi
    @tabdulradi
    It might be the "replication" section not parsed correctly. Try removing it, if not please create an issue report.
    Krunoslav Uzelac
    @Reeebuuk
    @tabdulradi cannot dl 0.4.0 for scala 2.12
    have added a resolver
    is the artifact there?
    Tamer Abdulradi
    @tabdulradi
    We didn't build for 2.12 yet. Only 2.11 available.
    Krunoslav Uzelac
    @Reeebuuk
    nooooo :)
    Tamer Abdulradi
    @tabdulradi
    Haha sorry. I'd recommend you to publishLocal and report if you got any issues
    Please note that current code on master is changing. So if you watched any of my recent talks, you would find the code a little bit different.
    The recent code is on a branch (with a PR created), but not in a stable state at the moment
    Krunoslav Uzelac
    @Reeebuuk
    when will you have a stable release? ETA?
    Tamer Abdulradi
    @tabdulradi
    I don't have any dates now sorry. The project is lacking funding at the moment, so I am only working on my free time. Which is mostly researching in the toy-Troy project now.
    Krunoslav Uzelac
    @Reeebuuk
    keep up the good work :)
    Tamer Abdulradi
    @tabdulradi
    Cheers mate ;)
    Uros Nedic
    @urosn
    I would like to ask do you plan to add features like Scala Doobie lib has for SQL but here for CQL?
    Tamer Abdulradi
    @tabdulradi
    Not in Troy, because troy is specific to Cassandra. But I renamed the Github organisation form "cassandra-scala" to "schemasafe" to be able to create a new project for relational DBs as well.
    Uros Nedic
    @urosn
    @tabdulradi I do not asked for relational but for Cassandra CQL. To get data from Cassandra into case classes, Options, Lists and so on
    Same what Doobe does in SQL troy to do in CQL.
    Tamer Abdulradi
    @tabdulradi
    This is supported already. Both in the current version and the upcoming as well.
    The current version you specify the Case class constructor, and the maco use it to instantiate the case class for you
    The upcoming feature I am using Shapeless to convert the Row to whatever case class that matches the Generic Repr
    Uros Nedic
    @urosn
    And something like this?
    scala> select(None, None, Nil, 10).check.unsafePerformIO // no filters
    
      SELECT name, code, population FROM country LIMIT ? 
    
      ✓ SQL Compiles and Typechecks
      ✓ P01 Long  →  BIGINT (int8)
      ✓ C01 name       VARCHAR (varchar) NOT NULL  →  String
      ✓ C02 code       CHAR    (bpchar)  NOT NULL  →  String
      ✓ C03 population INTEGER (int4)    NOT NULL  →  Int
    
    scala> select(Some("U%"), None, Nil, 10).check.unsafePerformIO // one filter
    
      SELECT name, code, population FROM country WHERE name LIKE ? LIMIT ? 
    
      ✓ SQL Compiles and Typechecks
      ✓ P01 String  →  VARCHAR (text)
      ✓ P02 Long    →  BIGINT  (int8)
      ✓ C01 name       VARCHAR (varchar) NOT NULL  →  String
      ✓ C02 code       CHAR    (bpchar)  NOT NULL  →  String
      ✓ C03 population INTEGER (int4)    NOT NULL  →  Int
    
    scala> select(Some("U%"), Some(12345), List("FRA", "GBR"), 10).check.unsafePerformIO // three filters
    
      SELECT name, code, population FROM country WHERE name LIKE ? AND population > ? AND code IN (?, ?) LIMIT ? 
    
      ✓ SQL Compiles and Typechecks
      ✓ P01 String  →  VARCHAR (text)
      ✓ P02 IntINTEGER (int4)
      ✓ P03 String  →  CHAR    (bpchar)
      ✓ P04 String  →  CHAR    (bpchar)
      ✓ P05 Long    →  BIGINT  (int8)
      ✓ C01 name       VARCHAR (varchar) NOT NULL  →  String
      ✓ C02 code       CHAR    (bpchar)  NOT NULL  →  String
      ✓ C03 population INTEGER (int4)    NOT NULL  →  Int
    It is about typechecking queries. Another example:
    scala> biggerThan(0).check.unsafePerformIO
    
        select code, name, population, gnp, indepyear
        from country
        where population > ?
    
      ✓ SQL Compiles and Typechecks
      ✕ P01 ShortINTEGER (int4)
        - Short is not coercible to INTEGER (int4) according to the JDBC specification.
          Fix this by changing the schema type to SMALLINT, or the Scala type to Int or
          JdbcType.
      ✕ C01 code       CHAR     (bpchar)  NOT NULL  →  Int
        - CHAR (bpchar) is ostensibly coercible to Int according to the JDBC specification
          but is not a recommended target type. Fix this by changing the schema type to
          INTEGER; or the Scala type to Code or String.
      ✓ C02 name       VARCHAR  (varchar) NOT NULL  →  String
      ✓ C03 population INTEGER  (int4)    NOT NULL  →  Int
      ✕ C04 gnp        NUMERIC  (numeric) NULL      →  Double
        - NUMERIC (numeric) is ostensibly coercible to Double according to the JDBC
          specification but is not a recommended target type. Fix this by changing the
          schema type to FLOAT or DOUBLE; or the Scala type to BigDecimal or BigDecimal.
        - Reading a NULL value into Double will result in a runtime failure. Fix this by
          making the schema type NOT NULL or by changing the Scala type to Option[Double]
      ✕ C05 indepyear  SMALLINT (int2)    NULL      →  
        - Column is unused. Remove it from the SELECT statement.
    Tamer Abdulradi
    @tabdulradi
    Can you paste how biggerThan is defined?
    Uros Nedic
    @urosn
    case class Country(code: String, name: String, pop: Int, gnp: Option[BigDecimal])
    
    def biggerThan(minPop: Int) = sql"""
      select code, name, population, gnp
      from country
      where population > $minPop
    """.query[Country]
    This is set-up:
    import doobie.imports._
    import cats._, cats.data._, cats.implicits._
    val xa = DriverManagerTransactor[IOLite](
      "org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
    )
    import xa.yolo._
    country table:
    CREATE TABLE country (
      code        character(3)  NOT NULL,
      name        text          NOT NULL,
      population  integer NOT NULL,
      gnp         numeric(10,2),
      indepyear   smallint
      -- more columns, but we won't use them here
    )
    Tamer Abdulradi
    @tabdulradi
    aha, I got it.
    Uros Nedic
    @urosn
    import xa.yolo._ is so-called YOLO mode - it makes life easier in REPL, do not need to do foreach(println(_)) and some other things for each statement.
    First paste of code is related to SQL fragments and it is defined here:
    // Import some convenience combinators.
    import Fragments.{ in, whereAndOpt }
    
    // Country Info
    case class Info(name: String, code: String, population: Int)
    
    // Construct a Query0 with some optional filter conditions and a configurable LIMIT.
    def select(name: Option[String], pop: Option[Int], codes: List[String], limit: Long) = {
    
      // Three Option[Fragment] filter conditions.
      val f1 = name.map(s => fr"name LIKE $s")
      val f2 = pop.map(n => fr"population > $n")
      val f3 = codes.toNel.map(cs => in(fr"code", cs))
    
      // Our final query
      val q: Fragment =
        fr"SELECT name, code, population FROM country" ++
        whereAndOpt(f1, f2, f3)                         ++
        fr"LIMIT $limit"
    
      // Consruct a Query0
      q.query[Info]
    
    }
    Tamer Abdulradi
    @tabdulradi
    I don't this we will be able to generate such detailed warning messages. Because Doobie's .check AFAIK is communicating to the database via macro.
    But Troy approach is different, all the validations are done by Scala typesystem.
    Uros Nedic
    @urosn
    Doobie doesn't use macros. Just JDBC
    Tamer Abdulradi
    @tabdulradi
    The .check does
    """The check logic requires both a database connection and concrete Meta instances that define column-level JDBC mappings. This could in principle happen at compile-time, but it’s not clear that this is what you always want and it’s potentially hairy to implement. So for now checking happens at unit-test time."""
    Uros Nedic
    @urosn
    I think Cassandra needs something like Dobbie lib.
    Tamer Abdulradi
    @tabdulradi
    Seems that I am wrong. So the warning messages is happening at runtime not compile time
    Troy generates them at compile time
    Try Quill if you want something working now. I've been told that it allows you to write raw queries
    Never tried/validated that though
    Uros Nedic
    @urosn
    I would like to prepare CQL queries as values (small programs).
    And compose them.
    Like in Doobie
    Tamer Abdulradi
    @tabdulradi
    This won't happen in Troy unfortunately. Queries must be literal strings. The philosophy here to make the code copy/paste friendly from/to the CQLSH
    so no composing / concatenation
    Don't forget that Cassandra's query is much stricter that relational dbs .. there is only few ways you can write the where statement. So something like composing where clauses at runtime could lead to an invalid query very easily