Skip to content

KdbTable

Jas edited this page Mar 9, 2017 · 1 revision

KdbTable

This object is a replacement for c.Flip. The main features provided by this class are:

  • Conversion to and from c.Flip

    • new KdbTable(String, Flip) to create a new object from c.Flip
    • KdbTable.convertToFlip for conversion to a Flip ready for serialisation by c.java
  • Column-wise and row-wise addition of data

    • addColumn adds a new column, with existing column and column length checks
    • addRow adds a new row (as KdbDict or Map), ensuring the row has all required columns
  • Rows access as KdbDict

    • getRow returns the specific row
    • Custom iterator and stream functions to allow iterator via for loop and Java 8 streams

Iterator and Stream Examples

Iterating over each row with a for loop:

public void printRowsWithIterator(KdbTable table) {
    for(KdbDict row : table) {
         System.out.println(row.get("col1");
    }
}

Using Java 8 streams to count the occurrence of a particular sym:

public long getSymCount(KdbTable table, String sym) {
    return table.stream()
                        .filter((row) -> sym.equals(row.getAs("sym", String.class)))
                        .count();
}
Clone this wiki locally