All Products
Search
Document Center

Tablestore:Operations on time series tables

Last Updated:Apr 23, 2024

In the TimeSeries model, time series data is stored in time series tables to allow applications to concurrently write and read petabytes of data and reduce storage costs. When you create a time series table, you can specify the time to live (TTL) of data in the table. After you create a time series table, you can manage the time series table based on your business requirements. For example, you can query the names of all time series tables in an instance and update the configurations of a time series table.

Usage notes

  • You can create up to 64 tables in an instance. The tables include data tables, secondary index tables, and time series tables. For information about more limits on the TimeSeries model, see Limits on the TimeSeries model.

    A time series table consists of a time series metadata table and a time series data table. Therefore, a time series table is equivalent to two tables.

  • The TimeSeries model is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Ulanqab), China (Shenzhen), China (Hong Kong), Germany (Frankfurt), US (Virginia), India (Mumbai), SAU (Riyadh), and Singapore.

Overview

Tablestore provides the CreateTimeseriesTable, ListTimeseriesTable, UpdateTimeseriesTable, DescribeTimeseriesTable, and DeleteTimeseriesTable operations to help you manage time series tables.

Before you use the TimeSeries model of Tablestore to store time series data, you must call the CreateTimeseriesTable operation to create a time series table.

When you create a time series table, you must specify a name for the time series table and specify the TTL of data in the table based on your business requirements.

After you specify the TTL of data in a time series table, Tablestore automatically deletes time series data whose retention period exceeds the TTL value in asynchronous mode. For more information, see TTL of time series data.

After you create a time series table, you can manage the time series table based on your business requirements. The following table describes the operations that you can perform on time series tables.

Operation

Description

Query the names of time series tables

To view the existing time series tables in an instance, call the ListTimeseriesTable operation to query the names of all time series tables that are created in the instance.

Update the configurations of a time series table

To delete historical data or extend the retention period of data in a time series table, call the UpdateTimeseriesTable operation to change the TTL of data in the time series table, change the TTL of time series metadata, or specify whether the attribute columns of time series can be modified.

Important

When time series metadata is retained for a period of time that exceeds the specified TTL value, Tablestore automatically deletes the metadata in asynchronous mode. The data in the time series table is not deleted. You can call the GetTimeseriesData operation to query the data in the time series table by specifying the time series identifiers.

  • After you change the TTL of data in a time series table, Tablestore automatically deletes data whose retention period exceeds the new TTL value in the time series table in asynchronous mode.

  • After you change the TTL of time series metadata, Tablestore automatically deletes time series metadata whose retention period exceeds the new TTL value in asynchronous mode.

    Important

    The attributes of time series metadata are stored in the _attributes column. You can update the attributes of time series metadata for which the TTL is set to -1. The value -1 indicates that the metadata never expires.

    If you want to change the TTL of time series metadata from -1 to a value that is greater than or equal to 604800 (seven days), make sure that you do not need to update the attributes of the time series metadata. In addition, you need to set Whether to Update Attributes of Time Series Metadata to No.

    If you set Whether to Update Attributes of Time Series Metadata to Yes, you must set TTL of Time Series Metadata to -1.

  • By default, the attribute columns of time series metadata can be modified. You can also specify that the attribute columns of time series metadata cannot be modified based on your business requirements.

Query information about a time series table

To view the configuration details of a time series table, call the DescribeTimeseriesTable operation to query the configurations of the time series table, such as the TTL of data in the time series table, table status, or configurations of time series metadata (such as whether the attribute columns of time series metadata can be modified).

Delete a time series table

To delete a time series table from an instance, call the DeleteTimeseriesTable operation

Important

You cannot restore a deleted time series table. Proceed with caution.

Methods

You can perform operations on a time series table in the Tablestore console or by using Tablestore CLI or SDKs.

Note

The supported features vary based on the method that you use to perform operations on a time series table.

Before you perform operations on a time series table, make sure that the following preparations are made:

Use the Tablestore console

