Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate template APIs in Python SDK #13009

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 2 additions & 87 deletions iotdb-client/client-py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down
28 changes: 0 additions & 28 deletions iotdb-client/client-py/SessionExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -365,32 +363,6 @@
# 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()

Expand Down
67 changes: 67 additions & 0 deletions iotdb-client/client-py/iotdb/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import random
import struct
import time
import warnings
from thrift.protocol import TBinaryProtocol, TCompactProtocol
from thrift.transport import TSocket, TTransport

Expand Down Expand Up @@ -60,6 +61,7 @@
from .utils.IoTDBConnectionException import IoTDBConnectionException

logger = logging.getLogger("IoTDB")
warnings.simplefilter("always", DeprecationWarning)


class Session(object):
Expand Down Expand Up @@ -1810,6 +1812,11 @@ def gen_insert_string_records_of_one_device_request(
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)
Expand All @@ -1833,6 +1840,11 @@ def create_schema_template(self, template: Template):
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
Expand Down Expand Up @@ -1861,6 +1873,11 @@ def add_measurements_in_template(
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"]
Expand Down Expand Up @@ -1895,6 +1912,11 @@ def add_measurements_in_template(
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
Expand All @@ -1916,6 +1938,11 @@ def delete_node_in_template(self, template_name: str, path: str):
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
Expand All @@ -1937,6 +1964,11 @@ def set_schema_template(self, template_name, prefix_path):
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.
Expand All @@ -1961,6 +1993,11 @@ def unset_schema_template(self, template_name, prefix_path):
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
Expand All @@ -1986,6 +2023,11 @@ def count_measurements_in_template(self, template_name: str):
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
Expand Down Expand Up @@ -2014,6 +2056,11 @@ def is_measurement_in_template(self, template_name: str, path: str):
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
Expand All @@ -2039,6 +2086,11 @@ def is_path_exist_in_template(self, template_name: str, path: str):
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
Expand Down Expand Up @@ -2067,6 +2119,11 @@ def show_measurements_in_template(self, template_name: str, pattern: str = ""):
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
"""
Expand All @@ -2092,6 +2149,11 @@ def show_all_templates(self):
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:
Expand All @@ -2116,6 +2178,11 @@ def show_paths_template_set_on(self, template_name):
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:
Expand Down
41 changes: 0 additions & 41 deletions iotdb-client/client-py/iotdb/template/InternalNode.py

This file was deleted.

9 changes: 9 additions & 0 deletions iotdb-client/client-py/iotdb/template/MeasurementNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,29 @@
# 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,
data_type: TSDataType,
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
Expand Down
Loading
Loading