TableTools and TableManagement Tools

TableTools

Class com.illumon.iris.db.tables.utils.TableTools contains many methods for printing, loading, saving and modifying tables. All methods of TableTools are statically imported into each IrisDbGroovySession by default.

See also the TableTools JavaDocs

Some of those functions follow:

Viewing data

void show(Table source, ...)

Prints the first few rows of a table to standard output.

void showWithIndex(Table source, ...)

Prints the first few rows of a table to standard output, and also shows the details of the index used to retrieve the data.

String string(Table t, ...)

Returns the first few rows of a table as a pipe-delimited string.

String html(Table source)

Returns an entire table formatted as HTML. Note that this should only be used on small tables, as the whole string is built in memory.

CSV files

Table readCsv(...)

Loads a CSV file as an in-memory DB table. Column types are inferred from the data.

void writeCsv(Table t, ...)

Writes a DB table out as a CSV file.

Binary log files

Table readBin(...)

Loads a binary log file as an in-memory DB table. Requires access to the listener class that matches the file to be loaded.

Manually creating tables and columns

Table emptyTable(int size)

Creates an empty table with size rows.

Table emptyTable(int size, TableDefinition tableDefinition)

Creates an empty table with size rows, and column names and types from tableDefinition.

Table newTable(ColumnHolder... columns)

Creates a new table with the specified columns.

ColumnHolder<T> col(String name, T... values)

Creates a new data column.

Manually creating tables and columns

Users may want to create columns for a new table out of arrays. Two examples follow:

from deephaven import *  
# deephaven.TableTools module imported as as ttools

myTable1 = ttools.newTable(
    ttools.stringCol("StringColumn", "Str1", "Str2", "Str3", "Str4"),
    ttools.intCol("IntegerColumn", 1, 2, 4, 8),
    ttools.doubleCol("DoubleColumn", 1.0, 2.0, 4.0, 8.0),
    ttools.charCol("CharColumn", "A", "B", "C", "D"))
myTable2 = ttools.newTable(
    ttools.stringCol("StringColumn", ["Str1", "Str2", "Str3", "Str4"]),
    ttools.intCol("IntegerColumn", [1, 2, 4, 8]),
    ttools.doubleCol("DoubleColumn", [1.0, 2.0, 4.0, 8.0]),
    ttools.charCol("CharColumn", ["A", "B", "C", "D"]))
myStrings = ["Str1", "Str2", "Str3", "Str4"] as String[]
myInts = [1, 2, 4, 8] as int[]
myDoubles = [1.0, 2.0, 4.0, 8.0] as double[]
myCharacters = ['A', 'B', 'C', 'D'] as char[]

myTable = newTable(
        stringCol("StringColumn", myStrings),
        intCol("IntegerColumn", myInts),
        doubleCol("Decimals", myDoubles),
        charCol("Characters" , myCharacters)
)

Each line of the query specifies the data type for the column, its name, and the data for that column in the form of an array. In the Groovy script, each array is first assigned to a variable, which is then included in the query that generates the new table.

from deephaven import *

InMemoryTable = jpy.get_type("com.illumon.iris.db.v2.InMemoryTable")
columnNames = ["OrderType","OrderName"]
columnData = [ 
  jpy.array("byte",[0,1,2,3]), 
  jpy.array("java.lang.String",["Unknown","Market","Limit","Peg"]), 
]
orderTypeCodes = InMemoryTable(columnNames,columnData)
import com.illumon.iris.db.v2.InMemoryTable

Object columnData = new Object[2]
columnNames = ["OrderType","OrderName"] as String[]
columnData[0] = ['0','1','2','3'] as byte[]
columnData[1] = ["Unknown","Market","Limit","Peg"] as String[]
OrderTypeCodes = new InMemoryTable(columnNames, columnData)

More

Table merge(Table... tables)

Combines the tables into an aggregate table. The resulting table comprises the rows of each of the Input Tables, in the given order of the inputs. Null inputs are skipped.

String diff(Table actual, Table expected, int maxDiffLines)

Computes the difference of two tables for use in verification.

TableManagementTools

Class com.illumon.iris.db.tables.utils.TableManagementTools contains many methods for managing tables. The TableManagementTools class is not imported by default, and would need to be manually imported into the IrisDbGroovySession to access its methods.

See also the TableManagementTools JavaDocs

Some of those functions follow:

Simple binary files

Table readTable(Table t, ...)

Loads a DB binary table.

void writeTable(Table t, ...)

Saves a table to disk in DB binary format.

void deleteTable(Table t, ...)

Deletes a DB binary format table from disk.

Directory

List<File> getAllDbDirs(String tableName, File rootDir, int levelsDeep)

Gets all of the directories for an on-disk database.

Add column(s)

TableDefinition addColumns(...)

Adds a new column to a table definition.


Last Updated: 16 February 2021 18:07 -04:00 UTC    Deephaven v.1.20200928  (See other versions)

Deephaven Documentation     Copyright 2016-2020  Deephaven Data Labs, LLC     All Rights Reserved