Use Tablestore SDK for Java to query time series metadata by measurement name, data source, tag, attribute, or update time, combine conditions, and paginate the results.
Prerequisites
Install the Tablestore SDK for Java and initialize a time series client.
Description
Call queryTimeseriesMeta to query time series metadata in a time series table. If you do not specify a condition, all time series metadata is returned. If you specify a condition, metadata is filtered by one or more time series characteristics.
public QueryTimeseriesMetaResponse queryTimeseriesMeta(QueryTimeseriesMetaRequest request) throws TableStoreException, ClientException
The server asynchronously builds metadata indexes for new time series. After you write a new time series, wait for the index to be built before you query its metadata.
The following example queries metadata of time series whose measurement name is cpu and whose os tag value starts with Ubuntu in example_timeseries_table.
CompositeMetaQueryCondition condition =
new CompositeMetaQueryCondition(MetaQueryCompositeOperator.OP_AND);
condition.addSubCondition(new MeasurementMetaQueryCondition(
MetaQuerySingleOperator.OP_EQUAL, "cpu"));
condition.addSubCondition(new TagMetaQueryCondition(
MetaQuerySingleOperator.OP_PREFIX, "os", "Ubuntu"));
QueryTimeseriesMetaRequest request =
new QueryTimeseriesMetaRequest("example_timeseries_table");
request.setCondition(condition);
request.setGetTotalHits(true);
request.setLimit(100);
QueryTimeseriesMetaResponse response =
timeseriesClient.queryTimeseriesMeta(request);
System.out.println(response.getTotalHits());
for (TimeseriesMeta meta : response.getTimeseriesMetas()) {
System.out.println(meta);
}
Parameters
QueryTimeseriesMetaRequest contains the following parameters.
|
Name |
Type |
Description |
|
timeseriesTableName (required) |
|
The time series table name. |
|
condition (optional) |
|
The condition used to query time series metadata. If this parameter is not specified, all time series metadata is returned. |
|
getTotalHits (optional) |
|
Specifies whether to return the total number of matching time series metadata entries. Default: |
|
limit (optional) |
|
The maximum number of time series metadata entries to return in a request. Only positive values take effect. The actual number of entries returned may be less than this value. |
|
nextToken (optional) |
|
The pagination token. Do not specify this parameter in the first request. If |
condition can be set to one of the following condition types. String conditions support OP_EQUAL, OP_GREATER_THAN, OP_GREATER_EQUAL, OP_LESS_THAN, OP_LESS_EQUAL, and OP_PREFIX. Update-time conditions do not support OP_PREFIX.
Composite condition
If condition is of the CompositeMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The logical operator. Valid values: |
|
subConditions (required) |
|
The non-empty list of conditions to combine. A subcondition can also be a composite condition. |
Measurement-name condition
If condition is of the MeasurementMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The query operator. |
|
value (required) |
|
The measurement name to match. |
Data-source condition
If condition is of the DataSourceMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The query operator. |
|
value (required) |
|
The data source identifier to match. |
Tag condition
If condition is of the TagMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The query operator. |
|
tagName (required) |
|
The non-empty tag name to match. |
|
value (required) |
|
The tag value to match. |
Attribute condition
If condition is of the AttributeMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The query operator. |
|
attributeName (required) |
|
The non-empty attribute name to match. |
|
value (required) |
|
The attribute value to match. |
Update-time condition
If condition is of the UpdateTimeMetaQueryCondition type, it contains the following parameters.
|
Name |
Type |
Description |
|
operator (required) |
|
The query operator. Valid values: |
|
timeInUs (required) |
|
The last update time of the metadata, in microseconds since 1970-01-01 00:00:00 UTC. |
Response
QueryTimeseriesMetaResponse contains the following operation-specific fields.
|
Field |
Type |
Description |
|
|
|
Call |
|
|
|
Call |
|
|
|
Call |
Time series metadata
Each element in timeseriesMetas[] is of the TimeseriesMeta type and contains the following fields.
|
Field |
Type |
Description |
|
|
|
Call |
|
|
|
Call |
|
|
|
Call |
Time series identifiers
timeseriesMetas[].timeseriesKey is of the TimeseriesKey type and contains the following fields.
|
Field |
Type |
Description |
|
|
|
Call |
|
|
|
Call |
|
|
|
Call |
Examples
Paginate all metadata
If nextToken in the response is not null, repeatedly pass the token until all results are returned.
List<TimeseriesMeta> allMetas = new ArrayList<>();
byte[] nextToken = null;
do {
request.setNextToken(nextToken);
QueryTimeseriesMetaResponse response =
timeseriesClient.queryTimeseriesMeta(request);
allMetas.addAll(response.getTimeseriesMetas());
nextToken = response.getNextToken();
} while (nextToken != null);