schemasafe / troy

Type-safe and Schema-safe Scala wrapper for Cassandra driver
Apache License 2.0
151 stars 14 forks source link

Research how we can use Cassandra's source code to typecheck queries #144

Open tabdulradi opened 6 years ago

tabdulradi commented 6 years ago

The plan is to add Cassandra itself as a compile time dependency, where we call the Java code that is responsible to validate and type check the query (properly happens you prepare a statement).

The Java code will be called from a macro.

Note that the solution must NOT start Cassandra server, not even in memory.

The solutions should provide 2 methods that look something like this:

// Allow us to create Schema representation from schema.cql file
def createSchema(schemaDefinitionStatements: Seq[String]): Either[String, Schema]

// Allow us to know the signature of the query (how many selected rows, what are the types) how many bind markers, what are their types? 
def schemaCheck(schema: Schema, query: String): Either[String, QuerySignature]

These 2 function should call Cassandra's source code.

A proof of concept can be written in a seperate Gist/Repo.

Useful links: https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/schema/Schema.java https://github.com/apache/cassandra/blob/trunk/test/unit/org/apache/cassandra/cql3/CQLTester.java#L810