缺少EOF会话使用datastax驱动程序执行cql查询

时间:2016-08-25 17:19:56

标签: cassandra datastax datastax-java-driver

我正在运行Java datastax驱动程序来执行cql查询以在一个查询中一起创建模式和表。并接收EOF例外如下。

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 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)

1 个答案:

答案 0 :(得分:1)

您需要将两个语句分隔为对session.execute的不同调用。

设计本机协议的方式,每个请求执行对应一个语句。有批处理执行请求可以包含多个语句,但我不确定它是否与schema DDL有很大关系。驱动程序实际上有一些在每次模式更改后发生的模式协议轮询,以确保在请求完成后对任何主机上的新元素的引用成功。