我正在尝试使用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)
我真的不明白我错过了什么。
答案 0 :(得分:2)
默认情况下,列名称不区分大小写,除非用双引号将它们括起来。
定义列时,不要使用引号,因此它被称为// Get weather data from Weather Underground every 3 minutes (due to daily 500 calls per day limit)
// define variables as false
var temp = false;
var cond = false;
var initiated = false;
function getCurrentWeather() {
wunder.conditions('', function (err, data) {
if (err) throw err;
temp = data.temp_c;
cond = data.weather;
// variables are now set so you can continue with rest of application
if(!initiated){
initiated = true;
initiateApplication();
}
});
};
getCurrentWeather();
setInterval(getCurrentWeather, 180000);
};
:
dayofyear
但是在您的主键定义中,您使用了引号,因此它正在寻找名为+"dayOfYear int , "
的列:
dayOfYear
在任何地方或任何地方都使用引号(取决于区分大小写是否重要)。