Create static tables

Deephaven often reads table data from Parquet, Kafka, or other external sources, but it can also generate tables from scratch. Static tables hold fixed data that does not change after creation. This guide covers two simple methods for creating them: emptyTable and newTable. It shows how to use these methods to create static tables and columns, and how to add data to those tables. To create a table that updates in real time, see Create a time table, Write data to an in-memory, real-time table, Create and use input tables, and Replay data from static tables.

emptyTable

The emptyTable method takes a single argument — a long representing the number of rows in the new table. The resulting table has no columns and the specified number of rows. In the following example, we create a table with 10 rows and no columns:

Calling emptyTable on its own generates a table with no data. You can add columns and data with update or another selection method, either in the same line that creates the table or at any time afterward.

In the following example, we create a table with 10 rows and a single column X with values 0 through 9 by using the special variable i to represent the row index. Then, we update the table again to add a column Y with values equal to X squared:

The Create new columns in a table section shows more ways to add columns.

newTable

Deephaven's newTable method creates a new table that you populate with data. It accepts one or more ColumnHolder objects as arguments.

A ColumnHolder stores a column's name, type, and data. Column methods such as stringCol and intCol create them. The Column types section lists these methods.

The following query creates a new table with a String column and an int column:

Column types

The following methods create columns of common types:

Data typeMethod
BooleanbooleanCol
bytebyteCol
charcharCol
java.lang.Objectcol
doubledoubleCol
floatfloatCol
java.time.InstantinstantCol
intintCol
longlongCol
shortshortCol
StringstringCol

When you pass col individual values, it creates a java.lang.Object column. To create a column of a type not in this list, such as an array column, see Array columns.

Array columns

newTable can also create array columns, where each cell holds an array. Typed methods such as intCol and stringCol can't create these. Instead, pass col an array of arrays, with one inner array per row.

The following example creates a new table with a single int[] column that has two rows:

Create new columns in a table

Selection methods and formulas work together to create new columns. The selection methods are select, view, update, updateView, and lazyUpdate. Selection methods and formulas each have their own job:

  • The selection method determines which columns appear in the output table. It also determines whether their values are computed immediately and stored in memory, or computed on demand when they are read.
  • The formulas are the recipes for computing the cell values.

In the following example, we use a table of student test results. Using update, we create a new Total column containing the sum of each student's math, science, and art scores, and an Average column computed from Total.

A formula can use a column created by an earlier formula in the same call, as Average uses Total here. The output table also keeps every column from the source table.

select, by contrast, includes only the columns you list. The following example keeps the Name column and adds a Total column:

The formulas you pass to update and the other selection methods can use the full Deephaven Query Language (DQL), including mathematical operations, built-in functions, comparison and conditional operators, Java functions, and user-defined closures. In the following example, we create a table with 100 rows, then create four columns:

The following example creates a table with two integer columns. Then, it updates the table to add a new column X via a formula that uses a variable, a user-defined closure, an auto-imported Java function, and various operators:

For more about DQL, see the Query string overview and Select and create columns.