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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8df0c79df6a Deprecate template APIs in Python SDK (#13009)
8df0c79df6a is described below

commit 8df0c79df6a927e16380b0b2bda456ad54de0c42
Author: Haonan <[email protected]>
AuthorDate: Wed Jul 24 11:18:40 2024 +0800

    Deprecate template APIs in Python SDK (#13009)
---
 iotdb-client/client-py/README.md                   |  89 +----------------
 iotdb-client/client-py/SessionExample.py           |  28 ------
 iotdb-client/client-py/iotdb/Session.py            |  67 +++++++++++++
 .../client-py/iotdb/template/InternalNode.py       |  41 --------
 .../client-py/iotdb/template/MeasurementNode.py    |   9 ++
 iotdb-client/client-py/iotdb/template/Template.py  |   8 ++
 .../client-py/iotdb/template/TemplateNode.py       |   8 ++
 iotdb-client/client-py/tests/test_template.py      | 110 ---------------------
 8 files changed, 94 insertions(+), 266 deletions(-)

diff --git a/iotdb-client/client-py/README.md b/iotdb-client/client-py/README.md
index cc23ebff2a3..8c6192834cc 100644
--- a/iotdb-client/client-py/README.md
+++ b/iotdb-client/client-py/README.md
@@ -312,91 +312,6 @@ session.execute_non_query_statement(sql)
 session.execute_statement(sql)
 ```
 
-### Device Template
-#### Create Device Template
-The step for creating a metadata template is as follows
-1. Create the template class
-2. Adding child Node,InternalNode and MeasurementNode can be chose
-3. Execute create device template function
-
-```python
-template = Template(name=template_name, share_time=True)
-
-i_node_gps = InternalNode(name="GPS", share_time=False)
-i_node_v = InternalNode(name="vehicle", share_time=True)
-m_node_x = MeasurementNode("x", TSDataType.FLOAT, TSEncoding.RLE, 
Compressor.SNAPPY)
-
-i_node_gps.add_child(m_node_x)
-i_node_v.add_child(m_node_x)
-
-template.add_template(i_node_gps)
-template.add_template(i_node_v)
-template.add_template(m_node_x)
-
-session.create_schema_template(template)
-```
-#### Modify Device Template nodes
-Modify nodes in a template, the template must be already created. These are 
functions that add or delete some measurement nodes.
-* add node in template
-```python
-session.add_measurements_in_template(template_name, measurements_path, 
data_types, encodings, compressors, is_aligned)
-```
-
-* delete node in template
-```python
-session.delete_node_in_template(template_name, path)
-```
-
-#### Set Device Template
-```python
-session.set_schema_template(template_name, prefix_path)
-```
-
-#### Uset Device Template
-```python
-session.unset_schema_template(template_name, prefix_path)
-```
-
-#### Show Device Template
-* Show all device templates
-```python
-session.show_all_templates()
-```
-* Count all nodes in templates
-```python
-session.count_measurements_in_template(template_name)
-```
-
-* Judge whether the path is measurement or not in templates, This measurement 
must be in the template
-```python
-session.count_measurements_in_template(template_name, path)
-```
-
-* Judge whether the path is exist or not in templates, This path may not 
belong to the template
-```python
-session.is_path_exist_in_template(template_name, path)
-```
-
-* Show nodes under in device template
-```python
-session.show_measurements_in_template(template_name)
-```
-
-* Show the path prefix where a device template is set
-```python
-session.show_paths_template_set_on(template_name)
-```
-
-* Show the path prefix where a device template is used (i.e. the time series 
has been created)
-```python
-session.show_paths_template_using_on(template_name)
-```
-
-#### Drop Device Template
-Delete an existing metadata template,dropping an already set template is not 
supported
-```python
-session.drop_schema_template("template_python")
-```
 
 
 ### Pandas Support
@@ -601,9 +516,9 @@ This is an example of how to connect to IoTDB with python, 
using the thrift rpc
 
 ### Prerequisites
 
-Python3.7 or later is preferred.
+Python3.6 or later is preferred.
 
-You have to install Thrift (0.11.0 or later) to compile our thrift file into 
python code. Below is the official tutorial of installation, eventually, you 
should have a thrift executable.
+You have to install Thrift (0.14.1 or later) to compile our thrift file into 
python code. Below is the official tutorial of installation, eventually, you 
should have a thrift executable.
 
 ```
 http://thrift.apache.org/docs/install/
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/iotdb/template/MeasurementNode.py 
b/iotdb-client/client-py/iotdb/template/MeasurementNode.py
index 7d96d4bc0d3..9c2de7a45b8 100644
--- a/iotdb-client/client-py/iotdb/template/MeasurementNode.py
+++ b/iotdb-client/client-py/iotdb/template/MeasurementNode.py
@@ -15,13 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+import warnings
 
 from iotdb.utils.IoTDBConstants import TSDataType, TSEncoding, Compressor
 from .TemplateNode import TemplateNode
 from ..tsfile.utils.ReadWriteIOUtils import ReadWriteUtils
 
+warnings.simplefilter("always", DeprecationWarning)
+
 
 class MeasurementNode(TemplateNode):
+
     def __init__(
         self,
         name: str,
@@ -29,6 +33,11 @@ class MeasurementNode(TemplateNode):
         encoding: TSEncoding,
         compression_type: Compressor,
     ):
+        warnings.warn(
+            "The APIs about template are deprecated and will be removed in 
future versions. Use sql instead.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
         self.name = name
         self.data_type = data_type
         self.encoding = encoding
diff --git a/iotdb-client/client-py/iotdb/template/Template.py 
b/iotdb-client/client-py/iotdb/template/Template.py
index 38f883d03fb..0c226c7cb6d 100644
--- a/iotdb-client/client-py/iotdb/template/Template.py
+++ b/iotdb-client/client-py/iotdb/template/Template.py
@@ -17,15 +17,23 @@
 #
 
 import struct
+import warnings
 
 from .TemplateNode import TemplateNode
 from ..tsfile.common.constant.TsFileConstant import TsFileConstant
 from ..tsfile.utils.Pair import Pair
 from ..tsfile.utils.ReadWriteIOUtils import ReadWriteUtils
 
+warnings.simplefilter("always", DeprecationWarning)
+
 
 class Template:
     def __init__(self, name, share_time: bool = False):
+        warnings.warn(
+            "The APIs about template are deprecated and will be removed in 
future versions. Use sql instead.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
         self.name = name
         self.children = dict()
         self.share_time = share_time
diff --git a/iotdb-client/client-py/iotdb/template/TemplateNode.py 
b/iotdb-client/client-py/iotdb/template/TemplateNode.py
index fb2372842e0..27552e005b8 100644
--- a/iotdb-client/client-py/iotdb/template/TemplateNode.py
+++ b/iotdb-client/client-py/iotdb/template/TemplateNode.py
@@ -15,6 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+import warnings
+
+warnings.simplefilter("always", DeprecationWarning)
 
 
 class TemplateNode(object):
@@ -23,6 +26,11 @@ class TemplateNode(object):
     """
 
     def __init__(self, name):
+        warnings.warn(
+            "The APIs about template are deprecated and will be removed in 
future versions. Use sql instead.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
         self.name = name
 
     def get_name(self):
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()

Reply via email to