時系列テーブルを作成した後、PutTimeseriesData 操作を呼び出して、1 行以上の時系列データをテーブルに書き込みます。
注意事項
時系列モデルには、Tablestore SDK for Python V6.1.0 以降が必要です。
説明
詳細については、「Python SDK のバージョン履歴」をご参照ください。
前提条件
作業を開始する前に、次の要件を満たしていることを確認してください。
初期化済みの Tablestore クライアント。詳細については、「Tablestore クライアントの初期化」をご参照ください。
パラメーター
|
パラメーター |
説明 |
|
timeseriesTableName (必須) |
時系列テーブルの名前。 |
|
timeseriesRows (必須) |
書き込む時系列行のリスト。各行は時系列識別子と関連データで構成されます。
|
使用例
次の例では、2 行の時系列データを時系列テーブルに書き込みます。
# 時系列を識別するためのタグを定義
tags = {"tag1": "t1", "tag2": "t2"}
# 時系列識別子を作成
key1 = TimeseriesKey("measure1", "datasource1", tags)
key2 = TimeseriesKey("measure2", "datasource2", tags)
# 各時系列のデータポイントを定義
field1 = {"long_field": 1, "string_field": "string", "bool_field": True, "double_field": 0.3}
field2 = {"binary_field2": bytearray(b'a')}
try:
# マイクロ秒単位のタイムスタンプで時系列行を構築
row1 = TimeseriesRow(key1, field1, int(time.time() * 1000000))
row2 = TimeseriesRow(key2, field2, int(time.time() * 1000000))
rows = [row1, row2]
# 時系列テーブルに行を書き込み
ots_client.put_timeseries_data("", rows)
print("put timeseries data succeeded.")
except Exception as e:
print("put timeseries data failed. %s" % e)