You can call the DeleteTimeseriesMeta operation to delete the metadata of multiple time series in a batch.
Prerequisites
A TimeseriesClient is initialized. For more information, see Initialize a Tablestore client.
Request parameters
To delete time series metadata, you must specify the time series identifiers of the time series whose metadata you want to delete. You can specify multiple time series identifiers to perform a batch deletion.
| Parameter | Type | Required | Description |
|---|---|---|---|
| timeseriesKey | TimeseriesKey | Yes | The identifier of a time series. A timeseriesKey consists of 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. Tags are key-value pairs of the STRING type. |
Sample code
The following sample code shows how to delete the metadata of 10 time series from a time series table. Each time series is identified by a combination of a measurement name, a 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)
}The following table describes the 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. |