gpt4 book ai didi

java - KDB : Inappropriate type casting for aggregation query result

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:35 24 4
gpt4 key购买 nike

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

最佳答案

您的查询返回一个键控表(因为 by city)您现在可以处理 c.Dict 或在选择之前插入 0! 以取消对表的键控。

0!从选项卡中按城市选择总金额

关于java - KDB : Inappropriate type casting for aggregation query result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36613690/

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