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 Initialization.
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)
// Call the TimeseriesClient instance to 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)
}