8
8
import csv
9
9
from datetime import datetime , timedelta
10
10
from typing import List , Generator , Any
11
- from pytz import UTC
12
11
13
12
from influxdb_client import Dialect , IntegerLiteral , BooleanLiteral , FloatLiteral , DateTimeLiteral , StringLiteral , \
14
13
VariableAssignment , Identifier , OptionStatement , File , DurationLiteral , Duration , UnaryExpression
15
14
from influxdb_client import Query , QueryService
16
15
from influxdb_client .client .flux_csv_parser import FluxCsvParser , FluxSerializationMode
17
16
from influxdb_client .client .flux_table import FluxTable , FluxRecord
17
+ from influxdb_client .client .util .date_utils import get_date_helper
18
18
19
19
20
20
class QueryApi (object ):
@@ -101,7 +101,7 @@ def query_stream(self, query: str, org=None, params: dict = None) -> Generator['
101
101
if org is None :
102
102
org = self ._influxdb_client .org
103
103
104
- response = self ._query_api .post_query (org = org , query = self ._create_query (query , self .default_dialect ),
104
+ response = self ._query_api .post_query (org = org , query = self ._create_query (query , self .default_dialect , params ),
105
105
async_req = False , _preload_content = False , _return_http_data_only = False )
106
106
107
107
_parser = FluxCsvParser (response = response , serialization_mode = FluxSerializationMode .stream )
@@ -165,6 +165,8 @@ def _params_to_extern_ast(params: dict) -> List['OptionStatement']:
165
165
166
166
statements = []
167
167
for key , value in params .items ():
168
+ if value is None :
169
+ continue
168
170
169
171
if isinstance (value , bool ):
170
172
literal = BooleanLiteral ("BooleanLiteral" , value )
@@ -173,10 +175,7 @@ def _params_to_extern_ast(params: dict) -> List['OptionStatement']:
173
175
elif isinstance (value , float ):
174
176
literal = FloatLiteral ("FloatLiteral" , value )
175
177
elif isinstance (value , datetime ):
176
- if not value .tzinfo :
177
- value = UTC .localize (value )
178
- else :
179
- value = value .astimezone (UTC )
178
+ value = get_date_helper ().to_utc (value )
180
179
literal = DateTimeLiteral ("DateTimeLiteral" , value .strftime ('%Y-%m-%dT%H:%M:%S.%fZ' ))
181
180
elif isinstance (value , timedelta ):
182
181
# convert to microsecodns
0 commit comments