The TimeSeries model is designed for time series data, making it ideal for scenarios such as Internet of Things (IoT) device monitoring, device data collection, and machine monitoring. It provides high-concurrency writes and queries, and offers low-cost storage for petabytes of data. This topic shows you how to use the TimeSeries model in the Tablestore console.
To use the TimeSeries model with a command-line tool, see Use the TimeSeries model with a command-line tool.
Notes
The TimeSeries model is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Ulanqab), China (Shenzhen), China (Chengdu), China (Hong Kong), Japan (Tokyo), Malaysia (Kuala Lumpur), Germany (Frankfurt), Indonesia (Jakarta), UK (London), US (Silicon Valley), US (Virginia), SAU (Riyadh - Partner Region), and Singapore.
Features such as Lastpoint index, time series analytics storage, custom time series identifiers, and data fields as primary keys are available only in the China (Hangzhou), China (Shanghai), China (Beijing), and China (Zhangjiakou) regions. To use these features, create your instance in one of these regions.
Prerequisites
You have activated the Tablestore service. For more information, see Activate Tablestore.
A TimeSeries model instance has been created.
Log on to the Tablestore console.
In the top navigation bar, select a resource group and a region.
On the Overview page, click Create Instance for TimeSeries Model.
In the Create Instance for TimeSeries Model dialog box, select an instance specification, enter an instance name, and add an instance description.
Click OK.
Procedure
Step 1: Create a time series table
Create a time series table to store time series data.
For information about the sample scenario and table schema, see Sample scenario.
Go to the Instance Management page.
Log on to the Tablestore console.
In the top navigation bar, select a resource group and a region.
On the Overview page, click the instance name or click Manage Instance in the Actions column of the instance.
On the Instance Details tab, click the Time Series Tables tab.
On the Time Series Tables tab, click Create Time Series Table.
NoteYou can also click Generate Demo with One Click to create a sample table with sample data to quickly try out the features. It may take a few seconds for a new time series to appear as the system initializes the sample table.
In the Create Time Series Table dialog box, set Time Series Table Name to car_example and keep the default settings for other parameters.
Click Create.
After the time series table is created, you can view the table on the Time Series Tables tab. If the new table does not appear in the list, click the
icon to refresh the time series table list.
Step 2: Write data
Write data to the time series table. Time series data consists of metadata and data points. If you do not create metadata beforehand, the system automatically extracts it from the data you write.
On the Time Series Tables tab, click the time series table name and then click the Query Data tab. Alternatively, click Manage Data in the Actions column of the time series table.
(Optional) Create a time series.
On the Query Data tab, click Add Time Series.
In the Add Time Series dialog box, add metadata for the time series, such as the metric name and data source.
In this example, set Metric Name to
car_tsdata, select a Data Source, and in the Tag section, add a filter condition where the key iscar_model, the operator is=, and the value ismodel_A. Then, click Add.Click Add.
Insert data.
In the Actions column of the time series that you want to manage, click Query Data.
Click Insert Data.
The system automatically obtains the metadata of the selected time series.
In the Insert Data dialog box, set the time and attribute columns.
Set the metric name to
car_tsdata. Add a tag whose key iscar_modeland value ismodel_A. Set the time toFebruary 5, 2025, 00:00:00. The required attribute columns include:vin_id(string),model(string, valuemodel_A),speed(double, value75.90),gps(string, value30.23,52.78),current_mileage(double, value10),remaining_oil(double, value20),available_mileage(double, value198), andtire_pressure(double, value2.4). After you configure the parameters, click OK.Click OK.
Step 3: Query time series data
Query data from a time series within a specified time range.
To query data in a table by using SQL, see Query time series data by using SQL.
If you are not sure about the information of the time series to query, you can retrieve time series by specifying multiple conditions. For more information, see Retrieve time series.
On the Query Data tab of the time series table, find the time series that you want to query and click Query Data in the Actions column.
Set query conditions.
By default, query results are sorted in ascending order of time. To query data in descending order, set Reverse Chronological Order to Yes.
Select a query method and specify a time range.
Click Query.
Data that meets the query conditions is displayed on the Query Data tab. The query results can be displayed in a list or a chart.
Use a Lastpoint index
A Lastpoint index allows you to quickly retrieve the latest data point for each time series in a time series table.
Go to the Instance Management page.
Log on to the Tablestore console.
In the top navigation bar, select a resource group and a region.
On the Overview page, click the instance name or click Manage Instance in the Actions column of the instance.
Go to the management page of the time series table.
On the Instance Details tab, click the Time Series Tables tab.
On the Time Series Tables tab, click the name of the time series table.
Create a Lastpoint index.
On the Basic Information tab of the management page of the time series table, click Create Lastpoint Index.
In the Create Lastpoint Index dialog box, set the Lastpoint index name and synchronization mode.
For example, set Lastpoint Index Name to
lastpoint_car_example, set Synchronization Mode to Full Synchronization, and then click Create.Click Create.
Query data by using the Lastpoint index.
In the Actions column of the Lastpoint index, click Query.
In the Search dialog box, set Mode to Range Search and keep the default settings for other parameters.
By default, the start primary key values for _#h, _m_name, _data_source, and _tags are set to the minimum, and the end primary key values are set to the maximum.
Click Query.
The data that meets the query conditions is displayed in the Lastpoint Index section on the Basic Information tab.
Retrieve time series
If you are unsure of the exact metric name or data source for a time series, you can search for it by specifying multiple conditions.
On the Query Data tab of the time series table, click Query Time Series in the upper-right corner.
In the Query Data dialog box, enter the metric name or data source of the time series, and then click Add to specify matching conditions for tags, attributes, or update time.
The condition in this example is used to query all time series that contain the tag
car_model=model_A.Click OK.
The data that meets the query conditions is displayed on the Query Data tab.
Sample scenario
In an Internet of Vehicles (IoV) scenario, vehicles use sensors to report time series data to the cloud. Storing, querying, and analyzing this data enables business features such as vehicle status reports, vehicle locating, traffic management, and trajectory projection. This topic uses a time series table in an IoV scenario as an example to describe how to create a time series table and perform read and write operations. The time series table stores vehicle trajectory data.
Parameter | Type | Description |
_m_name | String | The name of the metric, which indicates the physical quantity or monitoring metric measured by the time series data. |
_data_source | String | The identifier of the data source that generates the time series. This field can be left empty. |
_tags | String | Tags for the time series, defined as one or more key-value pairs of the string type. |
_time | Integer | The time when the data is reported. |
vin_id | String | The unique vehicle identification number (VIN). |
model | String | The vehicle model. |
speed | Double | The current speed. |
gps | String | The GPS coordinates of the vehicle, in the format |
current_mileage | Double | The current mileage. |
remaining_oil | Double | The remaining fuel. |
available_mileage | Double | The remaining drivable distance. |
tire_pressure | Double | The tire pressure data. |
Related documents
For more information about Lastpoint indexes, see Lastpoint index.