Delete time series
You can call the DeleteTimeseriesMeta operation to delete the metadata of multiple time series in a batch.
Prerequisites
A TimeseriesClient is initialized. Initialize a Tablestore client.
Request parameters
Specify the time series identifiers of the time series to delete. You can specify multiple identifiers for batch deletion.
| Parameter | Type | Required | Description |
|---|---|---|---|
| timeseriesKey | TimeseriesKey | Yes | The time series identifier. A timeseriesKey contains the following components: |
TimeseriesKey components
| Component | Type | Required | Description |
|---|---|---|---|
| measurementName | string | Yes | The measurement name of the time series. |
| dataSource | string | No | The data source of the time series. You can leave this parameter empty. |
| tags | map[string]string | No | The tags of the time series, specified as string key-value pairs. |
Sample code
The following example deletes the metadata of 10 time series. Each time series is identified by a measurement name, data source, and tags.
func DeleteTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
fmt.Println("[Info]: Begin to delete timeseries meta: ", timeseriesTableName)
// Construct a request to delete time series metadata.
deleteTimeseriesMetaRequest := tablestore.NewDeleteTimeseriesMetaRequest(timeseriesTableName)
for i := 0; i < 10; i++ {
timeseriesKey := tablestore.NewTimeseriesKey()
timeseriesKey.SetMeasurementName("cpu")
timeseriesKey.SetDataSource("host_" + strconv.Itoa(i))
timeseriesKey.AddTag("region", "hangzhou")
timeseriesKey.AddTag("os", "Ubuntu16.04")
deleteTimeseriesMetaRequest.AddTimeseriesKeys(timeseriesKey)
}
deleteTimeseriesMetaResponse, err := tsClient.DeleteTimeseriesMeta(deleteTimeseriesMetaRequest)
if err != nil {
fmt.Println("[Error]: Failed to delete timeseries meta with error: ", err)
return
}
fmt.Println("[Info]: DeleteTimeseriesMeta finished! RequestId: ", deleteTimeseriesMetaResponse.RequestId)
}
Key steps in the sample code:
| Step | Description |
|---|---|
| Create a request | Call tablestore.NewDeleteTimeseriesMetaRequest(timeseriesTableName) to create a delete request for the specified time series table. |
| Specify time series identifiers | Create TimeseriesKey objects by calling tablestore.NewTimeseriesKey(), and then set the measurement name, data source, and tags for each time series. |
| Add identifiers to the request | Call deleteTimeseriesMetaRequest.AddTimeseriesKeys(timeseriesKey) to add each time series identifier to the request. |
| Send the request | Call tsClient.DeleteTimeseriesMeta(deleteTimeseriesMetaRequest) to send the request. The response contains the RequestId. |