gpt4 book ai didi

java - 线程 "main"com.datastax.driver.core.exceptions.InvalidQueryException : Unknown definition referenced in PRIMARY KEY 中出现异常

转载 作者:行者123 更新时间:2023-11-30 03:22:19 27 4
gpt4 key购买 nike

我正在尝试使用 JAVA API 在 Cassandra 中创建表。

该查询运行良好并创建了表。

String query = "CREATE TABLE IF NOT EXISTS TopQuery1(term text , "
+"year text , "
+"month text , "
+"day text , "
+"hour text , "
+"count counter,"
+"PRIMARY KEY (\"term\", \"year\", \"month\", \"day\", \"hour\" ));";

但是当我执行以下查询时,它会抛出错误。

String query = "CREATE TABLE IF NOT EXISTS TopQuery2(term text , "
+"year text , "
+"month text , "
+"day text , "
+"hour text , "
+"dayOfYear int , "
+"weekOfYear int , "
+"ProductCount int , "
+"count counter,"
+"PRIMARY KEY (\"term\", \"year\", \"month\", \"day\", \"hour\", \"dayOfYear\", \"weekOfYear\", \"ProductCount\"));";

这是错误:

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Unknown definition dayOfYear referenced in PRIMARY KEY
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:289)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:205)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:36)
at CreateTable.main(CreateTable.java:81)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Unknown definition dayOfYear referenced in PRIMARY KEY
at com.datastax.driver.core.Responses$Error.asException(Responses.java:103)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:140)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:293)
at com.datastax.driver.core.RequestHandler.onSet(RequestHandler.java:455)
at com.datastax.driver.core.Connection$Dispatcher.messageReceived(Connection.java:734)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.handler.timeout.IdleStateAwareChannelUpstreamHandler.handleUpstream(IdleStateAwareChannelUpstreamHandler.java:36)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.timeout.IdleStateHandler.messageReceived(IdleStateHandler.java:294)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

我真的不明白我错过了什么。

最佳答案

默认情况下,列名称不区分大小写,除非您将它们用双引号引起来。

当您定义列时,您不使用引号,因此它被称为dayofyear:

+"dayOfYear int , "

但是在主键定义中使用引号,因此它正在查找名为 dayOfYear 的列:

+"PRIMARY KEY (... \"dayOfYear\" ...)";

要么到处使用引号,要么不使用引号(取决于区分大小写是否重要)。

关于java - 线程 "main"com.datastax.driver.core.exceptions.InvalidQueryException : Unknown definition referenced in PRIMARY KEY 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31049209/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com