influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
706 stars 185 forks source link

Can not write a point to the specific time (HH:MM:SS) using Point.time #620

Closed tkaewplik closed 8 months ago

tkaewplik commented 8 months ago

Specifications

Code sample to reproduce problem

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.domain.write_precision import WritePrecision

ORG = "org"
# ENDPOINT_URL = 'http://influxdb:8086'
BUCKET = 'table1'
TABLE_NAME = 'table1'
TOKEN = "XXXXX"
MEASUREMENT="_measurement"

client = InfluxDBClient(url="http://localhost:8086", token=TOKEN, org=ORG)

write_api = client.write_api(write_options=SYNCHRONOUS)

"""
Add Data
"""

p = Point(MEASUREMENT)

timestamp = "2023-12-05T21:20:32.001001231Z"        
p.time(timestamp, write_precision=WritePrecision.S)

fields = {"number": 1}

tags = {}
tags['tag1'] = "tag1"
tags['timeeeeeeee'] = timestamp

for tag in tags:
    p.tag(tag, tags[tag])

for field in fields:
    p.field(field, fields[field])

write_api.write(bucket=BUCKET, record=p)

"""
Close client
"""
client.close()

Expected behavior

I tried to add my data point to the specific time in the past

Actual behavior

timestamp = "2023-12-05T21:20:32.001001231Z"        
p.time(timestamp, write_precision=WritePrecision.S)
image

I should get the data point on "2023-12-05T21:20:32.001001231Z" but I got "2023-12-06T07:00:00.000Z" somehow. it seems that the time of the day can not be saved to that specific point

Additional info

No response

bednar commented 8 months ago

Hi @tkaewplik,

thanks for using our client.

I should get the data point on "2023-12-05T21:20:32.001001231Z" but I got "2023-12-06T07:00:00.000Z" somehow. it seems that the time of the day can not be saved to that specific point

Please check the query which is used in InfluxDB UI, there is a probably the window aggregation function which cause the the timestamp is 2023-12-06T07:00:00.000Z.