After you create a time series table, call the PutTimeseriesData operation to write one or more rows of time series data to the table.
Usage notes
The TimeSeries model requires Tablestore SDK for Python V6.1.0 or later.
For more information, see Python SDK version history.
Prerequisites
Before you begin, ensure that you have:
An initialized Tablestore client. For more information, see Initialize a Tablestore client.
Parameters
|
Parameter |
Description |
|
timeseriesTableName (required) |
The name of the time series table. |
|
timeseriesRows (required) |
The list of time series rows to write. Each row consists of a time series identifier and the associated data.
|
Examples
The following example writes two rows of time series data to a time series table:
# Define tags to identify the time series
tags = {"tag1": "t1", "tag2": "t2"}
# Create time series identifiers
key1 = TimeseriesKey("measure1", "datasource1", tags)
key2 = TimeseriesKey("measure2", "datasource2", tags)
# Define data points for each time series
field1 = {"long_field": 1, "string_field": "string", "bool_field": True, "double_field": 0.3}
field2 = {"binary_field2": bytearray(b'a')}
try:
# Build time series rows with a microsecond timestamp
row1 = TimeseriesRow(key1, field1, int(time.time() * 1000000))
row2 = TimeseriesRow(key2, field2, int(time.time() * 1000000))
rows = [row1, row2]
# Write the rows to the time series table
ots_client.put_timeseries_data("", rows)
print("put timeseries data succeeded.")
except Exception as e:
print("put timeseries data failed. %s" % e)