Created
July 27, 2017 16:40
-
-
Save fedefernandez/f5e3932451dc416239c7c9265ae6cf84 to your computer and use it in GitHub Desktop.
Troy sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import troy.cql.ast._ | |
import troy.schema._ | |
val sql = | |
""" | |
CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy' , 'replication_factor': '1'}; | |
CREATE TABLE test.posts ( | |
author_id text, | |
post_id timeuuid, | |
post_title text, | |
PRIMARY KEY ((author_id), post_id) | |
);""" | |
val dataDefinition = CqlParser.parseSchema(sql) | |
val schemaEngine = SchemaEngine(dataDefinition.get) match { | |
case V.Success(res, _) => res | |
case _ => throw new RuntimeException("") | |
} | |
schemaEngine(CqlParser.parseDML("SELECT * FROM test2.posts").get) | |
// res5: Result[(SchemaEngine.RowType, SchemaEngine.VariableTypes)] = Error(List(KeyspaceNotFound(KeyspaceName("test2"))), List()) | |
schemaEngine(CqlParser.parseDML("SELECT author_id FROM test.posts").get) | |
// res6: Result[(SchemaEngine.RowType, SchemaEngine.VariableTypes)] = Success((Columns(List(Text)), List()), List()) | |
schemaEngine(CqlParser.parseDML("SELECT name FROM test.posts").get) | |
// res7: Result[(SchemaEngine.RowType, SchemaEngine.VariableTypes)] = Error(List(ColumnNotFound("name", TableName(Some(KeyspaceName("test")), "posts"))), List()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
COURSIER_URL=https://raw.githubusercontent.com/alexarchambault/coursier/v1.0.0-M15/coursier | |
test -e ~/.coursier/coursier || \ | |
(mkdir -p ~/.coursier && curl -s --output ~/.coursier/coursier $COURSIER_URL && chmod +x ~/.coursier/coursier) | |
~/.coursier/coursier launch -q -P \ | |
-r bintray:tabdulradi/maven \ | |
com.lihaoyi:ammonite_2.12.2:1.0.0 \ | |
io.github.cassandra-scala:cql-ast_2.12:0.4.0 \ | |
io.github.cassandra-scala:cql-parser_2.12:0.4.0 \ | |
io.github.cassandra-scala:troy-schema_2.12:0.4.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment