1- import json
2- import urllib .parse
1+ import urllib .parse , json
32import pyarrow as pa
43from influxdb_client import InfluxDBClient as _InfluxDBClient , WriteOptions , Point
54from influxdb_client .client .write_api import WriteApi as _WriteApi , SYNCHRONOUS , ASYNCHRONOUS , PointSettings
65from influxdb_client .domain .write_precision import WritePrecision
76from influxdb_client .client .exceptions import InfluxDBError
87from pyarrow .flight import FlightClient , Ticket , FlightCallOptions
9- from influxdb_client_3 .read_file import upload_file
8+ from influxdb_client_3 .read_file import UploadFile
109
1110
1211def write_client_options (** kwargs ):
12+ """
13+ Function for providing additional arguments for the WriteApi client.
14+
15+ :param kwargs: Additional arguments for the WriteApi client.
16+ :return: dict with the arguments.
17+ """
1318 return kwargs
1419
1520def default_client_options (** kwargs ):
1621 return kwargs
1722
1823def flight_client_options (** kwargs ):
19- return kwargs # You can replace this with a specific data structure if needed
24+ """
25+ Function for providing additional arguments for the FlightClient.
26+
27+ :param kwargs: Additional arguments for the FlightClient.
28+ :return: dict with the arguments.
29+ """
30+ return kwargs
31+
32+ def file_parser_options (** kwargs ):
33+ """
34+ Function for providing additional arguments for the file parser.
35+
36+ :param kwargs: Additional arguments for the file parser.
37+ :return: dict with the arguments.
38+ """
39+ return kwargs
2040
2141
2242class InfluxDBClient3 :
@@ -40,13 +60,13 @@ def __init__(
4060 :type database: str
4161 :param token: The authentication token for accessing the InfluxDB server.
4262 :type token: str
43- :param write_client_options: Options for the WriteAPI .
44- :type write_client_options: dict
45- :param flight_client_options: Options for the FlightClient.
46- :type flight_client_options: dict
63+ :param write_client_options: Function for providing additional arguments for the WriteApi client .
64+ :type write_client_options: callable
65+ :param flight_client_options: Function for providing additional arguments for the FlightClient.
66+ :type flight_client_options: callable
4767 :param kwargs: Additional arguments for the InfluxDB Client.
4868 """
49- self ._org = org
69+ self ._org = org if org is not None else "default"
5070 self ._database = database
5171 self ._token = token
5272 self ._write_client_options = write_client_options if write_client_options is not None else default_client_options (write_options = SYNCHRONOUS )
@@ -72,7 +92,9 @@ def write(self, record=None, database=None ,**kwargs):
7292 Write data to InfluxDB.
7393
7494 :param record: The data point(s) to write.
75- :type record: Point or list of Point objects
95+ :type record: object or list of objects
96+ :param database: The database to write to. If not provided, uses the database provided during initialization.
97+ :type database: str
7698 :param kwargs: Additional arguments to pass to the write API.
7799 """
78100 if database is None :
@@ -84,7 +106,7 @@ def write(self, record=None, database=None ,**kwargs):
84106 raise e
85107
86108
87- def write_file (self , file , measurement_name = None , tag_columns = None , timestamp_column = 'time' , database = None , ** kwargs ):
109+ def write_file (self , file , measurement_name = None , tag_columns = None , timestamp_column = 'time' , database = None , file_parser_options = None , ** kwargs ):
88110 """
89111 Write data from a file to InfluxDB.
90112
@@ -96,13 +118,17 @@ def write_file(self, file, measurement_name=None, tag_columns=None, timestamp_co
96118 :type tag_columns: list
97119 :param timestamp_column: Timestamp column name. Defaults to 'time'.
98120 :type timestamp_column: str
121+ :param database: The database to write to. If not provided, uses the database provided during initialization.
122+ :type database: str
123+ :param file_parser_options: Function for providing additional arguments for the file parser.
124+ :type file_parser_options: callable
99125 :param kwargs: Additional arguments to pass to the write API.
100126 """
101127 if database is None :
102128 database = self ._database
103129
104130 try :
105- table = upload_file (file ).load_file ()
131+ table = UploadFile (file , file_parser_options ).load_file ()
106132 df = table .to_pandas () if isinstance (table , pa .Table ) else table
107133 self ._process_dataframe (df , measurement_name , tag_columns or [], timestamp_column , database = database , ** kwargs )
108134 except Exception as e :
@@ -138,10 +164,13 @@ def query(self, query, language="sql", mode="all", database=None, **kwargs ):
138164
139165 :param query: The query string.
140166 :type query: str
141- :param language: The query language (default is "sql").
167+ :param language: The query language; "sql" or "influxql" (default is "sql").
142168 :type language: str
143169 :param mode: The mode of fetching data (all, pandas, chunk, reader, schema).
144170 :type mode: str
171+ :param database: The database to query from. If not provided, uses the database provided during initialization.
172+ :type database: str
173+ :param kwargs: Additional arguments for the query.
145174 :return: The queried data.
146175 """
147176 if database is None :
@@ -188,5 +217,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
188217 "WritePrecision" ,
189218 "WriteOptions" ,
190219 "write_client_options" ,
191- "flight_client_options"
220+ "flight_client_options" ,
221+ "file_parser_options"
192222]
0 commit comments