我在KDB中运行以下查询来创建表格结构并在其中插入数据: -
n:1000000;item:`apple`banana`orange`pear;city:`beijing`chicago`london`paris;tab:([]time:asc n?0D0;n?item;amount:n?100;n?city);
发布哪个,我运行了一个Java程序来进行带聚合的选择查询。代码如下: -
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.logging.Level;
import java.util.logging.Logger;
import kx.c;
public class Aggregate {
public static class KxTableModel {
private c.Flip flip;
public void setFlip(c.Flip data) {
this.flip = data;
}
public int getRowCount() {
return Array.getLength(flip.y[0]);
}
public int getColumnCount() {
return flip.y.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return c.at(flip.y[columnIndex], rowIndex);
}
public String getColumnName(int columnIndex) {
return flip.x[columnIndex];
}
};
public static void main(String[] args) {
KxTableModel model = new KxTableModel();
c c = null;
try {
c = new c("localhost", 5001,":");
String query="select sum amount by city from tab";
// String query="0!select last price by sym from trade where date=last date";
model.setFlip((c.Flip) c.k(query));
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (c != null) {try{c.close();} catch (IOException ex) {}
}
}
System.out.println(model.getRowCount());
System.out.println(model.getValueAt(1, 1));
}
}
上面的代码在执行后给了我以下错误: -
Apr 14, 2016 9:30:10 AM Aggregate main
SEVERE: null
java.lang.ClassCastException: kx.c$Dict cannot be cast to kx.c$Flip
at Aggregate.main(Aggregate.java:40)
Exception in thread "main" java.lang.NullPointerException
at Aggregate$KxTableModel.getRowCount(Aggregate.java:17)
at Aggregate.main(Aggregate.java:47)
答案 0 :(得分:4)
您的查询返回一个键控表(因为by city
)
您现在可以在选择取消密钥表之前处理c.Dict
或插入0!
。
0!select sum amount by city from tab
答案 1 :(得分:0)
我遇到相同的错误,当我检查连接详细信息时,发现我正在查询错误的服务器。确保您连接到正确的服务器。