Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone location ignored #591

Open
Siirko opened this issue Jul 10, 2023 · 5 comments
Open

Timezone location ignored #591

Siirko opened this issue Jul 10, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@Siirko
Copy link
Contributor

Siirko commented Jul 10, 2023

Specifications

  • Client Version: 1.36.1
  • InfluxDB Version: 2.7.1
  • Platform: Ubuntu 22.04 LTS

Code sample to reproduce problem

    query = ("""
            import "date"
            import "timezone"
            option location = timezone.location(name: "Europe/Paris")
            from(bucket: "bucket")
            |> range(start: -10m)
            |> filter(fn: (r) => r._measurement == "devices")
            |> filter(fn: (r) =>
                r._field == "temperature"
                or r._field == "humidity"
                or r._field == "devEUI"
                or r._field == "deviceName"
            )
            |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
            |> keep(columns: ["_time", "temperature", "humidity", "deviceName"])
            |> sort(columns: ["_time"], desc: false)
             """
    ) 


    csv_result = readerdb_influx.query_csv(query=query,
                                            dialect=Dialect(header=True, 
                                                            delimiter=",", 
                                                            comment_prefix="#", 
                                                            annotations=[],
                                                            date_time_format="RFC3339")
                                            )
    for csv_lines in csv_result:
        print(csv_lines)
        
    result = readerdb_influx.query(query=query)
    for table in result:
        print(table)
        for record in table.records:
            print(record.values)

Expected behavior

_time should been "+0200" timezone and not in "Z"

Actual behavior

['', 'result', 'table', '_time', 'deviceName', 'humidity', 'temperature']
['', '_result', '0', '2023-07-10T08:04:15.983755716Z', 'RHF1S001-008', '61.3828125', '27.49101440429687']
['', '_result', '1', '2023-07-10T08:03:52.513992459Z', 'RHF1S001-009', '61.87109375', '27.437388916015628']
FluxTable() columns: 6, records: 1
{'result': '_result', 'table': 0, '_time': datetime.datetime(2023, 7, 10, 8, 4, 15, 983755, tzinfo=tzutc()), 'deviceName': 'RHF1S001-008', 'humidity': 61.3828125, 'temperature': 27.49101440429687}
FluxTable() columns: 6, records: 1
{'result': '_result', 'table': 1, '_time': datetime.datetime(2023, 7, 10, 8, 3, 52, 513992, tzinfo=tzutc()), 'deviceName': 'RHF1S001-009', 'humidity': 61.87109375, 'temperature': 27.437388916015628}

Additional info

I maybe did something wrong ?

@Siirko Siirko added the bug Something isn't working label Jul 10, 2023
@bednar
Copy link
Contributor

bednar commented Jul 10, 2023

Hi @Siirko,

thanks for using our client.

How looks like the raw output of your query in InfluxDB UI?

Regards

@Siirko
Copy link
Contributor Author

Siirko commented Jul 10, 2023

Hi @Siirko,

thanks for using our client.

How looks like the raw output of your query in InfluxDB UI?

Regards

With a simple request,

import "date"
import "timezone"
option location = timezone.location(name: "Europe/Paris")
from(bucket: "bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r["_measurement"] == "risinghf_uplink")
  |> filter(fn: (r) =>
                r._field == "temperature"
            )
  |> yield(name: "mean")

I got this
image

But using InfluxQL with

> precision rfc3339
> SELECT "temperature" FROM "risinghf_uplink" tz('Europe/Paris')

The time is correctly formatted

@Siirko
Copy link
Contributor Author

Siirko commented Jul 10, 2023

#454 (comment)

from influxdb_client.client.util import date_utils
from influxdb_client.client.util.date_utils import DateHelper
import dateutil.parser
from dateutil import tz

def parse_date(date_string: str):
    return dateutil.parser.parse(date_string).astimezone(tzlocal())

date_utils.date_helper = DateHelper()
date_utils.date_helper.parse_date = parse_date

This helped me to have correct result when using query() function, but not query_csv()

@bednar
Copy link
Contributor

bednar commented Jul 10, 2023

The query_csv returns data as is in InfluxDB response. You have to use your transformation function for datetime columns.

@Siirko
Copy link
Contributor Author

Siirko commented Jul 10, 2023

The query_csv returns data as is in InfluxDB response. You have to use your transformation function for datetime columns.

This is a "tricks", if I understand correctly what does

option location = timezone.location(name: "Europe/Paris")

in a flux query, I shouldn't be doing like I mentionned in previous answer and get correct date format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants