You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2020/11/26 09:55:44 UTC

[iotdb] 02/02: refactor python client structure

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

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

commit 3e79958550d30851ae46f4d94ec4858bb3bb0dd6
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Thu Nov 26 17:52:14 2020 +0800

    refactor python client structure
---
 client-py/compile.bat                              | 29 --------------
 client-py/compile.sh                               | 28 -------------
 client-py/pom.xml                                  |  4 +-
 client-py/pypi/README.md                           | 34 ++++++++++------
 client-py/readme.md                                | 46 +++++++++++++---------
 client-py/src/SessionExample.py                    | 14 +------
 client-py/src/__init__.py                          | 18 ---------
 client-py/src/{ => iotdb}/Session.py               | 16 +++-----
 client-py/src/iotdb/__init__.py                    |  0
 client-py/src/{ => iotdb}/utils/Field.py           |  0
 client-py/src/{ => iotdb}/utils/IoTDBConstants.py  |  0
 client-py/src/{ => iotdb}/utils/IoTDBRpcDataSet.py |  2 +-
 client-py/src/{ => iotdb}/utils/RowRecord.py       |  0
 client-py/src/{ => iotdb}/utils/SessionDataSet.py  |  0
 client-py/src/{ => iotdb}/utils/Tablet.py          |  0
 client-py/src/{ => iotdb}/utils/__init__.py        |  0
 pom.xml                                            |  2 +-
 thrift/src/main/thrift/cluster.thrift              |  1 +
 thrift/src/main/thrift/rpc.thrift                  |  1 +
 thrift/src/main/thrift/sync.thrift                 |  1 +
 20 files changed, 63 insertions(+), 133 deletions(-)

diff --git a/client-py/compile.bat b/client-py/compile.bat
deleted file mode 100644
index 7b8532f..0000000
--- a/client-py/compile.bat
+++ /dev/null
@@ -1,29 +0,0 @@
-@REM
-@REM Licensed to the Apache Software Foundation (ASF) under one
-@REM or more contributor license agreements.  See the NOTICE file
-@REM distributed with this work for additional information
-@REM regarding copyright ownership.  The ASF licenses this file
-@REM to you under the Apache License, Version 2.0 (the
-@REM "License"); you may not use this file except in compliance
-@REM with the License.  You may obtain a copy of the License at
-@REM
-@REM     http://www.apache.org/licenses/LICENSE-2.0
-@REM
-@REM Unless required by applicable law or agreed to in writing,
-@REM software distributed under the License is distributed on an
-@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-@REM KIND, either express or implied.  See the License for the
-@REM specific language governing permissions and limitations
-@REM under the License.
-@REM
-
-@echo off
-set THRIFT_EXE=D:\software\Thrift\thrift-0.13.0.exe
-set BAT_DIR=%~dp0
-set THRIFT_SCRIPT=%BAT_DIR%..\thrift\src\main\thrift\rpc.thrift
-set THRIFT_OUT=%BAT_DIR%target\iotdb
-
-rmdir /Q /S %THRIFT_OUT%
-mkdir -p %THRIFT_OUT%
-
-%THRIFT_EXE% -gen py -out %THRIFT_OUT%  %THRIFT_SCRIPT%
diff --git a/client-py/compile.sh b/client-py/compile.sh
deleted file mode 100644
index 63426c6..0000000
--- a/client-py/compile.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-export THRIFT_EXE=thrift
-export SH_DIR=$(dirname $0)/
-export THRIFT_SCRIPT=${SH_DIR}../thrift/src/main/thrift/rpc.thrift
-export THRIFT_OUT=${SH_DIR}target/iotdb
-
-rm -rf ${THRIFT_OUT}
-mkdir -p ${THRIFT_OUT}
-${THRIFT_EXE} -gen py -out ${THRIFT_OUT}  ${THRIFT_SCRIPT}
diff --git a/client-py/pom.xml b/client-py/pom.xml
index 267a68a..8921a87 100644
--- a/client-py/pom.xml
+++ b/client-py/pom.xml
@@ -57,7 +57,7 @@
                         </goals>
                         <configuration>
                             <encoding>utf-8</encoding>
-                            <outputDirectory>${project.build.directory}/pypi/iotdb_session</outputDirectory>
+                            <outputDirectory>${project.build.directory}/pypi/</outputDirectory>
                             <resources>
                                 <resource>
                                     <directory>${basedir}/../thrift/target/generated-sources-python</directory>
