Data types in Deephaven

For performance reasons, the Deephaven engine is implemented in Java. As such, Deephaven tables use Java data types for columns, both Java primitive types and Java objects. This guide describes the primitive, object, and array types that table columns hold, then shows how to make sure a column gets the type you want with a type cast.

Java data types

Primitive types

Java primitive types map directly to hardware representations and have fixed sizes. Deephaven stores primitive values directly rather than as objects, so they are faster and use less memory. That speed and memory saving is the main reason to use them for table columns.

The following table shows the mapping between Java primitive types and Java primitive type sizes:

Java primitive typeJava primitive type size
byte1 byte
short2 bytes
int4 bytes
long8 bytes
float4 bytes
double8 bytes
char2 bytes

Deephaven tables have no primitive boolean column type. A formula that returns a boolean produces a java.lang.Boolean column instead, and Deephaven stores each value in one byte.

A Groovy variable used in a query string produces a column of its value's type, and boxed numbers such as Integer and Double become int and double columns. Groovy decimal literals such as 3.14 are java.math.BigDecimal, so they produce BigDecimal columns unless you cast them or add a d suffix (3.14d). Groovy variables in query strings shows both cases.

Object types

Object types are Java classes whose values are objects rather than raw values. They consume more memory and are generally slower than their primitive counterparts.

Some object types are commonly used in tables despite the overhead:

When Deephaven can't tell what type a formula returns, such as a closure call, the column becomes a java.lang.Object column. Data type conversions shows an example and how to fix it with a type cast.

Array types

Deephaven tables commonly hold two kinds of array column:

Arrays vs vectors compares the two.

Data type conversions

To make sure a column computed by a Groovy closure gets the type you want, use a type cast. The following code block casts one call to the closure and leaves the other uncast, for comparison:

In sourceMeta, Typecast is a double column, while NoTypecast is a java.lang.Object column because the engine can't infer the closure's return type.