Create a time series table in the Tablestore console.

  1. Go to the Instance Management page.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click the name of the instance that you want to manage or click Manage Instance in the Actions column of the instance.

  2. In the lower part of the Instance Details tab, click the Time Series Tables tab.

  3. On the Time Series Tables tab, click Create Time Series Table.

    Note

    You can also click Generate Demo with One Click to create a test table with sample data for a quick start. When you create a time series table, the system performs specific initialization operations. You must wait for several seconds before the time series are displayed.

  4. In the Create Time Series Table dialog box, configure the parameters. The following table describes the parameters.

    Parameter

    Description

    Name

    The name of the time series table, which is used to uniquely identify the time series table in the instance.

    The name must be 1 to 128 characters in length and can contain only letters, digits, and underscores (_). The name must start with a letter or an underscore (_).

    Important

    The name of a time series table must be different from the name of an existing data table, secondary index table, and time series table.

    Time to Live

    The retention period of data in the time series table. Unit: seconds. If the system detects that the difference between the current time and the time column that is passed to the table exceeds the specified TTL value, the system automatically deletes the expired data.

    Important

    In a time series table, the system determines the time when the data is generated based on the time column that is passed to the table, not based on the time when the data is written to the table.

    The value of this parameter must be -1 or a value that is greater than or equal to 86400. A value of -1 specifies that the data never expires. A value of 86400 specifies one day.

  5. Click OK.

    After you create the time series table, you can view the time series table on the Time Series Tables tab. If the time series table is not displayed in the list of time series tables, click the fig_tablestore_002 icon to refresh the list.

After you create the time series table, you can manage the time series table based on your business requirements. The following table describes the operations that you can perform on time series tables.

Operation

Description

Modify the TTL of data in a time series table

  1. On the Time Series Tables tab, click the name of the time series table that you want to manage.

  2. In the Description section of the Basic Information tab, click the image.png icon next to Data Lifecycle.

  3. In the dialog box that appears, modify the TTL value.

    The TTL value is the retention period of data in the time series table. Unit: seconds. The value must be -1 or a value that is greater than or equal to 86400. A value of -1 specifies that the data never expires. A value of 86400 specifies one day.

  4. Click Yes.

Modify the TTL of time series metadata

  1. On the Time Series Tables tab, click the name of the time series table.

  2. In the Description section of the Basic Information tab, click the image.png icon next to TTL of Time Series Metadata.

  3. In the dialog box that appears, modify the TTL value.

    The TTL value is the retention period of the time series metadata in the time series table. Unit: seconds. The value must be -1 or a value that is greater than or equal to 604800. A value of -1 specifies that the metadata never expires. A value of 604800 specifies seven days.

  4. Click Yes.

Specify whether the attribute columns of time series metadata can be modified

  1. On the Time Series Tables tab, click the name of the time series table.

  2. In the Description section of the Basic Information tab, click the image.png icon next to Whether to Update Attributes of Time Series Metadata.

  3. In the dialog box that appears, select Yes or No.

  4. Click Yes.

Delete a time series table

  1. On the Time Series Tables tab, find the time series table that you want to manage and click Delete in the Actions column.

  2. In the message that appears, click OK.

Use the Tablestore CLI

Run the create command to create a time series table by using the Tablestore CLI. For more information, see Create a time series table.

The following sample code provides an example on how to create a time series table named mytable. Data in the mytable table does not expire.

create -m timeseries -t mytable --ttl -1

Before you perform operations on a table, you must run the use command to select the table that you want to manage. For more information, see Use a time series table.

The following sample code provides an example on how to select the mytable table:

use --ts -t mytable

After you create and select a time series table, you can manage the time series table based on your business requirements. The following table describes the operations that you can perform on time series tables.

Operation

Description

Query the names of time series tables

Run the list command to query the names of all tables in the current instance. For more information, see List the names of tables.

The following sample code provides an example on how to query the names of all time series tables:

list -t

Update the configurations of a time series table

Run the alter command to update the configurations of a table. For more information, see Update a time series table.

The following sample code provides an example on how to change the TTL of data in the time series table to 86400 (one day):

alter --ttl 86400 --ts

Query information about a time series table

Run the desc command to view information about a time series table. For more information, see Query the information about a time series table.

The following sample code provides an example on how to query information about the mytable table:

desc --ts -t mytable

Delete a time series table

