【问题标题】:Write null measure values to AWS Timestream将空度量值写入 AWS Timestream
【发布时间】:2021-01-01 22:05:00
【问题描述】:

当我尝试在 AWS Timestream 中写入一条记录(具有缺失/空度量值)时,它会引发以下错误。有什么建议如何将 NULL 度量值摄取到 AWS Timestream 中?

错误:ValidationException:调用 WriteRecords 操作时发生错误 (ValidationException):Timestream 仅支持双重测量值类型的有限 IEEE 标准 754 浮点精度。

示例代码如下:

import pandas as pd
import numpy as np
import s3fs
import io
import boto3
import awswrangler as wr
import datetime
import os
import time
import gc
from datetime import timedelta
from datetime import datetime
import sys

df = pd.DataFrame(
    {
        "time": [datetime.now(), datetime.now(), datetime.now()],
        "dim0": ["foo", "boo", "bar"],
        "dim1": [1, 2, 3],
        "measure": [1.0, 1.12345678, None],
    })

rejected_records = wr.timestream.write(
    df=df,
    database="tsdb",
    table="tstable1",
    time_col="time",
    measure_col="measure",
    dimensions_cols=["dim0", "dim1"],
    boto3_session = boto3.Session()
)
print(rejected_records)

【问题讨论】:

    标签: python amazon-web-services amazon-timestream


    【解决方案1】:

    IEEE 标准 754 支持 nan(“不是数字”)。

    在 Python 中,您必须在 None 上使用 float('nan') 来满足此标准。

    如果你使用的是 numpy,你也可以使用np.nan

    【讨论】:

      猜你喜欢
      • 2021-02-22
      • 1970-01-01
      • 2021-01-20
      • 2021-06-04
      • 2021-12-25
      • 2023-01-19
      • 2021-07-14
      • 2021-06-04
      • 2022-08-03
      相关资源
      最近更新 更多