After you create a time series table, you can call the PutTimeseriesData operation to write one or more rows of time series data to the table at the same time.
Usage notes
Features of the TimeSeries model are supported by Tablestore SDK for Python V6.1.0 and later. Make sure that you use a correct version of Tablestore SDK for Python.
For more information, see Version history of Tablestore SDK for Python.
Prerequisites
A client is initialized. 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 data. A row of time series data consists of time series identifiers and time series data.
|
Examples
The following sample code provides an example on how to write multiple rows of time series data to a time series table:
# The tag information of the time series.
tags = {"tag1": "t1", "tag2": "t2"}
# The time series identifiers.
key1 = TimeseriesKey("measure1", "datasource1", tags)
key2 = TimeseriesKey("measure2", "datasource2", tags)
# The time series data.
field1 = {"long_field": 1, "string_field": "string", "bool_field": True, "double_field": 0.3}
field2 = {"binary_field2": bytearray(b'a')}
try:
# The time series data.
row1 = TimeseriesRow(key1, field1, int(time.time() * 1000000))
row2 = TimeseriesRow(key2, field2, int(time.time() * 1000000))
rows = [row1, row2]
# Call the operation to write time series data.
ots_client.put_timeseries_data("", rows)
print("put timeseries data succeeded.")
except Exception as e:
# If an exception is thrown, the operation fails. Handle the exception.
print("put timeseries data failed. %s" % e)