You can call the QueryTimeseriesMeta operation to retrieve time series that meet multiple specified conditions.

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 metaQueryCondition parameter specifies the conditions for time series retrieval. The conditions include compositeMetaQueryCondition, measurementMetaQueryCondition, dataSourceMetaQueryCondition, tagMetaQueryCondition, attributeMetaQueryCondition, and updateTimeMetaQueryCondition. The following table describes the parameters.

Parameter Description
compositeMetaQueryCondition The composite condition, which includes the following content:
  • operator: the logical operator. Valid values: AND, OR, and NOT.
  • subConditions: a list of subconditions that can be combined by using operators for complex queries.
measurementMetaQueryCondition The metric name condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the metric name for a match query. Type: string.
dataSourceMetaQueryCondition The data source condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the data source for a match query. Type: string.
tagMetaQueryCondition The tag condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the value of the tag for a match query. Type: string.
attributeMetaQueryCondition The property condition for the metadata of the time series, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • attributeName: the name of the property. Type: string.
  • value: the value of the property. Type: string.
updateTimeMetaQueryCondition The update time condition for the metadata of the time series, which includes the following content:
  • operator: the relational operator. Valid values: =, !=, >, >=, <, and <=.
  • timeInUs: the timestamp of the time when the time series metadata is updated. Unit: microseconds.

Example

/**
 * Use QueryTimeseriesMetaSample to query the metric name, data source, and tag information of a specific time series in a time series table based on a specific condition, which 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 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().GetTagsSlice() ,
            "Attrs: " , curTimeseriesMeta.GetAttributeSlice())
    }
    fmt.Println("[Info]: QueryTimeseriesMetaSample finished !")
}