Varun Gupta
Varun Gupta

Reputation: 1457

missing EOF session execute cql query using datastax driver

I am running Java datastax driver to execute cql query to create schema and table(s) together in one query. And receiving EOF exception as below.

session.execute("CREATE KEYSPACE testkeyspace WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3' } AND DURABLE_WRITES = true;"+
            "CREATE TABLE testkeyspace.users (" +
            "    name text," +
            "    birth_year int," +
            "    gender text," +
            "    PRIMARY KEY (name)" +
            ") WITH read_repair_chance = 0.0" +
            "   AND dclocal_read_repair_chance = 0.1" +
            "   AND gc_grace_seconds = 864000" +
            "   AND bloom_filter_fp_chance = 0.01" +
            "   AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 'NONE' }" +
            "   AND comment = ''" +
            "   AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' }" +
            "   AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.LZ4Compressor' }" +
            "   AND default_time_to_live = 0" +
            "   AND speculative_retry = '99.0PERCENTILE'" +
            "   AND min_index_interval = 128" +
            "   AND max_index_interval = 2048;");

Exception Trace

Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:159 missing EOF at 'CREATE' (...} AND DURABLE_WRITES = true;[CREATE] TABLE...)
at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:58)
at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:24)
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:63)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:39)
at com.example.helloworld.HelloWorld.main(HelloWorld.java:58)
Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:159 missing EOF at 'CREATE' (...} AND DURABLE_WRITES = true;[CREATE] TABLE...)
at com.datastax.driver.core.Responses$Error.asException(Responses.java:132)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:184)
at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:798)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1005)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:928)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)

Upvotes: 0

Views: 2012

Answers (1)

Adam Holmberg
Adam Holmberg

Reputation: 7375

You need to separate the two statements into distinct calls to session.execute.

The way the native protocol is designed, each request execution corresponds to one statement. There are batch execution requests that can contain multiple statements, but I'm not sure it makes a lot of sense with schema DDL. The driver actually has some schema agreement polling that happens after each schema change, to make sure references to the new element succeed on any host after the request completes.

Upvotes: 1

Related Questions