This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new 5dd11ae fix python the session api does not infer the data as correct
type
5dd11ae is described below
commit 5dd11aea35903e9ff7c131cc4b1d01fa33c22203
Author: xiangdong huang <[email protected]>
AuthorDate: Thu Apr 1 14:28:42 2021 +0800
fix python the session api does not infer the data as correct type
---
client-py/src/iotdb/Session.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/client-py/src/iotdb/Session.py b/client-py/src/iotdb/Session.py
index 00186ec..a9c9f07 100644
--- a/client-py/src/iotdb/Session.py
+++ b/client-py/src/iotdb/Session.py
@@ -26,7 +26,7 @@ from .utils.IoTDBConstants import *
from thrift.protocol import TBinaryProtocol, TCompactProtocol
from thrift.transport import TSocket, TTransport
-from .thrift.rpc.TSIService import Client, TSCreateTimeseriesReq,
TSInsertRecordReq, TSInsertTabletReq, \
+from .thrift.rpc.TSIService import Client, TSCreateTimeseriesReq,
TSInsertRecordReq, TSInsertStringRecordReq, TSInsertTabletReq, \
TSExecuteStatementReq, TSOpenSessionReq, TSCreateMultiTimeseriesReq,
TSCloseSessionReq, TSInsertTabletsReq, TSInsertRecordsReq
from .thrift.rpc.ttypes import TSDeleteDataReq, TSProtocolVersion,
TSSetTimeZoneReq
@@ -212,8 +212,8 @@ class Session(object):
def insert_str_record(self, device_id, timestamp, measurements,
string_values):
""" special case for inserting one row of String (TEXT) value """
data_types = [TSDataType.TEXT.value for _ in string_values]
- request = self.gen_insert_record_req(device_id, timestamp,
measurements, data_types, string_values)
- status = self.__client.insertRecord(request)
+ request = self.gen_insert_str_record_req(device_id, timestamp,
measurements, data_types, string_values)
+ status = self.__client.insertStringRecord(request)
print("insert one record to device {} message: {}".format(device_id,
status.message))
def insert_record(self, device_id, timestamp, measurements, data_types,
values):
@@ -292,6 +292,14 @@ class Session(object):
values_in_bytes = Session.value_to_bytes(data_types, values)
return TSInsertRecordReq(self.__session_id, device_id, measurements,
values_in_bytes, timestamp)
+ def gen_insert_str_record_req(self, device_id, timestamp, measurements,
data_types, values):
+ if (len(values) != len(data_types)) or (len(values) !=
len(measurements)):
+ print("length of data types does not equal to length of
values!")
+ # could raise an error here.
+ return
+ values_in_bytes = Session.value_to_bytes(data_types, values)
+ return TSInsertStringRecordReq(self.__session_id, device_id,
measurements, values_in_bytes, timestamp)
+
def gen_insert_records_req(self, device_ids, times, measurements_lst,
types_lst, values_lst):
if (len(device_ids) != len(measurements_lst)) or (len(times) !=
len(types_lst)) or \
(len(device_ids) != len(times)) or (len(times) != len(values_lst)):