2828from iotdb .tsfile .utils .tsblock_serde import deserialize
2929from iotdb .utils .exception import IoTDBConnectionException
3030from iotdb .utils .IoTDBConstants import TSDataType
31- from iotdb .utils .rpc_utils import verify_success
31+ from iotdb .utils .rpc_utils import verify_success , convert_to_timestamp
3232
3333logger = logging .getLogger ("IoTDB" )
3434TIMESTAMP_STR = "Time"
@@ -41,7 +41,6 @@ def __init__(
4141 sql ,
4242 column_name_list ,
4343 column_type_list ,
44- column_name_index ,
4544 ignore_timestamp ,
4645 more_data ,
4746 query_id ,
@@ -51,6 +50,8 @@ def __init__(
5150 query_result ,
5251 fetch_size ,
5352 time_out ,
53+ zone_id ,
54+ time_precision ,
5455 column_index_2_tsblock_column_index_list ,
5556 ):
5657 self .__statement_id = statement_id
@@ -117,6 +118,8 @@ def __init__(
117118 self .__empty_resultSet = False
118119 self .has_cached_data_frame = False
119120 self .data_frame = None
121+ self .__zone_id = zone_id
122+ self .__time_precision = time_precision
120123
121124 def close (self ):
122125 if self .__is_closed :
@@ -155,7 +158,7 @@ def next(self):
155158
156159 def construct_one_data_frame (self ):
157160 if self .has_cached_data_frame or self .__query_result is None :
158- return True
161+ return
159162 result = {}
160163 has_pd_series = []
161164 for i in range (len (self .__column_index_2_tsblock_column_index_list )):
@@ -264,8 +267,8 @@ def result_set_to_pandas(self):
264267 continue
265268 data_type = self .__data_type_for_tsblock_column [location ]
266269 column_array = column_arrays [location ]
267- # BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TIMESTAMP, BLOB
268- if data_type in (0 , 1 , 2 , 3 , 4 , 8 , 10 ):
270+ # BOOLEAN, INT32, INT64, FLOAT, DOUBLE, BLOB
271+ if data_type in (0 , 1 , 2 , 3 , 4 , 10 ):
269272 data_array = column_array
270273 if (
271274 data_type != 10
@@ -278,6 +281,17 @@ def result_set_to_pandas(self):
278281 # TEXT, STRING
279282 elif data_type in (5 , 11 ):
280283 data_array = np .array ([x .decode ("utf-8" ) for x in column_array ])
284+ # TIMESTAMP
285+ elif data_type == 8 :
286+ data_array = pd .Series (
287+ [
288+ convert_to_timestamp (
289+ x , self .__time_precision , self .__zone_id
290+ )
291+ for x in column_array
292+ ],
293+ dtype = object ,
294+ )
281295 # DATE
282296 elif data_type == 9 :
283297 data_array = pd .Series (column_array ).apply (parse_int_to_date )
@@ -289,25 +303,21 @@ def result_set_to_pandas(self):
289303 data_type == 0 and null_indicator is not None
290304 ):
291305 tmp_array = []
292- # BOOLEAN, INT32, INT64, TIMESTAMP
293- if (
294- data_type == 0
295- or data_type == 1
296- or data_type == 2
297- or data_type == 8
298- ):
306+ # BOOLEAN, INT32, INT64
307+ if data_type == 0 or data_type == 1 or data_type == 2 :
299308 tmp_array = np .full (array_length , pd .NA , dtype = object )
300309 # FLOAT, DOUBLE
301310 elif data_type == 3 or data_type == 4 :
302311 tmp_array = np .full (
303312 array_length , np .nan , dtype = data_type .np_dtype ()
304313 )
305- # TEXT, STRING, BLOB, DATE
314+ # TEXT, STRING, BLOB, DATE, TIMESTAMP
306315 elif (
307316 data_type == 5
308317 or data_type == 11
309318 or data_type == 10
310319 or data_type == 9
320+ or data_type == 8
311321 ):
312322 tmp_array = np .full (array_length , None , dtype = object )
313323
@@ -320,7 +330,7 @@ def result_set_to_pandas(self):
320330
321331 if data_type == 1 :
322332 tmp_array = pd .Series (tmp_array ).astype ("Int32" )
323- elif data_type == 2 or data_type == 8 :
333+ elif data_type == 2 :
324334 tmp_array = pd .Series (tmp_array ).astype ("Int64" )
325335 elif data_type == 0 :
326336 tmp_array = pd .Series (tmp_array ).astype ("boolean" )
0 commit comments