Example for regular data: Create and load a regular time series
This example shows how to create a TimeSeries data type, create a time series table, create a regular time series by running the TSCreate function, and load data into the time series through the HCL Informix® TimeSeries Plug-in for Data Studio.
Prerequisites:
- IBM® Data Studio or IBM Optim™ Development Studio must be running and the Informix TimeSeries Plug-in for Data Studio must be installed. Data Studio can be installed on a different computer than the database server.
- The stores_demo database must exist. You create the stores_demo database by running the dbaccessdemo command.
In this example, you create a time series that contains electricity
meter readings. Readings are taken every 15 minutes. The table and TimeSeries data
type you create are similar to the examples in the ts_data table
in the stores_demo database. The following table lists the
time series properties used in this example.
Time series property | Definition |
---|---|
Timepoint size | 15 minutes |
When timepoints are valid | Every 15 minutes with no invalid times |
Data in the time series | The following data:
|
Time series table | The following columns:
|
Origin | All meter IDs have an origin of 2010-11-10 00:00:00.00000 |
Regularity | Regular |
Metadata | No metadata |
Amount of storage space | Approximately 1 MB (8640 timepoints for each of the 28 rows) |
Where to store the data | In an automatically created container in the same dbspace as the stores_demo database, which is in the root dbspace by default |
How to load the data | The TimeSeries plug-in |
How to access the data | A virtual table |
Creating a TimeSeries data type and table
You create a TimeSeries data type with columns for
the timestamp and the electricity usage value. Then you create a table
that has primary key column for the meter ID and a TimeSeries column.
To create the TimeSeries data type and table:
Creating regular, empty time series
You need to define the properties of the time series for
each meter ID by loading the meter IDs into the time series table
and creating a regular, empty time series for each meter ID. You use
the meter IDs from the ts_data table in the stores_demo database
to populate the meter_id column of your my_ts_data table.
To create regular, empty time series:
Creating the data load file
You create a time series data load file by creating a virtual
table based on the ts_data table and then unloading some of
the columns.
To create the data load file:
Loading the time series data
You use the TimeSeries plug-in to
load the data from the my_meter_data.unl file
into the my_ts_data table. The TimeSeries plug-in has
a cheat sheet that you use to guide you through the process of loading
the data.
To load time series data:
Accessing time series data through a virtual table
You create a virtual table to view the time series data in
relational data format.
To create a virtual table based on the time series table:
Use the TSCreateVirtualTab procedure
to create a virtual table named my_vt2 that is based on the my_ts_data table
by running the following SQL statement:
EXECUTE PROCEDURE TSCreateVirtualTab("my_vt2", "my_ts_data",
"calendar(ts_15min), origin(2010-11-10 00:00:00.00000)");
You can query the virtual table by running standard SQL statements.
For example, the following query returns the first value for each
of the 28 meter IDs:
SELECT * FROM my_vt2 WHERE timestamp = "2010-11-10 00:00:00.00000";