You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/04/07 09:37:45 UTC

[iotdb] 02/04: [IoTDB-2837] Add check and sort for NumpyTablet to make sure timestamps are ordered (#5434)

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 5b6485f00b196f00c662bb68bdf4458e3b8efc12
Author: Hang Zhang <34...@users.noreply.github.com>
AuthorDate: Thu Apr 7 14:09:36 2022 +0800

    [IoTDB-2837] Add check and sort for NumpyTablet to make sure timestamps are ordered (#5434)
---
 client-py/README.md                                |  30 +++---
 client-py/SessionAlignedTimeseriesExample.py       |  16 +++-
 client-py/SessionExample.py                        |  48 ++++++++--
 client-py/iotdb/Session.py                         | 104 +++++++++++++++++----
 client-py/iotdb/utils/NumpyTablet.py               |  21 ++++-
 client-py/iotdb/utils/Tablet.py                    |   8 +-
 client-py/tests/tablet_performance_comparison.py   |   8 +-
 client-py/tests/test_aligned_timeseries.py         |  79 +++++++++-------
 client-py/tests/test_session.py                    |  55 ++++++++---
 .../UserGuide/API/Programming-Python-Native-API.md |  30 +++---
 .../UserGuide/API/Programming-Python-Native-API.md |  30 +++---
 testcontainer/src/tool/parser.py                   |   4 +-
 12 files changed, 295 insertions(+), 138 deletions(-)

diff --git a/client-py/README.md b/client-py/README.md
index 65492cfd1f..6c0acd62e7 100644
--- a/client-py/README.md
+++ b/client-py/README.md
@@ -66,8 +66,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
@@ -195,16 +195,16 @@ data_types_ = [
     TSDataType.TEXT,
 ]
 np_values_ = [
-    np.array([False, True, False, True], np.dtype('>?')),
-    np.array([10, 100, 100, 0], np.dtype('>i4')),
-    np.array([11, 11111, 1, 0], np.dtype('>i8')),
-    np.array([1.1, 1.25, 188.1, 0], np.dtype('>f4')),
-    np.array([10011.1, 101.0, 688.25, 6.25], np.dtype('>f8')),
-    np.array(["test01", "test02", "test03", "test04"]),
+  np.array([False, True, False, True], np.dtype(">?")),
+  np.array([10, 100, 100, 0], np.dtype(">i4")),
+  np.array([11, 11111, 1, 0], np.dtype(">i8")),
+  np.array([1.1, 1.25, 188.1, 0], np.dtype(">f4")),
+  np.array([10011.1, 101.0, 688.25, 6.25], np.dtype(">f8")),
+  np.array(["test01", "test02", "test03", "test04"]),
 ]
-np_timestamps_ = np.array([1, 2, 3, 4], np.dtype('>i8'))
+np_timestamps_ = np.array([1, 2, 3, 4], np.dtype(">i8"))
 np_tablet_ = NumpyTablet(
-    "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
+  "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
 )
 session.insert_tablet(np_tablet_)
 ```
@@ -285,8 +285,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 result = session.execute_query_statement("SELECT * FROM root.*")
@@ -311,7 +311,7 @@ class MyTestCase(unittest.TestCase):
 
     def test_something(self):
         with IoTDBContainer() as c:
-            session = Session('localhost', c.get_exposed_port(6667), 'root', 'root')
+            session = Session("localhost", c.get_exposed_port(6667), "root", "root")
             session.open(False)
             result = session.execute_query_statement("SHOW TIMESERIES")
             print(result)
@@ -370,8 +370,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
diff --git a/client-py/SessionAlignedTimeseriesExample.py b/client-py/SessionAlignedTimeseriesExample.py
index a54b169422..0787fe91c3 100644
--- a/client-py/SessionAlignedTimeseriesExample.py
+++ b/client-py/SessionAlignedTimeseriesExample.py
@@ -52,7 +52,11 @@ data_type_lst_ = [
 encoding_lst_ = [TSEncoding.PLAIN for _ in range(len(data_type_lst_))]
 compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))]
 session.create_aligned_time_series(
-    "root.sg_test_01.d_02", measurements_lst_, data_type_lst_, encoding_lst_, compressor_lst_
+    "root.sg_test_01.d_02",
+    measurements_lst_,
+    data_type_lst_,
+    encoding_lst_,
+    compressor_lst_,
 )
 
 # setting more aligned time series once.
@@ -75,7 +79,11 @@ data_type_lst_ = [
 encoding_lst_ = [TSEncoding.PLAIN for _ in range(len(data_type_lst_))]
 compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))]
 session.create_aligned_time_series(
-    "root.sg_test_01.d_02", measurements_lst_, data_type_lst_, encoding_lst_, compressor_lst_
+    "root.sg_test_01.d_02",
+    measurements_lst_,
+    data_type_lst_,
+    encoding_lst_,
+    compressor_lst_,
 )
 
 # delete time series
@@ -108,7 +116,9 @@ data_types_ = [
     TSDataType.DOUBLE,
     TSDataType.TEXT,
 ]
-session.insert_aligned_record("root.sg_test_01.d_02", 1, measurements_, data_types_, values_)
+session.insert_aligned_record(
+    "root.sg_test_01.d_02", 1, measurements_, data_types_, values_
+)
 
 # insert multiple aligned records into database
 measurements_list_ = [
diff --git a/client-py/SessionExample.py b/client-py/SessionExample.py
index e73abbaee0..75897a44fb 100644
--- a/client-py/SessionExample.py
+++ b/client-py/SessionExample.py
@@ -58,7 +58,7 @@ session.create_time_series(
     None,
     {"tag1": "v1"},
     {"description": "v1"},
-    "temperature"
+    "temperature",
 )
 
 # setting multiple time series once.
@@ -105,7 +105,14 @@ compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))]
 tags_lst_ = [{"tag2": "v2"} for _ in range(len(data_type_lst_))]
 attributes_lst_ = [{"description": "v2"} for _ in range(len(data_type_lst_))]
 session.create_multi_time_series(
-    ts_path_lst_, data_type_lst_, encoding_lst_, compressor_lst_, None, tags_lst_, attributes_lst_, None
+    ts_path_lst_,
+    data_type_lst_,
+    encoding_lst_,
+    compressor_lst_,
+    None,
+    tags_lst_,
+    attributes_lst_,
+    None,
 )
 
 # delete time series
@@ -178,19 +185,41 @@ session.insert_tablet(tablet_)
 
 # insert one numpy tablet into the database.
 np_values_ = [
-    np.array([False, True, False, True], np.dtype('>?')),
-    np.array([10, 100, 100, 0], np.dtype('>i4')),
-    np.array([11, 11111, 1, 0], np.dtype('>i8')),
-    np.array([1.1, 1.25, 188.1, 0], np.dtype('>f4')),
-    np.array([10011.1, 101.0, 688.25, 6.25], np.dtype('>f8')),
+    np.array([False, True, False, True], np.dtype(">?")),
+    np.array([10, 100, 100, 0], np.dtype(">i4")),
+    np.array([11, 11111, 1, 0], np.dtype(">i8")),
+    np.array([1.1, 1.25, 188.1, 0], np.dtype(">f4")),
+    np.array([10011.1, 101.0, 688.25, 6.25], np.dtype(">f8")),
     np.array(["test01", "test02", "test03", "test04"]),
 ]
-np_timestamps_ = np.array([1, 2, 3, 4], np.dtype('>i8'))
+np_timestamps_ = np.array([1, 2, 3, 4], np.dtype(">i8"))
 np_tablet_ = NumpyTablet(
     "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
 )
 session.insert_tablet(np_tablet_)
 
+# insert one unsorted numpy tablet into the database.
+np_values_unsorted = [
+    np.array([False, False, False, True, True], np.dtype(">?")),
+    np.array([0, 10, 100, 1000, 10000], np.dtype(">i4")),
+    np.array([1, 11, 111, 1111, 11111], np.dtype(">i8")),
+    np.array([1.1, 1.25, 188.1, 0, 8.999], np.dtype(">f4")),
+    np.array([10011.1, 101.0, 688.25, 6.25, 8, 776], np.dtype(">f8")),
+    np.array(["test09", "test08", "test07", "test06", "test05"]),
+]
+np_timestamps_unsorted = np.array([9, 8, 7, 6, 5], np.dtype(">i8"))
+np_tablet_unsorted = NumpyTablet(
+    "root.sg_test_01.d_02",
+    measurements_,
+    data_types_,
+    np_values_unsorted,
+    np_timestamps_unsorted,
+)
+session.insert_tablet(np_tablet_unsorted)
+print(np_tablet_unsorted.get_timestamps())
+for value in np_tablet_unsorted.get_values():
+    print(value)
+
 # insert multiple tablets into database
 tablet_01 = Tablet(
     "root.sg_test_01.d_01", measurements_, data_types_, values_, [8, 9, 10, 11]
@@ -251,6 +280,9 @@ with session.execute_query_statement(
     while session_data_set.has_next():
         print(session_data_set.next())
 
+# delete storage group
+session.delete_storage_group("root.sg_test_01")
+
 # close session connection.
 session.close()
 
diff --git a/client-py/iotdb/Session.py b/client-py/iotdb/Session.py
index 567fed48d6..819a0dd892 100644
--- a/client-py/iotdb/Session.py
+++ b/client-py/iotdb/Session.py
@@ -110,7 +110,7 @@ class Session(object):
             username=self.__user,
             password=self.__password,
             zoneId=self.__zone_id,
-            configuration={"version": "V_0_13"}
+            configuration={"version": "V_0_13"},
         )
 
         try:
@@ -193,8 +193,17 @@ class Session(object):
 
         return Session.verify_success(status)
 
-    def create_time_series(self, ts_path, data_type, encoding, compressor,
-                           props=None, tags=None, attributes=None, alias=None):
+    def create_time_series(
+        self,
+        ts_path,
+        data_type,
+        encoding,
+        compressor,
+        props=None,
+        tags=None,
+        attributes=None,
+        alias=None,
+    ):
         """
         create single time series
         :param ts_path: String, complete time series path (starts from root)
@@ -210,7 +219,15 @@ class Session(object):
         encoding = encoding.value
         compressor = compressor.value
         request = TSCreateTimeseriesReq(
-            self.__session_id, ts_path, data_type, encoding, compressor, props, tags, attributes, alias
+            self.__session_id,
+            ts_path,
+            data_type,
+            encoding,
+            compressor,
+            props,
+            tags,
+            attributes,
+            alias,
         )
         status = self.__client.createTimeseries(request)
         logger.debug(
@@ -220,7 +237,7 @@ class Session(object):
         return Session.verify_success(status)
 
     def create_aligned_time_series(
-            self, device_id, measurements_lst, data_type_lst, encoding_lst, compressor_lst
+        self, device_id, measurements_lst, data_type_lst, encoding_lst, compressor_lst
     ):
         """
         create aligned time series
@@ -235,7 +252,12 @@ class Session(object):
         compressor_lst = [compressor.value for compressor in compressor_lst]
 
         request = TSCreateAlignedTimeseriesReq(
-            self.__session_id, device_id, measurements_lst, data_type_lst, encoding_lst, compressor_lst
+            self.__session_id,
+            device_id,
+            measurements_lst,
+            data_type_lst,
+            encoding_lst,
+            compressor_lst,
         )
         status = self.__client.createAlignedTimeseries(request)
         logger.debug(
@@ -247,8 +269,15 @@ class Session(object):
         return Session.verify_success(status)
 
     def create_multi_time_series(
-            self, ts_path_lst, data_type_lst, encoding_lst, compressor_lst,
-            props_lst=None, tags_lst=None, attributes_lst=None, alias_lst=None
+        self,
+        ts_path_lst,
+        data_type_lst,
+        encoding_lst,
+        compressor_lst,
+        props_lst=None,
+        tags_lst=None,
+        attributes_lst=None,
+        alias_lst=None,
     ):
         """
         create multiple time series
@@ -266,8 +295,15 @@ class Session(object):
         compressor_lst = [compressor.value for compressor in compressor_lst]
 
         request = TSCreateMultiTimeseriesReq(
-            self.__session_id, ts_path_lst, data_type_lst, encoding_lst, compressor_lst, props_lst, tags_lst,
-            attributes_lst, alias_lst
+            self.__session_id,
+            ts_path_lst,
+            data_type_lst,
+            encoding_lst,
+            compressor_lst,
+            props_lst,
+            tags_lst,
+            attributes_lst,
+            alias_lst,
         )
         status = self.__client.createMultiTimeseries(request)
         logger.debug(
@@ -319,7 +355,7 @@ class Session(object):
             logger.exception("data deletion fails because: ", e)
 
     def insert_str_record(self, device_id, timestamp, measurements, string_values):
-        """ special case for inserting one row of String (TEXT) value """
+        """special case for inserting one row of String (TEXT) value"""
         if type(string_values) == str:
             string_values = [string_values]
         if type(measurements) == str:
@@ -337,8 +373,10 @@ class Session(object):
 
         return Session.verify_success(status)
 
-    def insert_aligned_str_record(self, device_id, timestamp, measurements, string_values):
-        """ special case for inserting one row of String (TEXT) value """
+    def insert_aligned_str_record(
+        self, device_id, timestamp, measurements, string_values
+    ):
+        """special case for inserting one row of String (TEXT) value"""
         if type(string_values) == str:
             string_values = [string_values]
         if type(measurements) == str:
@@ -409,7 +447,9 @@ class Session(object):
 
         return Session.verify_success(status)
 
-    def insert_aligned_record(self, device_id, timestamp, measurements, data_types, values):
+    def insert_aligned_record(
+        self, device_id, timestamp, measurements, data_types, values
+    ):
         """
         insert one row of aligned record into database, if you want improve your performance, please use insertTablet method
             for example a record at time=10086 with three measurements is:
@@ -522,7 +562,12 @@ 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, is_aligned
+            self.__session_id,
+            device_id,
+            measurements,
+            values_in_bytes,
+            timestamp,
+            is_aligned,
         )
 
     def gen_insert_str_record_req(
@@ -537,7 +582,13 @@ class Session(object):
         )
 
     def gen_insert_records_req(
-        self, device_ids, times, measurements_lst, types_lst, values_lst, is_aligned=False
+        self,
+        device_ids,
+        times,
+        measurements_lst,
+        types_lst,
+        values_lst,
+        is_aligned=False,
     ):
         if (
             (len(device_ids) != len(measurements_lst))
@@ -561,7 +612,12 @@ class Session(object):
             value_lst.append(values_in_bytes)
 
         return TSInsertRecordsReq(
-            self.__session_id, device_ids, measurements_lst, value_lst, times, is_aligned
+            self.__session_id,
+            device_ids,
+            measurements_lst,
+            value_lst,
+            times,
+            is_aligned,
         )
 
     def insert_tablet(self, tablet):
@@ -621,7 +677,9 @@ class Session(object):
         insert multiple aligned tablets, tablets are independent to each other
         :param tablet_lst: List of tablets
         """
-        status = self.__client.insertTablets(self.gen_insert_tablets_req(tablet_lst, True))
+        status = self.__client.insertTablets(
+            self.gen_insert_tablets_req(tablet_lst, True)
+        )
         logger.debug("insert multiple tablets, message: {}".format(status.message))
 
         return Session.verify_success(status)
@@ -742,7 +800,13 @@ class Session(object):
         return Session.verify_success(status)
 
     def gen_insert_records_of_one_device_request(
-        self, device_id, times_list, measurements_list, values_list, types_list, is_aligned=False
+        self,
+        device_id,
+        times_list,
+        measurements_list,
+        values_list,
+        types_list,
+        is_aligned=False,
     ):
         binary_value_list = []
         for values, data_types, measurements in zip(
@@ -762,7 +826,7 @@ class Session(object):
             measurements_list,
             binary_value_list,
             times_list,
-            is_aligned
+            is_aligned,
         )
 
     def test_insert_tablet(self, tablet):
diff --git a/client-py/iotdb/utils/NumpyTablet.py b/client-py/iotdb/utils/NumpyTablet.py
index 72a83fee20..8dd8457459 100644
--- a/client-py/iotdb/utils/NumpyTablet.py
+++ b/client-py/iotdb/utils/NumpyTablet.py
@@ -23,9 +23,7 @@ from iotdb.utils.BitMap import BitMap
 
 
 class NumpyTablet(object):
-    def __init__(
-        self, device_id, measurements, data_types, values, timestamps
-    ):
+    def __init__(self, device_id, measurements, data_types, values, timestamps):
         """
         creating a numpy tablet for insertion
           for example, considering device: root.sg1.d1
@@ -41,6 +39,17 @@ class NumpyTablet(object):
         :param values: List of numpy array, the values of each column should be the inner numpy array
         :param timestamps: Numpy array, the timestamps
         """
+        if len(values) > 0 and len(values[0]) != len(timestamps):
+            raise RuntimeError(
+                "Input error! len(timestamps) does not equal to len(values)!"
+            )
+
+        if not NumpyTablet.check_sorted(timestamps):
+            index = timestamps.argsort()
+            timestamps = timestamps[index]
+            for i in range(len(values)):
+                values[i] = values[i][index]
+
         self.__values = values
         self.__timestamps = timestamps
         self.__device_id = device_id
@@ -68,6 +77,12 @@ class NumpyTablet(object):
     def get_device_id(self):
         return self.__device_id
 
+    def get_timestamps(self):
+        return self.__timestamps
+
+    def get_values(self):
+        return self.__values
+
     def get_binary_timestamps(self):
         return self.__timestamps.tobytes()
 
diff --git a/client-py/iotdb/utils/Tablet.py b/client-py/iotdb/utils/Tablet.py
index bf64118905..2f41889f22 100644
--- a/client-py/iotdb/utils/Tablet.py
+++ b/client-py/iotdb/utils/Tablet.py
@@ -23,9 +23,7 @@ from iotdb.utils.BitMap import BitMap
 
 
 class Tablet(object):
-    def __init__(
-        self, device_id, measurements, data_types, values, timestamps
-    ):
+    def __init__(self, device_id, measurements, data_types, values, timestamps):
         """
         creating a tablet for insertion
           for example, considering device: root.sg1.d1
@@ -172,9 +170,7 @@ class Tablet(object):
                         has_none = True
 
             else:
-                raise RuntimeError(
-                    "Unsupported data type:" + str(self.__data_types[i])
-                )
+                raise RuntimeError("Unsupported data type:" + str(self.__data_types[i]))
 
         if has_none:
             for i in range(self.__column_number):
diff --git a/client-py/tests/tablet_performance_comparison.py b/client-py/tests/tablet_performance_comparison.py
index 76d26f8f41..3626e818a8 100644
--- a/client-py/tests/tablet_performance_comparison.py
+++ b/client-py/tests/tablet_performance_comparison.py
@@ -75,9 +75,9 @@ def generate_csv_data(
         if _type == TSDataType.BOOLEAN:
             return [random.randint(0, 1) == 1 for _ in range(_row)]
         elif _type == TSDataType.INT32:
-            return [random.randint(-(2 ** 31), 2 ** 31) for _ in range(_row)]
+            return [random.randint(-(2**31), 2**31) for _ in range(_row)]
         elif _type == TSDataType.INT64:
-            return [random.randint(-(2 ** 63), 2 ** 63) for _ in range(_row)]
+            return [random.randint(-(2**63), 2**63) for _ in range(_row)]
         elif _type == TSDataType.FLOAT:
             return [1.5 for _ in range(_row)]
         elif _type == TSDataType.DOUBLE:
@@ -208,9 +208,7 @@ def performance_test(
                 for m in measurements:
                     value_array.append(csv_data.at[t, m])
                 values.append(value_array)
-            tablet = Tablet(
-                device_id, measurements, data_types, values, timestamps_
-            )
+            tablet = Tablet(device_id, measurements, data_types, values, timestamps_)
         else:
             # Use the NEW method to construct numpy tablet
             timestamps_ = csv_data[TIME_STR].values
diff --git a/client-py/tests/test_aligned_timeseries.py b/client-py/tests/test_aligned_timeseries.py
index 3e6126d4d5..ef57af5f59 100644
--- a/client-py/tests/test_aligned_timeseries.py
+++ b/client-py/tests/test_aligned_timeseries.py
@@ -78,7 +78,11 @@ def test_aligned_timeseries():
         encoding_lst_ = [TSEncoding.PLAIN for _ in range(len(data_type_lst_))]
         compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))]
         session.create_aligned_time_series(
-            "root.sg_test_01.d_02", measurements_lst_, data_type_lst_, encoding_lst_, compressor_lst_
+            "root.sg_test_01.d_02",
+            measurements_lst_,
+            data_type_lst_,
+            encoding_lst_,
+            compressor_lst_,
         )
 
         # setting more aligned time series once.
@@ -101,19 +105,23 @@ def test_aligned_timeseries():
         encoding_lst_ = [TSEncoding.PLAIN for _ in range(len(data_type_lst_))]
         compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))]
         session.create_aligned_time_series(
-            "root.sg_test_01.d_02", measurements_lst_, data_type_lst_, encoding_lst_, compressor_lst_
+            "root.sg_test_01.d_02",
+            measurements_lst_,
+            data_type_lst_,
+            encoding_lst_,
+            compressor_lst_,
         )
 
         # delete time series
         if (
-                session.delete_time_series(
-                    [
-                        "root.sg_test_01.d_02.s_07",
-                        "root.sg_test_01.d_02.s_08",
-                        "root.sg_test_01.d_02.s_09",
-                    ]
-                )
-                < 0
+            session.delete_time_series(
+                [
+                    "root.sg_test_01.d_02.s_07",
+                    "root.sg_test_01.d_02.s_08",
+                    "root.sg_test_01.d_02.s_09",
+                ]
+            )
+            < 0
         ):
             test_fail()
             print_message("delete time series failed")
@@ -141,10 +149,10 @@ def test_aligned_timeseries():
             TSDataType.TEXT,
         ]
         if (
-                session.insert_aligned_record(
-                    "root.sg_test_01.d_02", 1, measurements_, data_types_, values_
-                )
-                < 0
+            session.insert_aligned_record(
+                "root.sg_test_01.d_02", 1, measurements_, data_types_, values_
+            )
+            < 0
         ):
             test_fail()
             print_message("insert record failed")
@@ -161,10 +169,10 @@ def test_aligned_timeseries():
         data_type_list_ = [data_types_, data_types_]
         device_ids_ = ["root.sg_test_01.d_02", "root.sg_test_01.d_02"]
         if (
-                session.insert_aligned_records(
-                    device_ids_, [2, 3], measurements_list_, data_type_list_, values_list_
-                )
-                < 0
+            session.insert_aligned_records(
+                device_ids_, [2, 3], measurements_list_, data_type_list_, values_list_
+            )
+            < 0
         ):
             test_fail()
             print_message("insert records failed")
@@ -189,7 +197,11 @@ def test_aligned_timeseries():
             "root.sg_test_01.d_02", measurements_, data_types_, values_, [8, 9, 10, 11]
         )
         tablet_02 = Tablet(
-            "root.sg_test_01.d_02", measurements_, data_types_, values_, [12, 13, 14, 15]
+            "root.sg_test_01.d_02",
+            measurements_,
+            data_types_,
+            values_,
+            [12, 13, 14, 15],
         )
         if session.insert_aligned_tablets([tablet_01, tablet_02]) < 0:
             test_fail()
@@ -225,24 +237,24 @@ def test_aligned_timeseries():
         values_list = [[False, 22, 33], [True, 1, 23], [False, 15, 26]]
 
         if (
-                session.insert_aligned_records_of_one_device(
-                    "root.sg_test_01.d_02",
-                    time_list,
-                    measurements_list,
-                    data_types_list,
-                    values_list,
-                )
-                < 0
+            session.insert_aligned_records_of_one_device(
+                "root.sg_test_01.d_02",
+                time_list,
+                measurements_list,
+                data_types_list,
+                values_list,
+            )
+            < 0
         ):
             test_fail()
             print_message("insert records of one device failed")
 
         # execute non-query sql statement
         if (
-                session.execute_non_query_statement(
-                    "insert into root.sg_test_01.d_02(timestamp, s_02) aligned values(16, 188)"
-                )
-                < 0
+            session.execute_non_query_statement(
+                "insert into root.sg_test_01.d_02(timestamp, s_02) aligned values(16, 188)"
+            )
+            < 0
         ):
             test_fail()
             print_message(
@@ -250,7 +262,9 @@ def test_aligned_timeseries():
             )
 
         # execute sql query statement
-        session_data_set = session.execute_query_statement("select * from root.sg_test_01.d_02")
+        session_data_set = session.execute_query_statement(
+            "select * from root.sg_test_01.d_02"
+        )
         session_data_set.set_fetch_size(1024)
         expect_count = 20
         actual_count = 0
@@ -271,6 +285,7 @@ def test_aligned_timeseries():
         # close session connection.
         session.close()
 
+
 if final_flag:
     print("All executions done!!")
 else:
diff --git a/client-py/tests/test_session.py b/client-py/tests/test_session.py
index c526af34e9..6ecd14205c 100644
--- a/client-py/tests/test_session.py
+++ b/client-py/tests/test_session.py
@@ -69,13 +69,22 @@ def test_session():
 
         # setting time series.
         session.create_time_series(
-            "root.sg_test_01.d_01.s_01", TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY
+            "root.sg_test_01.d_01.s_01",
+            TSDataType.BOOLEAN,
+            TSEncoding.PLAIN,
+            Compressor.SNAPPY,
         )
         session.create_time_series(
-            "root.sg_test_01.d_01.s_02", TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY
+            "root.sg_test_01.d_01.s_02",
+            TSDataType.INT32,
+            TSEncoding.PLAIN,
+            Compressor.SNAPPY,
         )
         session.create_time_series(
-            "root.sg_test_01.d_01.s_03", TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY
+            "root.sg_test_01.d_01.s_03",
+            TSDataType.INT64,
+            TSEncoding.PLAIN,
+            Compressor.SNAPPY,
         )
         session.create_time_series(
             "root.sg_test_01.d_02.s_01",
@@ -85,7 +94,7 @@ def test_session():
             None,
             {"tag1": "v1"},
             {"description": "v1"},
-            "temperature"
+            "temperature",
         )
 
         # setting multiple time series once.
@@ -131,7 +140,14 @@ def test_session():
         tags_lst_ = [{"tag2": "v2"} for _ in range(len(data_type_lst_))]
         attributes_lst_ = [{"description": "v2"} for _ in range(len(data_type_lst_))]
         session.create_multi_time_series(
-            ts_path_lst_, data_type_lst_, encoding_lst_, compressor_lst_, None, tags_lst_, attributes_lst_, None
+            ts_path_lst_,
+            data_type_lst_,
+            encoding_lst_,
+            compressor_lst_,
+            None,
+            tags_lst_,
+            attributes_lst_,
+            None,
         )
 
         # delete time series
@@ -225,16 +241,20 @@ def test_session():
 
         # insert one numpy tablet into the database.
         np_values_ = [
-            np.array([False, True, False, True], np.dtype('>?')),
-            np.array([10, 100, 100, 0], np.dtype('>i4')),
-            np.array([11, 11111, 1, 0], np.dtype('>i8')),
-            np.array([1.1, 1.25, 188.1, 0], np.dtype('>f4')),
-            np.array([10011.1, 101.0, 688.25, 6.25], np.dtype('>f8')),
+            np.array([False, True, False, True], np.dtype(">?")),
+            np.array([10, 100, 100, 0], np.dtype(">i4")),
+            np.array([11, 11111, 1, 0], np.dtype(">i8")),
+            np.array([1.1, 1.25, 188.1, 0], np.dtype(">f4")),
+            np.array([10011.1, 101.0, 688.25, 6.25], np.dtype(">f8")),
             np.array(["test01", "test02", "test03", "test04"]),
         ]
-        np_timestamps_ = np.array([1, 2, 3, 4], np.dtype('>i8'))
+        np_timestamps_ = np.array([1, 2, 3, 4], np.dtype(">i8"))
         np_tablet_ = NumpyTablet(
-            "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
+            "root.sg_test_01.d_02",
+            measurements_,
+            data_types_,
+            np_values_,
+            np_timestamps_,
         )
         if session.insert_tablet(np_tablet_) < 0:
             test_fail()
@@ -245,7 +265,11 @@ def test_session():
             "root.sg_test_01.d_01", measurements_, data_types_, values_, [8, 9, 10, 11]
         )
         tablet_02 = Tablet(
-            "root.sg_test_01.d_01", measurements_, data_types_, values_, [12, 13, 14, 15]
+            "root.sg_test_01.d_01",
+            measurements_,
+            data_types_,
+            values_,
+            [12, 13, 14, 15],
         )
         if session.insert_tablets([tablet_01, tablet_02]) < 0:
             test_fail()
@@ -306,7 +330,9 @@ def test_session():
             )
 
         # execute sql query statement
-        session_data_set = session.execute_query_statement("select * from root.sg_test_01.d_01")
+        session_data_set = session.execute_query_statement(
+            "select * from root.sg_test_01.d_01"
+        )
         session_data_set.set_fetch_size(1024)
         expect_count = 20
         actual_count = 0
@@ -327,6 +353,7 @@ def test_session():
         # close session connection.
         session.close()
 
+
 if final_flag:
     print("All executions done!!")
 else:
diff --git a/docs/UserGuide/API/Programming-Python-Native-API.md b/docs/UserGuide/API/Programming-Python-Native-API.md
index 6d07c0b451..c167af2ea4 100644
--- a/docs/UserGuide/API/Programming-Python-Native-API.md
+++ b/docs/UserGuide/API/Programming-Python-Native-API.md
@@ -46,8 +46,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
@@ -175,16 +175,16 @@ data_types_ = [
     TSDataType.TEXT,
 ]
 np_values_ = [
-    np.array([False, True, False, True], np.dtype('>?')),
-    np.array([10, 100, 100, 0], np.dtype('>i4')),
-    np.array([11, 11111, 1, 0], np.dtype('>i8')),
-    np.array([1.1, 1.25, 188.1, 0], np.dtype('>f4')),
-    np.array([10011.1, 101.0, 688.25, 6.25], np.dtype('>f8')),
-    np.array(["test01", "test02", "test03", "test04"]),
+  np.array([False, True, False, True], np.dtype(">?")),
+  np.array([10, 100, 100, 0], np.dtype(">i4")),
+  np.array([11, 11111, 1, 0], np.dtype(">i8")),
+  np.array([1.1, 1.25, 188.1, 0], np.dtype(">f4")),
+  np.array([10011.1, 101.0, 688.25, 6.25], np.dtype(">f8")),
+  np.array(["test01", "test02", "test03", "test04"]),
 ]
-np_timestamps_ = np.array([1, 2, 3, 4], np.dtype('>i8'))
+np_timestamps_ = np.array([1, 2, 3, 4], np.dtype(">i8"))
 np_tablet_ = NumpyTablet(
-    "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
+  "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
 )
 session.insert_tablet(np_tablet_)
 ```
@@ -265,8 +265,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 result = session.execute_query_statement("SELECT * FROM root.*")
@@ -291,7 +291,7 @@ class MyTestCase(unittest.TestCase):
 
     def test_something(self):
         with IoTDBContainer() as c:
-            session = Session('localhost', c.get_exposed_port(6667), 'root', 'root')
+            session = Session("localhost", c.get_exposed_port(6667), "root", "root")
             session.open(False)
             result = session.execute_query_statement("SHOW TIMESERIES")
             print(result)
@@ -350,8 +350,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
diff --git a/docs/zh/UserGuide/API/Programming-Python-Native-API.md b/docs/zh/UserGuide/API/Programming-Python-Native-API.md
index ab05e6ff49..f32c8d4aa5 100644
--- a/docs/zh/UserGuide/API/Programming-Python-Native-API.md
+++ b/docs/zh/UserGuide/API/Programming-Python-Native-API.md
@@ -44,8 +44,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
@@ -175,16 +175,16 @@ data_types_ = [
     TSDataType.TEXT,
 ]
 np_values_ = [
-    np.array([False, True, False, True], np.dtype('>?')),
-    np.array([10, 100, 100, 0], np.dtype('>i4')),
-    np.array([11, 11111, 1, 0], np.dtype('>i8')),
-    np.array([1.1, 1.25, 188.1, 0], np.dtype('>f4')),
-    np.array([10011.1, 101.0, 688.25, 6.25], np.dtype('>f8')),
-    np.array(["test01", "test02", "test03", "test04"]),
+  np.array([False, True, False, True], np.dtype(">?")),
+  np.array([10, 100, 100, 0], np.dtype(">i4")),
+  np.array([11, 11111, 1, 0], np.dtype(">i8")),
+  np.array([1.1, 1.25, 188.1, 0], np.dtype(">f4")),
+  np.array([10011.1, 101.0, 688.25, 6.25], np.dtype(">f8")),
+  np.array(["test01", "test02", "test03", "test04"]),
 ]
-np_timestamps_ = np.array([1, 2, 3, 4], np.dtype('>i8'))
+np_timestamps_ = np.array([1, 2, 3, 4], np.dtype(">i8"))
 np_tablet_ = NumpyTablet(
-    "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
+  "root.sg_test_01.d_02", measurements_, data_types_, np_values_, np_timestamps_
 )
 session.insert_tablet(np_tablet_)
 ```
@@ -261,8 +261,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 result = session.execute_query_statement("SELECT ** FROM root")
@@ -287,7 +287,7 @@ class MyTestCase(unittest.TestCase):
 
     def test_something(self):
         with IoTDBContainer() as c:
-            session = Session('localhost', c.get_exposed_port(6667), 'root', 'root')
+            session = Session("localhost", c.get_exposed_port(6667), "root", "root")
             session.open(False)
             result = session.execute_query_statement("SHOW TIMESERIES")
             print(result)
@@ -339,8 +339,8 @@ from iotdb.Session import Session
 
 ip = "127.0.0.1"
 port_ = "6667"
-username_ = 'root'
-password_ = 'root'
+username_ = "root"
+password_ = "root"
 session = Session(ip, port_, username_, password_)
 session.open(False)
 zone = session.get_time_zone()
diff --git a/testcontainer/src/tool/parser.py b/testcontainer/src/tool/parser.py
index 96d50ac5df..5cee0a85a0 100644
--- a/testcontainer/src/tool/parser.py
+++ b/testcontainer/src/tool/parser.py
@@ -20,7 +20,7 @@ import os
 import sys
 import re
 
-pattern = re.compile(r'docker\-java\-stream\-+(\d+)')
+pattern = re.compile(r"docker\-java\-stream\-+(\d+)")
 
 
 def getAllLogs(filename):
@@ -76,4 +76,4 @@ if __name__ == "__main__":
             output(nodes, i)
             count = count + 1
 
-    print("find {} failed tests".format(count))
\ No newline at end of file
+    print("find {} failed tests".format(count))