All Products
Search
Document Center

Tablestore:Retrieve time series

Last Updated:Jun 14, 2024

If you want to query the information about time series, such as the metric name and data source, or you want to list time series that meet specified conditions, you can call the QueryTimeseriesMeta operation. This operation allows you to query time series by specific conditions such as metric name, data source, tag, attribute, and update time.

Prerequisites

Parameters

The metaQueryCondition parameter specifies the conditions for a time series retrieval. The conditions include compositeMetaQueryCondition, measurementMetaQueryCondition, dataSourceMetaQueryCondition, tagMetaQueryCondition, attributeMetaQueryCondition, and updateTimeMetaQueryCondition. The following table describes the parameters.

Parameter

Required

Description

compositeMetaQueryCondition

No

The composite condition, which includes the following content:

  • operator: the logical operator. Valid logical operators: AND, OR, and NOT.

  • subConditions: the subconditions that can be combined by using operators for complex queries.

measurementMetaQueryCondition

Yes. You must specify one of the parameters.

The metric name condition, which includes the following content:

  • operator: the relational operator or prefix match condition. Valid relational operators: =, >, >=, <, and <=.

  • value: the name of the metric of the time series that you want to query. Type: STRING.

dataSourceMetaQueryCondition

The data source condition, which includes the following content:

  • operator: the relational operator or prefix match condition. Valid relational operators: =, >, >=, <, and <=.

  • value: the data source of the time series that you want to query. Type: STRING.

tagMetaQueryCondition

The tag condition, which includes the following content:

  • operator: the relational operator or prefix match condition. Valid relational operators: =, >, >=, <, and <=.

  • value: the value of the tag of the time series that you want to query. Type: STRING.

attributeMetaQueryCondition

The attribute condition for the metadata of the time series. The attribute condition includes the following content:

  • operator: the relational operator or prefix match condition. Valid relational operators: =, >, >=, <, and <=.

  • attributeName: the name of the attribute. Type: STRING.

  • value: the value of the attribute. Type: STRING.

updateTimeMetaQueryCondition

The update time condition for the metadata of the time series. The update time condition includes the following content:

  • operator: the relational operator. Valid relational operators: =, >, >=, <, and <=.

  • timeInUs: the timestamp when the time series metadata was updated. Unit: microseconds.

Examples

The following sample code provides an example on how to query the metric name, data source, and tags of the time series based on the specified condition. The specified condition can be a composite condition.

func QueryTimeseriesMetaSample(client *tablestore.TimeseriesClient , timeseriesTableName string) {
    fmt.Println("[Info]: Begin to query timeseries table meta!")

    // Construct multiple query conditions. 
    measurementMetaQueryCondition := tablestore.NewMeasurementQueryCondition(tablestore.OP_GREATER_EQUAL , "")
    datasourceMetaQueryCondition := tablestore.NewDataSourceMetaQueryCondition(tablestore.OP_GREATER_EQUAL , "")
    tagMetaQueryCondition := tablestore.NewTagMetaQueryCondition(tablestore.OP_GREATER_THAN , "City" , "")

    // Construct a composite condition. 
    compsiteMetaQueryCondition := tablestore.NewCompositeMetaQueryCondition(tablestore.OP_AND)
    compsiteMetaQueryCondition.AddSubConditions(measurementMetaQueryCondition)
    compsiteMetaQueryCondition.AddSubConditions(datasourceMetaQueryCondition)
    compsiteMetaQueryCondition.AddSubConditions(tagMetaQueryCondition)

    // Construct the query request. 
    queryTimeseriesMetaRequest := tablestore.NewQueryTimeseriesMetaRequest(timeseriesTableName)
    queryTimeseriesMetaRequest.SetCondition(compsiteMetaQueryCondition)
    queryTimeseriesMetaRequest.SetLimit(-1)

    // Call the time series client-related operation to execute the query request. 
    queryTimeseriesTableResponse , err := client.QueryTimeseriesMeta(queryTimeseriesMetaRequest)
    if err != nil {
        fmt.Println("[Error]: Query timeseries table meta failed with error: " , err)
        return
    }
    fmt.Println("[Info]: Query timeseries table meta succeed: ")
    for i := 0; i < len(queryTimeseriesTableResponse.GetTimeseriesMetas()); i++ {
        curTimeseriesMeta := queryTimeseriesTableResponse.GetTimeseriesMetas()[i]
        fmt.Println("[Info]: Meta_" , i , ": " , "Measurement: " , curTimeseriesMeta.GetTimeseriesKey().GetMeasurementName() ,
            "Source: " , curTimeseriesMeta.GetTimeseriesKey().GetDataSource() ,
            "Tags: " , curTimeseriesMeta.GetTimeseriesKey().GetTags(),
            "Attrs: " , curTimeseriesMeta.GetAttributeSlice())
    }
    fmt.Println("[Info]: QueryTimeseriesMetaSample finished !")
}

FAQ

References