Welcome to KDB+ (Q) documentation covering setup, operations, and integration examples for this high-performance time-series database.
Overview
KDB+ is a high-performance column-oriented database with a built-in expressive query and programming language called Q. It's particularly well-suited for financial time-series data and real-time analytics.
privatestaticvoidprintStocks(cc)throwsc.KException,IOException{// KDB+ query: select from stocks where time < .z.p, sorted by time descendingStringquery="xdesc[`time] select from stocks where time < .z.p";// Send query and receive resultObjectresult_kdb=c.k(query);Fliptable=(Flip)result_kdb;String[]columnNames=table.x;Object[]columnData=table.y;introwCount=Array.getLength(columnData[0]);for(inti=0;i<rowCount;i++){StringBuilderrow=newStringBuilder();for(intj=0;j<columnNames.length;j++){Objectcol=columnData[j];Objectvalue=Array.get(col,i);row.append(columnNames[j]).append("=").append(value).append(" ");}System.out.println(row.toString());}}
// Define stream schemastocks:([]time:`timestamp$();sym:`symbol$();price:`float$());// Load tick utilities\l tick/u.q.u.init[]// Memory management - keep only last minute of data.z.ts:{`stockssetselectfromstockswheretime>.z.p-00:01:00.000};\t1000// Execute every second
// Initialize tick publishing\l tick/u.q.u.init[]// Define update function for dashboards.u.upd:{[table;data]insert[table;flipdata];.u.pub[table;flipdata];}.u.snap:{stocks}// Publish updates every second\t1000.z.ts:{.u.pub[`stocks;.u.snap[`stocks]]}