Use Tablestore SDK for Java to update the attributes of multiple time series metadata entries and obtain errors for failed entries.
Prerequisites
-
Install the Tablestore SDK for Java and initialize a time series client.
-
The time series table allows metadata attributes to be updated. If updates are not allowed, modify the time series table configurations and set
allowUpdateAttributestotrue.
Description
Call updateTimeseriesMeta to update the attributes of multiple time series metadata entries. If the specified metadata does not exist, the server adds it.
public UpdateTimeseriesMetaResponse updateTimeseriesMeta(UpdateTimeseriesMetaRequest request) throws TableStoreException, ClientException
Time series metadata indexes are updated asynchronously. After you submit an update, wait for the index to be updated before you query the latest attributes.
The following example updates the status attribute of the specified time series in example_timeseries_table to online and checks failed entries.
Map<String, String> tags = new HashMap<>();
tags.put("region", "cn-hangzhou");
tags.put("host", "host_0");
TimeseriesKey timeseriesKey =
new TimeseriesKey("cpu", "source_0", tags);
Map<String, String> attributes = new HashMap<>();
attributes.put("status", "online");
TimeseriesMeta meta = new TimeseriesMeta(timeseriesKey);
meta.setAttributes(attributes);
UpdateTimeseriesMetaRequest request =
new UpdateTimeseriesMetaRequest("example_timeseries_table");
request.setMetas(Collections.singletonList(meta));
UpdateTimeseriesMetaResponse response =
timeseriesClient.updateTimeseriesMeta(request);
for (UpdateTimeseriesMetaResponse.FailedRowResult result : response.getFailedRows()) {
System.out.println(result.getIndex());
System.out.println(result.getError());
}
Parameters
UpdateTimeseriesMetaRequest contains the following parameters.
|
Name |
Type |
Description |
|
timeseriesTableName (required) |
|
The time series table name. |
|
metas (required) |
|
The non-empty list of time series metadata entries to update. You can update multiple entries in a request. |
Time series metadata
Each element in metas[] is of the TimeseriesMeta type and contains the following parameters.
|
Name |
Type |
Description |
|
timeseriesKey (required) |
|
The identifiers of the time series whose metadata you want to update. |
|
attributes (optional) |
|
The metadata attributes to set as string key-value pairs. If this parameter is not specified or is set to an empty map, Tablestore SDK for Java does not send attribute content. |
updateTimeInUs is generated by the server and is returned when you query time series metadata. Do not set this field in an update request. Otherwise, Tablestore SDK for Java rejects the request.
Time series identifiers
metas[].timeseriesKey is of the TimeseriesKey type and contains the following parameters.
|
Name |
Type |
Description |
|
measurementName (required) |
|
The measurement name. Tablestore SDK for Java 5.17.2 and later allow this parameter to be empty. |
|
dataSource (optional) |
|
The data source identifier, which can be empty. |
|
tags (optional) |
|
The tags as string key-value pairs. If this parameter is not specified, an empty map is used. |
Response
UpdateTimeseriesMetaResponse contains the following operation-specific field.
|
Field |
Type |
Description |
|
|
|
Call |
Failed entry information
Each element in failedRows[] is of the UpdateTimeseriesMetaResponse.FailedRowResult type and contains the following fields.
|
Field |
Type |
Description |
|
|
|
Call |
|
|
|
Call |