Skip to main content

Tables (Collections)

A table is a stored version of an stream or a table of events. Its schema is defined in the table definition that is similar to a stream definition. These events are stored in database. In Macrometa GDN, tables are called collections.


If you want to use an existing Macrometa collection as a store, then you must define it in the stream worker.


Tables allow the stream worker to work with stored events. By defining a schema for tables, the stream processor enables them to be processed by queries using their defined attributes with the streaming data. You can also query the state of the stored events in the table.

Any table defined in a stream worker is automatically a store for that stream worker. Tables can be stores or sinks.

You can query table contents using Table Operators.

You can speed up reference time by creating one or more Table Indexes.


There are several ways to define tables.


The syntax for a new table definition is as follows:

CREATE TABLE (GLOBAL|LOCAL)? <table_name> (<attribute_name> <attribute_type>, ...);

For example, this statement creates a global collection:

CREATE TABLE SensorTable (sensorId string, temperature double);


The CREATE TABLE AS SELECT statement creates a new table by selecting data from an existing stream and applying filters or transformations. The new table can be used for persistent storage, querying, and analysis.

The syntax for CREATE TABLE AS SELECT is as follows:

CREATE TABLE <table_name> (<attribute_name> <attribute_type>, ...)
[WITH ( property_name = expression [, ...] )]
AS SELECT select_expr [, ...]
FROM from_stream … ;


You can also use general store syntax:

CREATE STORE (GLOBAL|LOCAL)? <table_name> WITH(type="database", propKey=”propVal”,)(<attribute_name> <attribute_type>, ...);

For example, this statement creates a global collection:

CREATE STORE SensorTable WITH(type=database, collection=’SampleTable’, map.type=’json’) (sensorId string, temperature double);


The following parameters are configured in a table definition:

table nameThe name of the table defined. (PascalCase is used for table name as a convention.)
GLOBAL or LOCALWhether the table is globally or locally replicated. Default is GLOBAL.
attribute nameThe schema of the table is defined by its attributes with uniquely identifiable attribute names (camelCase is used for attribute names as a convention.)
attribute typeThe type of each attribute defined in the schema. This can be STRING, INT, LONG, DOUBLE, FLOAT, BOOL, or OBJECT.
fromIf collection.type is specified as edge, this field indicates which field to be considered as a source node of the edge.
toIf collection.type is specified as edge, this field indicates which field to be considered as a destination node of the edge.
[WITH (property_name = expression [, ...])]Optional properties for the new table, such as a time-to-live or a partition key.
SELECT select_expr [, ...]The selection criteria for the new table.
FROM from_stream …The name of the existing stream to select data from.

Example 1

The following defines a local table named RoomTypeTable with roomNo and type attributes of data types int and string respectively.

CREATE TABLE RoomTypeTable (roomNo int, type string);

Example 2

The following defines a global table named SweetProductionCollection with name and amount attributes of data types string and double.

CREATE TABLE GLOBAL SweetProductionCollection (name string, amount double);

Example 3

CREATE TABLE StockTable (symbol string, price float, volume long)
AS SELECT symbol, price, volume
FROM InputStream[price > 500] WINDOW SLIDING_LENGTH(1);

In this example, StockTable is created with three attributes: symbol, price, and volume. The new table is created by selecting data from InputStream, where the price is greater than 500, and applying a SLIDING_LENGTH window with a length of 1. The resulting table will contain only those tuples from InputStream where the price is greater than 500, and will have the attributes symbol, price, and volume.