すべてのプロダクト
Search
ドキュメントセンター

Tablestore:時系列データの書き込み

最終更新日:May 01, 2026

時系列テーブルを作成した後、PutTimeseriesData 操作を呼び出して、1 行以上の時系列データをテーブルに書き込みます。

注意事項

時系列モデルには、Tablestore SDK for Python V6.1.0 以降が必要です。

説明

詳細については、「Python SDK のバージョン履歴」をご参照ください。

前提条件

作業を開始する前に、次の要件を満たしていることを確認してください。

パラメーター

パラメーター

説明

timeseriesTableName (必須)

時系列テーブルの名前。

timeseriesRows (必須)

書き込む時系列行のリスト。各行は時系列識別子と関連データで構成されます。

  • timeseries_key (必須):時系列識別子。以下のフィールドで構成されます。

    • measurement_name (必須):時系列のメトリック名。

    • data_source (必須):データソース識別子。

    • tags (必須):時系列のタグ。キーと値のペアで指定します。

  • time_in_us (必須):データポイントのタイムスタンプ(マイクロ秒単位)。

  • fields (必須):データポイント。フィールドのキーと値のペアで指定します。

使用例

次の例では、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)