为什么使用用户定义数据类的可迭代对象在 aioinflux 中调用 `write` 似乎只插入最后一项?
Why does calling `write` in aioinflux with an iterable of a user-defined dataclass seem to only insert the last item?
我一直在尝试将列表中包含的数据插入到 运行 influxdb 服务器中。
该列表包含以下类型的项目 CoordInfluxData:
from aioinflux.serialization.usertype import FLOAT, INT, TIMEINT, lineprotocol
from dataclasses import dataclass
@lineprotocol(
schema=dict(lon=INT, lat=INT, time=TIMEINT, humidity=FLOAT, wind_speed=FLOAT)
)
@dataclass
class CoordInfluxData(dict):
lon: int
lat: int
time: int
humidity: float
wind_speed: float
我正在使用 influxdb1.8,我不明白为什么要插入这样一个用户定义的数据类的可迭代对象,不仅似乎只在数据库中插入可迭代对象的最后一项,而且即使我显式调用 write
并提供 measurement
参数,不会在数据库中创建测量。唯一创建的测量与我尝试编写的自定义数据类同名。
这是一个示例脚本
import asyncio
from dataclasses import dataclass
from aioinflux import InfluxDBClient
from aioinflux.serialization.usertype import FLOAT, INT, TIMEINT, lineprotocol
@lineprotocol(
schema=dict(lon=INT, lat=INT, time=TIMEINT, humidity=FLOAT, wind_speed=FLOAT)
)
@dataclass
class CoordInfluxData(dict):
lon: int
lat: int
time: int
humidity: float
wind_speed: float
async def main():
db_name = "coord_data"
data = [
CoordInfluxData(
lon=164, lat=-15, time=1649938757, humidity=75, wind_speed=5.36
),
CoordInfluxData(lon=33, lat=-18, time=1649938757, humidity=73, wind_speed=0.99),
CoordInfluxData(
lon=139, lat=18, time=1649938757, humidity=86, wind_speed=15.13
),
]
client = InfluxDBClient(db=db_name)
await client.create_database(db_name)
await client.write(data, "weather_data")
await client.close()
# Call main
asyncio.run(main())
在详尽研究报告的问题并仔细查看提供的数据后,我认为问题在于 InfluxDB
将提供的点识别为重复项。正如 docs 所说:
A point is uniquely identified by the measurement name, tag set, and
timestamp. If you submit a new point with the same measurement, tag
set, and timestamp as an existing point, the field set becomes the
union of the old field set and the new field set, where any ties go to
the new field set
我一直在尝试将列表中包含的数据插入到 运行 influxdb 服务器中。 该列表包含以下类型的项目 CoordInfluxData:
from aioinflux.serialization.usertype import FLOAT, INT, TIMEINT, lineprotocol
from dataclasses import dataclass
@lineprotocol(
schema=dict(lon=INT, lat=INT, time=TIMEINT, humidity=FLOAT, wind_speed=FLOAT)
)
@dataclass
class CoordInfluxData(dict):
lon: int
lat: int
time: int
humidity: float
wind_speed: float
我正在使用 influxdb1.8,我不明白为什么要插入这样一个用户定义的数据类的可迭代对象,不仅似乎只在数据库中插入可迭代对象的最后一项,而且即使我显式调用 write
并提供 measurement
参数,不会在数据库中创建测量。唯一创建的测量与我尝试编写的自定义数据类同名。
这是一个示例脚本
import asyncio
from dataclasses import dataclass
from aioinflux import InfluxDBClient
from aioinflux.serialization.usertype import FLOAT, INT, TIMEINT, lineprotocol
@lineprotocol(
schema=dict(lon=INT, lat=INT, time=TIMEINT, humidity=FLOAT, wind_speed=FLOAT)
)
@dataclass
class CoordInfluxData(dict):
lon: int
lat: int
time: int
humidity: float
wind_speed: float
async def main():
db_name = "coord_data"
data = [
CoordInfluxData(
lon=164, lat=-15, time=1649938757, humidity=75, wind_speed=5.36
),
CoordInfluxData(lon=33, lat=-18, time=1649938757, humidity=73, wind_speed=0.99),
CoordInfluxData(
lon=139, lat=18, time=1649938757, humidity=86, wind_speed=15.13
),
]
client = InfluxDBClient(db=db_name)
await client.create_database(db_name)
await client.write(data, "weather_data")
await client.close()
# Call main
asyncio.run(main())
在详尽研究报告的问题并仔细查看提供的数据后,我认为问题在于 InfluxDB
将提供的点识别为重复项。正如 docs 所说:
A point is uniquely identified by the measurement name, tag set, and timestamp. If you submit a new point with the same measurement, tag set, and timestamp as an existing point, the field set becomes the union of the old field set and the new field set, where any ties go to the new field set