You can call the GetTimeseriesData operation to query the time series data that meets the specified conditions in a time series table.

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

Parameter Description
timeseriesKey The time series that you want to query, which includes the following content:
  • measurementName: the metric name of the time series.
  • dataSource: the data source of the time series. You can leave this parameter empty.
  • tags: the tags of the time series, which are multiple key-value pairs of the string type.
timeRange The time range for the query, which includes the following content:
  • beginTimeInUs: the start time.
  • endTimeInUs: the end time.
limit The maximum number of rows to return.
Note The limit parameter limits only the maximum number of rows to return. If the number of rows that meets the specified condition exceeds the limit, the number of rows that are returned may be less than the value of limit due to other limits such as the limit on the amount of data for a scan. In this case, you can obtain the remaining rows by using nextToken.
nextToken If only some rows that meet the specified condition are returned in a query and the response includes nextToken, you can specify nextToken in the next request to obtain the remaining rows.

Example

/**
 * Use GetTimeseriesDataSample to query the time series data in a specific time series in a time series table based on timeseriesKey. 
 */
func GetTimeseriesDataSample(client *tablestore.TimeseriesClient , timeseriesTableName string) {
    fmt.Println("[Info]: Begin to get timeseries data !")

    // Construct the timeseriesKey for the time series in which you want to query the time series data. 
    timeseriesKey := tablestore.NewTimeseriesKey()
    timeseriesKey.SetMeasurementName("NETWORK")
    timeseriesKey.SetDataSource("127.0.0.1")
    timeseriesKey.AddTag("City" , "Hangzhou")
    timeseriesKey.AddTag("Region" , "Xihu")

    // Construct the query request. 
    getTimeseriesDataRequest := tablestore.NewGetTimeseriesDataRequest(timeseriesTableName)
    getTimeseriesDataRequest.SetTimeseriesKey(timeseriesKey)
    getTimeseriesDataRequest.SetTimeRange(0 , time.Now().UnixNano() / 1000) // Specify the time range for the query. 
    getTimeseriesDataRequest.SetLimit(-1)

    // Call the time series client to query the data in the time series. 
    getTimeseriesResp , err := client.GetTimeseriesData(getTimeseriesDataRequest)
    if err != nil {
        fmt.Println("[Error]: Get timeseries data Failed with error: " , err)
        return
    }
    fmt.Println("[Info]: Get timeseries data succeed ! TimeseriesRows: ")
    for i := 0; i < len(getTimeseriesResp.GetRows()); i++ {
        fmt.Println("[Info]: Row" , i , ": [" , getTimeseriesResp.GetRows()[i].GetTimeseriesKey().GetMeasurementName(),
            getTimeseriesResp.GetRows()[i].GetTimeseriesKey().GetDataSource(),
            getTimeseriesResp.GetRows()[i].GetTimeseriesKey().GetTagsSlice(), "]",
            getTimeseriesResp.GetRows()[i].GetFieldsSlice(),
            getTimeseriesResp.GetRows()[i].GetTimeInus())
    }
    fmt.Println("[Info]: GetTimeseriesDataSample finished! RequestId: " , getTimeseriesResp.RequestId)
}