You can call the CreateTimeseriesTable operation to create a time series table. When you create a time series table, you can configure the time to live (TTL) of data and parameters about time series metadata.
Prerequisites
An instance for the TimeSeries model is created in the Tablestore console. For more information, see Create an instance for the TimeSeries model.
A TimeseriesClient instance is initialized. For more information, see Initialize an OTSClient instance.
Usage notes
The name of the time series table that you create cannot be the same as the name of an existing data table.
Parameters
Parameter | Description |
TimeseriesTableMeta | The configurations of the time series table.
|
Example
The following sample code provides an example on how to create a time series table:
/**
* Use CreateTimeseriesTableSample to create a time series table named timeseriesTableName and specify the time to live (TTL) of the data in the time series table.
*/
func CreateTimeseriesTableSample(client *tablestore.TimeseriesClient, timeseriesTableName string , timeToLive int64) {
fmt.Println("[Info]: Begin to create timeseries table: " , timeseriesTableName)
// Construct the configurations of the time series table.
timeseriesTableOptions := tablestore.NewTimeseriesTableOptions(timeToLive)
// Construct the metadata of the time series table.
// Specify the name of the time series table.
timeseriesTableMeta := tablestore.NewTimeseriesTableMeta(timeseriesTableName)
// Specify the configurations of the time series table.
timeseriesTableMeta.SetTimeseriesTableOptions(timeseriesTableOptions)
// Construct a request to create the time series table.
createTimeseriesTableRequest := tablestore.NewCreateTimeseriesTableRequest()
createTimeseriesTableRequest.SetTimeseriesTableMeta(timeseriesTableMeta)
// Create the time series table.
createTimeseriesTableResponse , err := client.CreateTimeseriesTable(createTimeseriesTableRequest)
if err != nil {
fmt.Println("[Error]: Failed to create timeseries table with error: " , err)
return
}
fmt.Println("[Info]: CreateTimeseriesTable finished! RequestId: " , createTimeseriesTableResponse.RequestId)
}
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 Write time series data and Query time series data.
You can modify the TTL of data in a time series table. For more information, see Update a time series table.
You can query all time series tables on the current instance. For more information, see Query the names of time series tables.
You can query the information about a time series table. For more information, see Query the information about a time series table.
You can delete a time series table that you no longer require. For more information, see Delete a time series table.
To back up time series data in Tablestore in a cost-effective manner or export time series data as files to local devices, you can use the Data Integration feature of DataWorks to synchronize time series data from Tablestore to Object Storage Service (OSS) for storage or download. For more information, see Synchronize data from Tablestore to OSS.
To visualize time series data, you can connect Tablestore to Grafana. For more information, see Connect Tablestore to Grafana.
If you use Realtime Compute for Apache Flink to compute and analyze data, you can use Tablestore time series tables to store the results. For more information, see Tutorial (TimeSeries model).