All Products
Search
Document Center

Tablestore:Update time series

Last Updated:Apr 25, 2025

You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at the same time. If the time series metadata that you want to update does not exist, the time series metadata is added.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Operation

public class UpdateTimeseriesMetaRequest implements Request {
    /** The name of the time series table. */
    private final String timeseriesTableName;
    /** The metadata of the time series. */
    private List<TimeseriesMeta> metas = new ArrayList<TimeseriesMeta>();
}

public class TimeseriesMeta {
    /** The identifiers of the time series metadata. */
    private TimeseriesKey timeseriesKey;
    /** The attributes of the time series metadata. */
    private SortedMap<String, String> attributes = new TreeMap<String, String>();
    /** The time to live (TTL) of the time series metadata. */
    private long updateTimeInUs = -1;
}

public class TimeseriesKey implements Comparable<TimeseriesKey> {
    /** The name of the metric. */
    private final String measurementName;
    /** The name of the data source. */
    private final String dataSource;
    /** The tag information. */
    private final SortedMap<String, String> tags = new TreeMap<String, String>();
    private String tagsString;
}

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

Description

timeseriesKey

The identifiers of the time series.

attributes

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

Example

The following sample code provides an example on how to update the attributes in the metadata of time series in a time series table:

private static void updateTimeseriesMeta(TimeseriesClient client) {
    List<TimeseriesMeta> timeseriesMetaList = new ArrayList<TimeseriesMeta>();
    for (int i = 0; i < 10; i++) {
        Map<String, String> tags = new HashMap<String, String>();
        tags.put("region", "hangzhou");
        tags.put("os", "Ubuntu16.04");
        // Construct time series identifiers.
        TimeseriesKey timeseriesKey = new TimeseriesKey("cpu", "host_" + i, tags);
        TimeseriesMeta meta = new TimeseriesMeta(timeseriesKey);
        // Specify the attributes in the metadata of the time series.
        Map<String, String> attrs = new HashMap<String, String>();
        attrs.put("status", "online");
        meta.setAttributes(attrs);
        timeseriesMetaList.add(meta);
    }
    // Specify the name of the time series table.
    String tableName = "<TIME_SERIES_TABLE>";
    UpdateTimeseriesMetaRequest updateTimeseriesMetaRequest = new UpdateTimeseriesMetaRequest(tableName);
    updateTimeseriesMetaRequest.setMetas(timeseriesMetaList);
    UpdateTimeseriesMetaResponse updateTimeseriesMetaResponse = client.updateTimeseriesMeta(updateTimeseriesMetaRequest);
    // Check whether the attributes are updated.
    if (!updateTimeseriesMetaResponse.isAllSuccess()) {
        for (UpdateTimeseriesMetaResponse.FailedRowResult failedRowResult : updateTimeseriesMetaResponse.getFailedRows()) {
            System.out.println(failedRowResult.getIndex());
            System.out.println(failedRowResult.getError());
        }
    }
}

References

To view the updated attributes in the metadata of time series, you can retrieve time series. For more information, see Query time series.