All Products
Search
Document Center

Tablestore:Update time series metadata

Last Updated:Jun 07, 2024

You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at a time.

Prerequisites

Parameters

The timeseriesMeta parameter specifies the metadata of a time series. Each timeseriesMeta parameter consists of the timeseriesKey and attributes parameters. The following table describes the parameters.

Parameter

Required

Description

timeseriesKey

Yes

The identifiers of the time series. You can use the following parameters to specify the identifiers of a time series:

  • measurementName: the metric name of the time series.

  • dataSource: the data source of the time series. You can leave this parameter empty.

  • tags: the tags of the time series. The value of this parameter is key-value pairs of the STRING type.

Important

If you are not sure about information of the time series that you want to query, such as the metric name and data source, you can call the QueryTimeseriesMeta operation to retrieve time series based on various conditions. For more information, see Retrieve time series.

attributes

Yes

The attributes of the time series. The value consists of one or more key-value pairs of the STRING type.

Examples

The following sample code provides an example on how to updates the attributes of a time series:

func UpdateTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
    fmt.Println("[Info]: Begin to update timeseries meta!")

    updateTimeseriesMetaRequest := tablestore.NewUpdateTimeseriesMetaRequest(timeseriesTableName)

    timeseriesKey := tablestore.NewTimeseriesKey()
    timeseriesKey.SetMeasurementName("NETWORK")
    timeseriesKey.SetDataSource("127.0.0.1")
    timeseriesKey.AddTag("City" , "Hangzhou")
    timeseriesKey.AddTag("Region" , "Xihu")

    timeseriesMeta := tablestore.NewTimeseriesMeta(timeseriesKey)
    //timeseriesMeta.SetUpdateTimeInUs(96400)
    timeseriesMeta.AddAttribute("NewRegion" , "Yuhang")
    timeseriesMeta.AddAttribute("NewCity" , "Shanghai")

    updateTimeseriesMetaRequest.AddTimeseriesMetas(timeseriesMeta)

    updateTimeseriesMetaResponse , err := tsClient.UpdateTimeseriesMeta(updateTimeseriesMetaRequest)
    if err != nil {
        fmt.Println("[Error]: Update timeseries meta failed with error: " , err)
        return
    }

    if len(updateTimeseriesMetaResponse.GetFailedRowResults()) > 0 {
        fmt.Println("[Error]: Update timeseries meta failed row: ")
        for i := 0; i < len(updateTimeseriesMetaResponse.GetFailedRowResults()); i++ {
            fmt.Println("[Error]: " , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Index , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Error)
        }
    }


    fmt.Println("[Info]: UpdateTimeseriesMetaSample finished!")
}

FAQ

References