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/12/19 10:50:59 UTC
[iotdb] branch rel/0.13 updated: [To rel/0.13][IOTDB-5236] Fix DeleteData Python API cannot work (#8513)
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
The following commit(s) were added to refs/heads/rel/0.13 by this push:
new 01217a9ec6 [To rel/0.13][IOTDB-5236] Fix DeleteData Python API cannot work (#8513)
01217a9ec6 is described below
commit 01217a9ec6f787e9dc41e3c1bd92b80ac050edf8
Author: Haonan <hh...@outlook.com>
AuthorDate: Mon Dec 19 18:50:53 2022 +0800
[To rel/0.13][IOTDB-5236] Fix DeleteData Python API cannot work (#8513)
---
client-py/iotdb/Session.py | 24 ++++-
client-py/tests/test_delete_data.py | 178 ++++++++++++++++++++++++++++++++++++
2 files changed, 198 insertions(+), 4 deletions(-)
diff --git a/client-py/iotdb/Session.py b/client-py/iotdb/Session.py
index 88af9e8343..17a7c849f1 100644
--- a/client-py/iotdb/Session.py
+++ b/client-py/iotdb/Session.py
@@ -339,13 +339,29 @@ class Session(object):
data_set.close_operation_handle()
return result
- def delete_data(self, paths_list, timestamp):
+ def delete_data(self, paths_list, end_time):
"""
- delete all data <= time in multiple time series
+ delete all data <= end_time in multiple time series
:param paths_list: time series list that the data in.
- :param timestamp: data with time stamp less than or equal to time will be deleted.
+ :param end_time: data with time stamp less than or equal to time will be deleted.
"""
- request = TSDeleteDataReq(self.__session_id, paths_list, timestamp)
+ request = TSDeleteDataReq(self.__session_id, paths_list, -9223372036854775808, end_time)
+ try:
+ status = self.__client.deleteData(request)
+ logger.debug(
+ "delete data from {}, message: {}".format(paths_list, status.message)
+ )
+ except TTransport.TException as e:
+ logger.exception("data deletion fails because: ", e)
+
+ def delete_data_in_range(self, paths_list, start_time, end_time):
+ """
+ delete data >= start_time and data <= end_time in multiple timeseries
+ :param paths_list: time series list that the data in.
+ :param start_time: delete range start time.
+ :param end_time: delete range end time.
+ """
+ request = TSDeleteDataReq(self.__session_id, paths_list, start_time, end_time)
try:
status = self.__client.deleteData(request)
logger.debug(
diff --git a/client-py/tests/test_delete_data.py b/client-py/tests/test_delete_data.py
new file mode 100644
index 0000000000..7e9df9ac7e
--- /dev/null
+++ b/client-py/tests/test_delete_data.py
@@ -0,0 +1,178 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Uncomment the following line to use apache-iotdb module installed by pip3
+
+from iotdb.Session import Session
+from iotdb.IoTDBContainer import IoTDBContainer
+from iotdb.utils.IoTDBConstants import TSDataType
+
+# whether the test has passed
+final_flag = True
+failed_count = 0
+
+
+def test_fail():
+ global failed_count
+ global final_flag
+ final_flag = False
+ failed_count += 1
+
+
+def print_message(message):
+ print("*********")
+ print(message)
+ print("*********")
+
+
+def test_delete_date():
+ with IoTDBContainer("iotdb:dev") as db:
+ db: IoTDBContainer
+ session = Session(db.get_container_host_ip(), db.get_exposed_port(6667))
+ session.open(False)
+ session.execute_non_query_statement("CREATE Storage group root.str_test_01")
+
+ if not session.is_open():
+ print("can't open session")
+ exit(1)
+
+ # insert string records of one device
+ time_list = [1, 2, 3]
+ measurements_list = [
+ ["s_01", "s_02", "s_03"],
+ ["s_01", "s_02", "s_03"],
+ ["s_01", "s_02", "s_03"],
+ ]
+ values_list = [
+ [False, 22, 33],
+ [True, 1, 23],
+ [False, 15, 26],
+ ]
+ data_types_list = [
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ ]
+
+ if (
+ session.insert_records_of_one_device(
+ "root.str_test_01.d_01",
+ time_list,
+ measurements_list,
+ data_types_list,
+ values_list,
+ )
+ < 0
+ ):
+ test_fail()
+ print_message("insert string records of one device failed")
+
+ # insert aligned string record into the database.
+ time_list = [1, 2, 3]
+ measurements_list = [
+ ["s_01", "s_02", "s_03"],
+ ["s_01", "s_02", "s_03"],
+ ["s_01", "s_02", "s_03"],
+ ]
+ values_list = [
+ [False, 22, 33],
+ [True, 1, 23],
+ [False, 15, 26],
+ ]
+ data_types_list = [
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64],
+ ]
+
+ if (
+ session.insert_aligned_records_of_one_device(
+ "root.str_test_01.d_02",
+ time_list,
+ measurements_list,
+ data_types_list,
+ values_list,
+ )
+ < 0
+ ):
+ test_fail()
+ print_message("insert aligned record of one device failed")
+
+ # execute delete data
+ session.delete_data(["root.str_test_01.d_02.s_01", "root.str_test_01.d_02.s_02"], 1)
+
+ # execute raw data query sql statement
+ session_data_set = session.execute_query_statement(
+ "select s_01, s_02 from root.str_test_01.d_02"
+ + " where time >= 1 and time <= 4"
+ )
+ session_data_set.set_fetch_size(1024)
+ expect_count = 2
+ actual_count = 0
+ while session_data_set.has_next():
+ print(session_data_set.next())
+ actual_count += 1
+ session_data_set.close_operation_handle()
+
+ if actual_count != expect_count:
+ test_fail()
+ print_message(
+ "query count mismatch: expect count: "
+ + str(expect_count)
+ + " actual count: "
+ + str(actual_count)
+ )
+ assert actual_count == expect_count
+
+ # execute delete data
+ session.delete_data_in_range(["root.str_test_01.d_02.s_01", "root.str_test_01.d_02.s_02"], 2, 3)
+
+ # execute raw data query sql statement
+ session_data_set = session.execute_query_statement(
+ "select s_01, s_02 from root.str_test_01.d_02"
+ + " where time >= 1 and time <= 4"
+ )
+ session_data_set.set_fetch_size(1024)
+ expect_count = 0
+ actual_count = 0
+ while session_data_set.has_next():
+ print(session_data_set.next())
+ actual_count += 1
+ session_data_set.close_operation_handle()
+
+ if actual_count != expect_count:
+ test_fail()
+ print_message(
+ "query count mismatch: expect count: "
+ + str(expect_count)
+ + " actual count: "
+ + str(actual_count)
+ )
+ assert actual_count == expect_count
+
+ # close session connection.
+ session.close()
+
+
+if final_flag:
+ print("All executions done!!")
+else:
+ print("Some test failed, please have a check")
+ print("failed count: ", failed_count)
+ exit(1)
+