Use Tablestore SDK for Go 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 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 |
Specify time series identifiers | Create |
Add identifiers to the request | Call |
Send the request | Call |