Hello,
I want to use the python client library to add a tag to all the records matching a query.
That’s what I got so far, but it’s not working.
client = InfluxDBClient(url=url, token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)
query_api = client.query_api()
query = "<put_your_query_here>"
result = query_api.query(org=org, query=query)
for table in result:
for record in table.records:
record["ADDITIONAL_TAG"] = str(uuid.uuid4())
write_api.write(bucket=bucket, org=org, record=record)
I want to avoid creating the point with p = Point(...).tag(...).field(...) because in that case I need to know the tags in advance since in the docs I only see values.get("<your tag>") to retrieve tags.
Thanks
The write_api doesn’t supports writes FluxRecord into InfluxDB.
The best option for you is to create a dictionary with values from FluxRecord. Something like:
result = query_api.query('from(bucket:"my-bucket") |> range(start: -10m)')
for table in result:
for record in table.records:
ignore = ['result', 'table', '_time', '_start', '_stop', '_field', '_measurement']
# tags
tag_names = [column.label for column in table.columns if column.group and column.label not in ignore]
tags = {tag: record[tag] for tag in tag_names}
tags["ADDITIONAL_TAG"] = str(uuid.uuid4())
# fields
field_names = [column.label for column in table.columns if not column.group and column.label not in ignore]
fields = {field: record[field] for field in field_names}
lp_dict = {
"measurement": record["_measurement"],
"tags": tags,
"fields": fields,
"time": record["_time"]
}
write_api.write(bucket=bucket, org=org, record=lp_dict)