@@ -94,7 +94,7 @@
                         </goals>
                         <configuration>
                             <encoding>utf-8</encoding>
-                            <outputDirectory>${project.build.directory}/pypi/iotdb_session</outputDirectory>
+                            <outputDirectory>${project.build.directory}/pypi/</outputDirectory>
                             <resources>
                                 <resource>
                                     <directory>${basedir}/src/</directory>
diff --git a/client-py/pypi/README.md b/client-py/pypi/README.md
index 590aac8..dc7182c 100644
--- a/client-py/pypi/README.md
+++ b/client-py/pypi/README.md
@@ -32,11 +32,11 @@
 [![IoTDB Website](https://img.shields.io/website-up-down-green-red/https/shields.io.svg?label=iotdb-website)](https://iotdb.apache.org/)
 
 
-Apache IoTDB (incubating) (Database for Internet of Things) is an integrated data management engine designed for
-timeseries data. It provides users with services for data collection, storage and analysis. Due to its light-weight
-architecture, high performance and rich feature set together with its deep integration with Apache Hadoop and Spark,
-Apache IoTDB (incubating) can meet the requirements of massive data storage, high-speed data ingestion and complex data
-analysis in the IoT industrial fields.
+Apache IoTDB (Database for Internet of Things) is an IoT native database with high performance for 
+data management and analysis, deployable on the edge and the cloud. Due to its light-weight 
+architecture, high performance and rich feature set together with its deep integration with 
+Apache Hadoop, Spark and Flink, Apache IoTDB can meet the requirements of massive data storage, 
+high-speed data ingestion and complex data analysis in the IoT industrial fields.
 
 
 # Apache IoTDB Python Client API
@@ -51,15 +51,23 @@ You have to install thrift (>=0.13) before using the package.
 
 First, download the package: `pip3 install apache-iotdb`
 
-You can get an example of using the package to read and write data at here: [Example](https://github.com/apache/iotdb/blob/rel/0.10/client-py/src/SessionExample.py)
+You can get an example of using the package to read and write data at here: [Example](https://github.com/apache/iotdb/blob/rel/0.11/client-py/src/SessionExample.py)
 
 (you need to add `import iotdb` in the head of the file)
 
-# DISCLAIMER
+Or:
 
-Apache IoTDB is an effort undergoing incubation at The Apache Software Foundation (ASF).
-Incubation is required of all newly accepted projects until a further review indicates that the
-infrastructure, communications, and decision making process have stabilized in a manner consistent
-with other successful ASF projects. While incubation status is not necessarily a reflection of the
-completeness or stability of the code, it does indicate that the project has yet to be fully
-endorsed by the ASF.
\ No newline at end of file
+```python
+
+from iotdb.Session import Session
+
+ip = "127.0.0.1"
+port_ = "6667"
+username_ = 'root'
+password_ = 'root'
+session = Session(ip, port_, username_, password_)
+session.open(False)
+zone = session.get_time_zone()
+session.close()
+
+```
\ No newline at end of file
diff --git a/client-py/readme.md b/client-py/readme.md
index abdcb7f..113a334 100644
--- a/client-py/readme.md
+++ b/client-py/readme.md
@@ -33,29 +33,39 @@ tutorial of installation, eventually, you should have a thrift executable.
 http://thrift.apache.org/docs/install/
 ```
 
-## Compile the thrift library
-If you have added Thrift executable into your path, you may just run `client-py/compile.sh` or
- `client-py\compile.bat`, or you will have to modify it to set variable `THRIFT_EXE` to point to
-your executable. This will generate thrift sources under folder `target`, you can add it to your
-`PYTHONPATH` so that you would be able to use the library in your code. Notice that the scripts
-locate the thrift source file by relative path, so if you move the scripts else where, they are
-no longer valid.
-
-Optionally, if you know the basic usage of thrift, you can only download the thrift source file in
-`thrift\src\main\thrift\rpc.thrift`, and simply use `thrift -gen py -out ./target/iotdb rpc.thrift` 
-to generate the python library.
+## Compile the thrift library and Debug
+
+In the root of IoTDB's source code folder,  run `mvn generate-sources -pl client-py -am`.
+
+Then a complete project will be generated at `client-py/target/pypi` folder. 
+But !BE CAUTIOUS!
+All your modifications in `client-py/target/pypi` must be copied manually to `client-py/src/` folder.
+Otherwise once you run `mvn clean`, you will lose all your effort.
+
+Or, you can also copy `client-py/target/pypi/iotdb/thrift` folder to `client-py/src/thrift`, then the 
+`src` folder will become also a complete python project. 
+But !BE CAUTIOUS!
+Do not upload `client-py/src/thrift` to the git repo.
+
 
 ## Session Client & Example
-We packed up the Thrift interface in `client-py/src/Session.py` (similar with its Java counterpart), also provided 
+We packed up the Thrift interface in `client-py/src/iotdb/Session.py` (similar with its Java counterpart), also provided 
 an example file `client-py/src/SessionExample.py` of how to use the session module. please read it carefully.
 
-## How to Debug
 
-To debug the python API module, run `mvn generate-sources -pl thrift,client-py`
+Or, another simple example:
 
-Then, go to target/pypi to get the complete projects.
+```$python
 
-But !BE CAUTIOUS!
-All your modifications in target/pypi must be copied manually to src/ folder.
-Otherwise once you run `mvn clean`, you will lose all your effort.
+from iotdb.Session import Session
+
+ip = "127.0.0.1"
+port_ = "6667"
+username_ = 'root'
+password_ = 'root'
+session = Session(ip, port_, username_, password_)
+session.open(False)
+zone = session.get_time_zone()
+session.close()
 
+```
\ No newline at end of file
diff --git a/client-py/src/SessionExample.py b/client-py/src/SessionExample.py
index 35e57bd..9eac78f 100644
--- a/client-py/src/SessionExample.py
+++ b/client-py/src/SessionExample.py
@@ -16,20 +16,10 @@
 # under the License.
 #
 
-import sys
 # Uncomment the following line to use apache-iotdb module installed by pip3
 
-# for debug
-# sys.path.append("./utils")
-# from IoTDBConstants import *
-# from Tablet import Tablet
-# from Session import Session
-
-# for package
-from iotdb_session.utils.IoTDBConstants import *
-from iotdb_session.utils.Tablet import Tablet
-from iotdb_session.Session import Session
-
+from iotdb.Session import Session
+from iotdb.utils import Tablet
 
 # creating session connection.
 ip = "127.0.0.1"
diff --git a/client-py/src/__init__.py b/client-py/src/__init__.py
deleted file mode 100644
index a4797b6..0000000
--- a/client-py/src/__init__.py
+++ /dev/null
@@ -1,18 +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.
-#
-
diff --git a/client-py/src/Session.py b/client-py/src/iotdb/Session.py
similarity index 97%
rename from client-py/src/Session.py
rename to client-py/src/iotdb/Session.py
index 1fe8e41..839ba95 100644
--- a/client-py/src/Session.py
+++ b/client-py/src/iotdb/Session.py
@@ -16,24 +16,18 @@
 # under the License.
 #
 
-import sys
 import struct
+import sys
 import time
 
-#sys.path.append("../../thrift/target/generated-sources-python")
-sys.path.append("./utils")
-
-# for package
-from .utils.IoTDBConstants import *
-from .utils.SessionDataSet import SessionDataSet
+from .utils import SessionDataSet
 
 from thrift.protocol import TBinaryProtocol, TCompactProtocol
 from thrift.transport import TSocket, TTransport
 
-from .iotdb.rpc.TSIService import Client, TSCreateTimeseriesReq, TSInsertRecordReq, TSInsertTabletReq, \
-     TSExecuteStatementReq, TSOpenSessionReq, TSQueryDataSet, TSFetchResultsReq, TSCloseOperationReq, \
-     TSCreateMultiTimeseriesReq, TSCloseSessionReq, TSInsertTabletsReq, TSInsertRecordsReq
-from .iotdb.rpc.ttypes import TSDeleteDataReq, TSProtocolVersion, TSSetTimeZoneReq
+from .thrift.rpc.TSIService import Client, TSCreateTimeseriesReq, TSInsertRecordReq, TSInsertTabletReq, \
+     TSExecuteStatementReq, TSOpenSessionReq, TSCreateMultiTimeseriesReq, TSCloseSessionReq, TSInsertTabletsReq, TSInsertRecordsReq
+from .thrift.rpc.ttypes import TSDeleteDataReq, TSProtocolVersion, TSSetTimeZoneReq
 
 # for debug
 # from IoTDBConstants import *
diff --git a/client-py/src/iotdb/__init__.py b/client-py/src/iotdb/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/client-py/src/utils/Field.py b/client-py/src/iotdb/utils/Field.py
similarity index 100%
rename from client-py/src/utils/Field.py
rename to client-py/src/iotdb/utils/Field.py
diff --git a/client-py/src/utils/IoTDBConstants.py b/client-py/src/iotdb/utils/IoTDBConstants.py
similarity index 100%
rename from client-py/src/utils/IoTDBConstants.py
rename to client-py/src/iotdb/utils/IoTDBConstants.py
diff --git a/client-py/src/utils/IoTDBRpcDataSet.py b/client-py/src/iotdb/utils/IoTDBRpcDataSet.py
similarity index 99%
rename from client-py/src/utils/IoTDBRpcDataSet.py
rename to client-py/src/iotdb/utils/IoTDBRpcDataSet.py
index 6aa2fa3..21c2f0e 100644
--- a/client-py/src/utils/IoTDBRpcDataSet.py
+++ b/client-py/src/iotdb/utils/IoTDBRpcDataSet.py
@@ -28,7 +28,7 @@ path = dirname(dirname(abspath(__file__)))
 sys.path.append(path)
 
 from thrift.transport import TTransport
-from iotdb.rpc.TSIService import TSFetchResultsReq, TSCloseOperationReq
+from iotdb.thrift.rpc.TSIService import TSFetchResultsReq, TSCloseOperationReq
 
 
 class IoTDBRpcDataSet(object):
diff --git a/client-py/src/utils/RowRecord.py b/client-py/src/iotdb/utils/RowRecord.py
similarity index 100%
rename from client-py/src/utils/RowRecord.py
rename to client-py/src/iotdb/utils/RowRecord.py
diff --git a/client-py/src/utils/SessionDataSet.py b/client-py/src/iotdb/utils/SessionDataSet.py
similarity index 100%
rename from client-py/src/utils/SessionDataSet.py
rename to client-py/src/iotdb/utils/SessionDataSet.py
diff --git a/client-py/src/utils/Tablet.py b/client-py/src/iotdb/utils/Tablet.py
similarity index 100%
rename from client-py/src/utils/Tablet.py
rename to client-py/src/iotdb/utils/Tablet.py
diff --git a/client-py/src/utils/__init__.py b/client-py/src/iotdb/utils/__init__.py
similarity index 100%
rename from client-py/src/utils/__init__.py
rename to client-py/src/iotdb/utils/__init__.py
diff --git a/pom.xml b/pom.xml
index fd734d4..999dc91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -997,7 +997,7 @@
                                     <generator>py</generator>
                                     <thriftExecutable>${thrift.exec.absolute.path}</thriftExecutable>
                                     <thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot>
-                                    <outputDirectory>${project.build.directory}/generated-sources-python/iotdb</outputDirectory>
+                                    <outputDirectory>${project.build.directory}/generated-sources-python/</outputDirectory>
                                 </configuration>
                             </execution>
                             <execution>
diff --git a/thrift/src/main/thrift/cluster.thrift b/thrift/src/main/thrift/cluster.thrift
index a85e090..6e96d86 100644
--- a/thrift/src/main/thrift/cluster.thrift
+++ b/thrift/src/main/thrift/cluster.thrift
@@ -19,6 +19,7 @@
 
 include "rpc.thrift"
 namespace java org.apache.iotdb.cluster.rpc.thrift
+namespace py iotdb.thrift.cluster
 
 typedef i32 int 
 typedef i16 short
diff --git a/thrift/src/main/thrift/rpc.thrift b/thrift/src/main/thrift/rpc.thrift
index 7b83144..4f412bf 100644
--- a/thrift/src/main/thrift/rpc.thrift
+++ b/thrift/src/main/thrift/rpc.thrift
@@ -17,6 +17,7 @@
  * under the License.
  */
 namespace java org.apache.iotdb.service.rpc.thrift
+namespace py iotdb.thrift.rpc
 
 // The return status code and message in each response.
 struct TSStatus {
diff --git a/thrift/src/main/thrift/sync.thrift b/thrift/src/main/thrift/sync.thrift
index 3e243f4..2c67353 100755
--- a/thrift/src/main/thrift/sync.thrift
+++ b/thrift/src/main/thrift/sync.thrift
@@ -17,6 +17,7 @@
  * under the License.
  */
 namespace java org.apache.iotdb.service.sync.thrift
+namespace py iotdb.thrift.sync
 
 struct SyncStatus{
   1:required i32 code