我對KDB不太好(如果問題聽起來很愚蠢)。我正在嘗試使用kdb(磁盤不是內存)從數據庫加載所有數據。我已經問upserts的問題,我想通了如何從控制檯UPSERT並保存到磁盤使用qJava寫入KDB
q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)`dsPricing insert(123;2003.03.23;1.0;3.0;4.0;2.0;1000)
q)`dsPricing insert(123;2003.03.24;1.0;3.0;4.0;2.0;2000)
q)save `:dsPricing
q)`:dsPricing upsert(123;2003.03.25;1.0;3.0;4.0;2.0;1500)
現在我試圖做到這一點在Java中,並具有以下代碼
public class LoadDS {
SqlSession session;
private DataStreamMapper mapper ;
public static void main(String args[]){
final QConnection q = new QBasicConnection(args.length >= 1 ? args[0] : "localhost", args.length >= 2 ? Integer.parseInt(args[1]) : 5001, "user",
"pwd");
LoadDS l=new LoadDS();
l.session = MyBatisConnectionFactory.getSqlSessionFactory("SMALLS").openSession();
l.mapper = l.session.getMapper(DataStreamMapper.class);
List<DataStream> prices = l.mapper.selectHistoricalPrices(1);
try {
q.open();
q.sync("upsert", "'dsPricing", l.getData(prices));
} catch (QException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
private Object[] getData(List<DataStream> prices) {
final Object[] data = new Object[] {new int[prices.size()], new QDate[prices.size()],
new float[prices.size()], new float[prices.size()],
new float[prices.size()],new float[prices.size()],
new int[prices.size()]
};
for (int i = 0; i < prices.size(); i++) {
((int[]) data[0])[i] = prices.get(i).getInfoCode();
((QDate[]) data[1])[i] = new QDate(prices.get(i).getMarketDate());
((float[]) data[2])[i] = (float)prices.get(i).getOpen_();
((float[]) data[3])[i] = (float)prices.get(i).getClose_();
((float[]) data[4])[i] = (float)prices.get(i).getHigh();
((float[]) data[5])[i] = (float)prices.get(i).getLow();
((int[]) data[6])[i] = (int)prices.get(i).getVolume();
}
return data;
}
}
誰能告訴我我做錯了什麼?數據沒有得到保存,我嘗試了多種變化。我寧願只從SQL加載數據並將其保存到磁盤以進行初始加載。
您是否嘗試過使用消息處理程序向KDB一旁看到這是怎麼回事?在kdb端設置.z.po:{show「connected」},這樣你就可以確定你已經連接了。在kdb一側設置.z.pg:{0N!x}以準確查看您發送的內容 – terrylynch 2014-09-11 12:40:10
您是否確實意指''dsPricing'中的''而不是'\'(很難看到這個字體中的不同,意味着反擊與反轉!) – 2014-09-16 14:33:18