You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at the same time.
Prerequisites
- Time series data is written to the time series table. For more information, see Write time series data.
- The TimeseriesClient is initialized. For more information, see Initialization.
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 identifier of the time series. |
attributes | The properties of the time series. The value is a key-value pair of the string type. |
Example
Update the properties of the time series that meet the specified conditions in a time series table named test_timeseries_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 TimeseriesKey.
TimeseriesKey timeseriesKey = new TimeseriesKey("cpu", "host_" + i, tags);
TimeseriesMeta meta = new TimeseriesMeta(timeseriesKey);
// Specify the properties of the time series.
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("status", "online");
meta.setAttributes(attrs);
timeseriesMetaList.add(meta);
}
String tableName = "test_timeseries_table";
UpdateTimeseriesMetaRequest updateTimeseriesMetaRequest = new UpdateTimeseriesMetaRequest(tableName);
updateTimeseriesMetaRequest.setMetas(timeseriesMetaList);
UpdateTimeseriesMetaResponse updateTimeseriesMetaResponse = client.updateTimeseriesMeta(updateTimeseriesMetaRequest);
// Check whether the properties of the time series are updated.
if (!updateTimeseriesMetaResponse.isAllSuccess()) {
for (UpdateTimeseriesMetaResponse.FailedRowResult failedRowResult : updateTimeseriesMetaResponse.getFailedRows()) {
System.out.println(failedRowResult.getIndex());
System.out.println(failedRowResult.getError());
}
}
}