Python aioinflux `serialization.usertype.SchemaError: Can't have more than one timestamp-type attribute`, how to avoid it?

Python aioinflux `serialization.usertype.SchemaError: Can't have more than one timestamp-type attribute`, how to avoid it?

我有这个 dataclass 和这样的 lineprotocol 架构:

from datetime import date, datetime
from aioinflux import lineprotocol, TIMEDT, TAG, FLOAT, MEASUREMENT, STR, INT
from dataclasses import dataclass
from shared import DEBUG_TABLE_NAME


@lineprotocol(
    schema=dict(
        timestamp=TIMEDT,
        measurement=MEASUREMENT,
        target_id=INT,
        type=TAG,
        weight=FLOAT,
        confidence=FLOAT,
        statement=TAG,
        now_time=TIMEDT,
        height=INT,
        dt_time=TIMEDT,
        success=TAG,
    )
)
@dataclass
class DataPoint:
    timestamp: datetime
    target_id: int
    type: str
    weight: float
    confidence: float
    statement: str
    now_time: datetime
    height: int
    dt_time: datetime
    success: str
    measurement: str = DEBUG_TABLE_NAME

但是在尝试 运行 代码时出现此错误: aioinflux.serialization.usertype.SchemaError: Can't have more than one timestamp-type attribute [~TIMEINT, ~TIMEDT, ~TIMESTR]

我还需要一些其他属性,例如 now_timedt_time,时间格式要短一些。但这似乎引发了 aioinflux 的错误。如何避免这种情况?

字段的有效值类型仅为:Float、Integer、UInteger、String、Boolean (Reference)

您可以做的是将日期存储为整数(时间戳)或字符串(RFC3339 格式)。 然后,如果需要,您可以在 Flux 查询中将其投回,使用:

  1. toTime() 方便转换 _value
  2. time() 转换单个值(例如,在 map() 内)