Run the drop command to delete a table that you no longer require. For more information, see Delete a time series table.

The following sample code provides an example on how to delete the mytable table:

drop -t mytable --ts -y

Use Tablestore SDKs

You can use Tablestore SDK for Java and Tablestore SDK for Go to create and manage a time series table. In this example, Tablestore SDK for Java is used.

Create a time series table based on your business requirements.

The following sample code provides an example on how to create a time series table named test_timeseries_table whose data never expires.

private static void createTimeseriesTable(TimeseriesClient client) {
    String tableName = "test_timeseries_table";
    TimeseriesTableMeta timeseriesTableMeta = new TimeseriesTableMeta(tableName);
    int timeToLive = -1;
    timeseriesTableMeta.setTimeseriesTableOptions(new TimeseriesTableOptions(timeToLive));
    CreateTimeseriesTableRequest request = new CreateTimeseriesTableRequest(timeseriesTableMeta);
    
    client.createTimeseriesTable(request);
}

After you create the time series table, you can manage the time series table based on your business requirements.

Query the names of time series tables

The following sample code provides an example on how to query the names of all time series tables in an instance.

private static void listTimeseriesTable(TimeseriesClient client) {
    ListTimeseriesTableResponse listTimeseriesTableResponse = client.listTimeseriesTable();
    for (String table : listTimeseriesTableResponse.getTimeseriesTableNames()) {
        System.out.println(table);
    }
}

Modify the TTL of data in a time series table

The following sample code provides an example on how to change the TTL of the data in a time series table to three years.

private static void updateTimeseriesTable(TimeseriesClient client) {
    // Specify the name of the time series table. 
    String tableName = "<TIMESERIES_TABLE>";
    UpdateTimeseriesTableRequest updateTimeseriesTableRequest = new UpdateTimeseriesTableRequest(tableName);
    // Change the TTL to three years. 
    updateTimeseriesTableRequest.setTimeseriesTableOptions(new TimeseriesTableOptions(86400 * 365 * 3)); 
    client.updateTimeseriesTable(updateTimeseriesTableRequest);

    DescribeTimeseriesTableResponse describeTimeseriesTableResponse = client.describeTimeseriesTable(new DescribeTimeseriesTableRequest(tableName));
    TimeseriesTableMeta tableMeta = describeTimeseriesTableResponse.getTimeseriesTableMeta();
    // View the modified TTL. 
    System.out.println(tableMeta.getTimeseriesTableOptions().getTimeToLive()); 
}

Query information about a time series table

The following sample code provides an example on how to query the information about a time series table.

private static void describeTimeseriesTable(TimeseriesClient client) {
    // Specify the name of the time series table. 
    String tableName = "<TIMESERIES_TABLE>";
    DescribeTimeseriesTableResponse describeTimeseriesTableResponse = client.describeTimeseriesTable(new DescribeTimeseriesTableRequest(tableName));
    TimeseriesTableMeta tableMeta = describeTimeseriesTableResponse.getTimeseriesTableMeta();
    // View the name of the time series table. 
    System.out.println(tableMeta.getTimeseriesTableName()); 
    // View the status of the time series table. 
    System.out.println(tableMeta.getStatus()); 
    // View the TTL of data in the time series table. 
    System.out.println(tableMeta.getTimeseriesTableOptions().getTimeToLive()); 
    // View the TTL of the time series metadata. 
    System.out.println(tableMeta.getTimeseriesMetaOptions().getMetaTimeToLive()); 
    // Check whether the property columns of the time series metadata can be modified. 
    System.out.println(tableMeta.getTimeseriesMetaOptions().getAllowUpdateAttributes()); 
}

Delete a time series table

The following sample code provides an example on how to delete a time series table.

private static void deleteTimeseriesTable(TimeseriesClient client) {
    // Specify the name of the time series table. 
    String tableName = "<TIMESERIES_TIME>";
    DeleteTimeseriesTableRequest deleteTimeseriesTableRequest = new DeleteTimeseriesTableRequest(tableName);
    client.deleteTimeseriesTable(deleteTimeseriesTableRequest);
}

References

After you create a time series table, you can write time series data to the table and read time series data from the table. For more information, see Basic data operations.