Skip to main content
Version: Python

How to 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.

meta_table

The meta_table attribute 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_table

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.

from deephaven import new_table
from deephaven.column import string_col, int_col, double_col

miami = new_table(
[
string_col(
"Month",
[
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
],
),
int_col("Temp", [60, 62, 65, 68, 73, 76, 77, 77, 76, 74, 68, 63]),
double_col(
"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_table

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.

from deephaven import new_table

from deephaven.column import string_col, int_col

miami = new_table(
[
string_col("Day", ["Jan 1", "Jan 1", "Jan 2", "Jan 2", "Jan 3", "Jan 3"]),
int_col("Temp", [45, 62, 48, 63, 39, 59]),
]
)

avg_temp = miami.avg_by(by=["Day"])

Although the Temp column is originally created as an int column, the Temp column in the avg_by 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 = avg_temp.meta_table

attributes

The attributes method returns all of a Table's defined attributes.

print(miami.attributes())

has_columns

Use has_columns to check whether a table contains a column (or columns) with the provided column name(s). It will return True if all columns are in the table, or False if any of the provided column names are not found in the table.

print(miami.has_columns("Month"))
print(miami.has_columns(["Month", "NotAColumnName"]))

to_string

Use to_string return the first n rows of a table as a pipe-delimited string.

source.to_string(
num_rows: int = 10,
cols: Union[str, Sequence[str]] = None
) -> str
  • num_rows is the number of rows from the beginning of the table to return. The default is 10.
  • cols is the column name(s) to include in the string. The default is None, which includes all columns.
print(miami.to_string(4))

Attributes

The following attributes do not take arguments, but will print metadata information in the console.

columns

For a full list of a Table's column definitions, use columns:

print(miami.columns)

To see whether or not a Table is a blink table, use is_blink:

print(miami.is_blink)

is_flat

To see whether or not a Table is flat, use is_flat:

print(miami.is_flat)

is_refreshing

To see whether or not a Table is refreshing, use is_refreshing:

print(miami.is_refreshing)

size

To see the number of rows in a Table, use size:

print(miami.size)

update_graph

To get the source Table's update graph, use update_graph:

print(miami.update_graph)