[ Lorcan Coyle ]
> Are there any plans for a goal for running a CQL-based load scripts, along
> the lines of the cassandra:load goal for CLI scripts? The Cassandra
> community is pushing users away from CLI and towards CQL. I think this
> feature could be a useful addition to the cassandra maven plugin.
>
> The cassandra:cql-exec goal is great for executing statements against a
> pre-existing keyspace but it cannot (after many hours trying*) create new
> keyspaces and populate them in the same way as the cassandra:load goal does
> with CLI scripts. I've hacked a workable solution, whereby I load CLI using
> cassandra:load and then follow up with cassandra:cql-exec to execute some
> `ALTER TABLE` cql statements to rename columns, etc. to make my column
> families / tables more cql-friendly.
TTBMK, it runs semilcolon deimited statements as-is, which should be all
you need; I've used it to create keyspaces and column families.
> I'll go ahead and add an issue to the jira if there is any take on this
> suggestion. I'd be happy to help out on this if I can. If there's no
> traction, I'll stick with my hack...
On a somewhat unrelated note, I banged together a patch that updates
support to CQL 3. It's attached to this email, but if I can figure out
how to submit a Jira issue, I'll attach it there as well.
> * cassandra:cql-exec executes all statements individually and in isolation,
> so a 'use <keyspace>;' statement doesn't stick. Also, it doesn't like empty
> lines or lines with comments (due to the way it splits the input by
> semi-colon). For running statements in isolation, against a preexisting
> keyspace it does the job.
Yeah, you should fully qualify your tables, i.e.:
CREATE TABLE <keyspace>.<table> (id int PRIMARY KEY);
--
Eric Evans
[email protected]
Index: src/main/java/org/codehaus/mojo/cassandra/CqlExecCassandraMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/cassandra/CqlExecCassandraMojo.java (revision 18746)
+++ src/main/java/org/codehaus/mojo/cassandra/CqlExecCassandraMojo.java (working copy)
@@ -17,9 +17,11 @@
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.Compression;
+import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.CqlResult;
import org.apache.cassandra.thrift.CqlRow;
import org.apache.cassandra.thrift.Cassandra.Client;
+import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
@@ -124,6 +126,11 @@
{
for (String op : StringUtils.split(cqlStatement, ";"))
{
+ // Skip empty statements
+ if (op.trim().equals(""))
+ continue;
+
+ getLog().debug("Executing CQL Statement: "+op);
cqlOps.add(doExec(op));
}
} else
@@ -198,8 +205,11 @@
{
try
{
- result = client.execute_cql_query(statementBuf, Compression.NONE);
+ result = client.execute_cql3_query(statementBuf, Compression.NONE, ConsistencyLevel.ONE);
rowIter = result.getRowsIterator();
+ } catch (InvalidRequestException ire) {
+ getLog().error("Invalid request: "+ire.getWhy());
+ throw new ThriftApiExecutionException(ire);
} catch (Exception e)
{
throw new ThriftApiExecutionException(e);
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email