This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch Deprecate_template_apis in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 6ee99f27db51b84ebc494c9c886ef4b5ea232788 Author: HTHou <[email protected]> AuthorDate: Wed Jul 24 10:47:04 2024 +0800 Deprecate template apis --- iotdb-client/client-py/SessionExample.py | 28 ------ iotdb-client/client-py/iotdb/Session.py | 67 +++++++++++++ .../client-py/iotdb/template/InternalNode.py | 41 -------- iotdb-client/client-py/tests/test_template.py | 110 --------------------- 4 files changed, 67 insertions(+), 179 deletions(-) diff --git a/iotdb-client/client-py/SessionExample.py b/iotdb-client/client-py/SessionExample.py index d7223b16146..c489fe7d03d 100644 --- a/iotdb-client/client-py/SessionExample.py +++ b/iotdb-client/client-py/SessionExample.py @@ -20,8 +20,6 @@ import numpy as np from iotdb.Session import Session -from iotdb.template.MeasurementNode import MeasurementNode -from iotdb.template.Template import Template from iotdb.utils.BitMap import BitMap from iotdb.utils.IoTDBConstants import TSDataType, TSEncoding, Compressor from iotdb.utils.Tablet import Tablet @@ -365,32 +363,6 @@ with session.execute_last_data_query( # delete database session.delete_storage_group("root.sg_test_01") -# create template -template = Template(name="template_python", share_time=False) -m_node_1 = MeasurementNode( - name="s1", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, -) -m_node_2 = MeasurementNode( - name="s2", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, -) -m_node_3 = MeasurementNode( - name="s3", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, -) -template.add_template(m_node_1) -template.add_template(m_node_2) -template.add_template(m_node_3) -session.create_schema_template(template) -print("create template success template_python") - # close session connection. session.close() diff --git a/iotdb-client/client-py/iotdb/Session.py b/iotdb-client/client-py/iotdb/Session.py index 0a3bf41b224..5aca06c2781 100644 --- a/iotdb-client/client-py/iotdb/Session.py +++ b/iotdb-client/client-py/iotdb/Session.py @@ -20,6 +20,7 @@ import logging import random import struct import time +import warnings from thrift.protocol import TBinaryProtocol, TCompactProtocol from thrift.transport import TSocket, TTransport @@ -60,6 +61,7 @@ from .thrift.rpc.ttypes import ( from .utils.IoTDBConnectionException import IoTDBConnectionException logger = logging.getLogger("IoTDB") +warnings.simplefilter("always", DeprecationWarning) class Session(object): @@ -1810,6 +1812,11 @@ class Session(object): return request def create_schema_template(self, template: Template): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ create device template, users using this method should use the template class as an argument :param template: The template contains multiple child node(see Template.py) @@ -1833,6 +1840,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def drop_schema_template(self, template_name: str): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ drop device template, this method should be used to the template unset anything :param template_name: template name @@ -1861,6 +1873,11 @@ class Session(object): compressors: list, is_aligned: bool = False, ): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ add measurements in the template, the template must already create. This function adds some measurements' node. :param template_name: template name, string list, like ["name_x", "name_y", "name_z"] @@ -1895,6 +1912,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def delete_node_in_template(self, template_name: str, path: str): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ delete a node in the template, this node must be already in the template :param template_name: template name @@ -1916,6 +1938,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def set_schema_template(self, template_name, prefix_path): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ set template in prefix path, template already exit, prefix path is not measurements :param template_name: template name @@ -1937,6 +1964,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def unset_schema_template(self, template_name, prefix_path): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ unset device template from prefix path, this method unsetting the template from entities, which have already inserted records using the template, is not supported. @@ -1961,6 +1993,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def count_measurements_in_template(self, template_name: str): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ drop device template, this method should be used to the template unset anything :param template_name: template name @@ -1986,6 +2023,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def is_measurement_in_template(self, template_name: str, path: str): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ judge the node in the template is measurement or not, this node must in the template :param template_name: template name @@ -2014,6 +2056,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def is_path_exist_in_template(self, template_name: str, path: str): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ judge whether the node is a measurement or not in the template, this node must be in the template :param template_name: template name @@ -2039,6 +2086,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def show_measurements_in_template(self, template_name: str, pattern: str = ""): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ show all measurements under the pattern in template :param template_name: template name @@ -2067,6 +2119,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def show_all_templates(self): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ show all device templates """ @@ -2092,6 +2149,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def show_paths_template_set_on(self, template_name): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ show the path prefix where a device template is set :param template_name: @@ -2116,6 +2178,11 @@ class Session(object): raise IoTDBConnectionException(self.connection_error_msg()) from None def show_paths_template_using_on(self, template_name): + warnings.warn( + "The APIs about template are deprecated and will be removed in future versions. Use sql instead.", + DeprecationWarning, + stacklevel=2, + ) """ show the path prefix where a device template is used :param template_name: diff --git a/iotdb-client/client-py/iotdb/template/InternalNode.py b/iotdb-client/client-py/iotdb/template/InternalNode.py deleted file mode 100644 index bac17ca90ab..00000000000 --- a/iotdb-client/client-py/iotdb/template/InternalNode.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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. -# - -from .TemplateNode import TemplateNode - - -class InternalNode(TemplateNode): - def __init__(self, name, share_time): - super().__init__(name) - self.children = {} - self.share_time = share_time - - def add_child(self, node: TemplateNode): - if node.get_name() in self.children.keys(): - assert "Duplicated child of node in template." - - self.children.update({node.get_name(): node}) - - def delete_child(self, node): - self.children.pop(node.get_name(), None) - - def get_children(self): - return self.children - - def is_share_time(self): - return self.share_time diff --git a/iotdb-client/client-py/tests/test_template.py b/iotdb-client/client-py/tests/test_template.py deleted file mode 100644 index 1b58bcdee1b..00000000000 --- a/iotdb-client/client-py/tests/test_template.py +++ /dev/null @@ -1,110 +0,0 @@ -# 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. -# -from iotdb.IoTDBContainer import IoTDBContainer -from iotdb.Session import Session -from iotdb.template.InternalNode import InternalNode -from iotdb.template.MeasurementNode import MeasurementNode -from iotdb.template.Template import Template -from iotdb.utils.IoTDBConstants import TSDataType, Compressor, TSEncoding - - -def test_template_create(): - with IoTDBContainer("iotdb:dev") as db: - db: IoTDBContainer - session = Session(db.get_container_host_ip(), db.get_exposed_port(6667)) - session.open(False) - - measurement_template_name = "template_python" - template = Template(name=measurement_template_name, share_time=False) - m_node_1 = MeasurementNode( - name="s1", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, - ) - m_node_2 = MeasurementNode( - name="s2", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, - ) - m_node_3 = MeasurementNode( - name="s3", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, - ) - template.add_template(m_node_1) - template.add_template(m_node_2) - template.add_template(m_node_3) - session.create_schema_template(template) - - assert session.show_measurements_in_template(measurement_template_name) == [ - "s3", - "s1", - "s2", - ] - - session.drop_schema_template(measurement_template_name) - - session.close() - - -def test_set_template(): - with IoTDBContainer("iotdb:dev") as db: - db: IoTDBContainer - session = Session(db.get_container_host_ip(), db.get_exposed_port(6667)) - session.open(False) - - template_name = "set_template_python" - template = Template(name=template_name, share_time=False) - m_node_x = MeasurementNode( - name="x", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, - ) - m_node_y = MeasurementNode( - name="y", - data_type=TSDataType.INT64, - encoding=TSEncoding.RLE, - compression_type=Compressor.SNAPPY, - ) - template.add_template(m_node_x) - template.add_template(m_node_y) - session.create_schema_template(template) - - session.execute_non_query_statement("CREATE DATABASE root.python") - - session.set_schema_template(template_name, "root.python.GPS") - session.execute_non_query_statement( - "create timeseries of device template on root.python.GPS" - ) - - assert session.show_paths_template_set_on(template_name) == ["root.python.GPS"] - assert session.show_paths_template_using_on(template_name) == [ - "root.python.GPS" - ] - - session.execute_non_query_statement( - "delete timeseries of device template from root.python.GPS" - ) - - session.unset_schema_template(template_name, "root.python.GPS") - session.drop_schema_template(template_name) - session.close()
