Skip to main content
Version: Java (Groovy)

Access table meta data

This guide will show you how to use methods and attributes from Deephaven's Table class to access the meta data for your table.

A table's metadata provides basic information about its source data, such as the table type and size, whether the data is refreshing, and the data types of each column. You may want to confirm if a column is an int or a double, or check whether a column is a partitioning column or grouping column.

Get a metadata table with meta

The meta method creates a new table that contains the table's meta data. Specifically, this table contains information about every column in the original table.

result = source.meta()

This can be useful when you want to confirm which columns in a table are partitioning or grouping, or verify the data type of a column.

Let's create a table of weather data for Miami, Florida.

miami = newTable(
stringCol("Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),
intCol("Temp", 60, 62, 65, 68, 73, 76, 77, 77, 76, 74, 68, 63),
doubleCol("Rain", 1.62, 2.25, 3.00, 3.14, 5.34, 9.67, 6.50, 8.88, 9.86, 6.33, 3.27, 2.04),
)

We can access the meta data as follows:

meta = miami.meta()

Obviously, this is more useful for a table we are unfamiliar with, but as you can see, the meta table provides information about the column and data types.

Now, let's create a table of weather data for Miami over three dates in January, then averages the high and low temperatures by day.

miami = newTable(
stringCol("Day", "Jan 1", "Jan 1", "Jan 2", "Jan 2", "Jan 3", "Jan 3"),
intCol("Temp", 45, 62, 48, 63, 39, 59),
)

avgTemp = miami.avgBy("Day")

Although the Temp column is originally created as an int column, the Temp column in the avgBy table becomes a double column. We can see this by hovering over the column header in the UI, and also by accessing the table's metadata.

meta = avgTemp.meta()

Table Metadata Methods

The following methods can be used to access specific elements of a table's metadata:

getAttribute

Use the getAttribute method to get the value of a specific table attribute.

import io.deephaven.engine.table.impl.util.AppendOnlyArrayBackedInputTable
import io.deephaven.engine.table.AttributeMap

source = newTable(
doubleCol("Doubles", 3.1, 5.45, -1.0),
stringCol("Strings", "Creating", "New", "Tables")
)

result = AppendOnlyArrayBackedInputTable.make(source)
println result.getAttribute("AddOnly")

getAttributes

The getAttributes method returns all the attributes in the source table's AttributeMap. An optional included parameter allows you to specify which keys should be included in the result.

import java.util.function.Predicate

// include all attributes
println result.getAttributes()

// get attribute keys
println result.getAttributeKeys()

// include only the "AddOnly" attribute
println result.getAttributes(Predicate.isEqual("AddOnly"))

getAttributeKeys

getAttributeKeys returns an immutable set of all the source table's attributes that have values.

println result.getAttributeKeys()

getDefinition

Use the getDefinition method to get the source table's TableDefinition.

println result.getDefinition()

hasAttribute

The hasAttribute method returns True if the source table has the specified attribute, and False otherwise.

println result.hasAttribute("AddOnly")
println result.hasAttribute("NotAnAttribute")

hasColumns

The hasColumns method returns True if the source table has the specified columns, and False otherwise.

println result.hasColumns("Doubles")
println result.hasColumns("Doubles", "NotAColumn")

isEmpty

To see if a table is empty, use the isEmpty method. This method returns True if the table is empty, or False if it is not.

table = emptyTable(1)
println result.isEmpty()
println table.isEmpty()

isFlat

The isFlat method returns True if the source table is flat, and False otherwise.

println result.isFlat()

isFailed

The isFailed method returns True if the source table is in a failed state and False otherwise.

println result.isFailed()

isRefreshing

The isRefreshing method returns True if the source table is refreshing, and False otherwise.

println result.isRefreshing()

numColumns

The numColumns method returns the number of columns in the source table.

println result.numColumns()