You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at a time.
For more information about the UpdateTimeseriesMeta operation, see UpdateTimeseriesMeta.
Prerequisites
Time series data is written to the time series table from which you want to query data. For more information, see Write time series data.
A TimeseriesClient instance is initialized. For more information, see Initialize a client.
Syntax
public class UpdateTimeseriesMetaRequest implements Request {
/** The name of the time series table. */
private final String timeseriesTableName;
/** The time series metadata. */
private List<TimeseriesMeta> metas = new ArrayList<TimeseriesMeta>();
}
public class TimeseriesMeta {
/** The identifier of the time series metadata. */
private TimeseriesKey timeseriesKey;
/** The properties 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 tags of the time series. */
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 identifier of the time series metadata. |
attributes | The properties of the time series metadata. 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 properties of the metadata of multiple 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 the identifiers of the time series.
TimeseriesKey timeseriesKey = new TimeseriesKey("cpu", "host_" + i, tags);
TimeseriesMeta meta = new TimeseriesMeta(timeseriesKey);
// Specify the values of the properties 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 properties of all time series are updated.
if (!updateTimeseriesMetaResponse.isAllSuccess()) {
for (UpdateTimeseriesMetaResponse.FailedRowResult failedRowResult : updateTimeseriesMetaResponse.getFailedRows()) {
System.out.println(failedRowResult.getIndex());
System.out.println(failedRowResult.getError());
}
}
}