You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/09/25 13:34:53 UTC
[incubator-iotdb] 01/01: temp save
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch py_client
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit cbcfd4606cdf8d4d78418fbb33f875006e06b873
Author: jt <jt...@163.com>
AuthorDate: Wed Sep 25 21:23:46 2019 +0800
temp save
---
.gitignore | 3 +-
client-py/compile.bat | 9 ++++++
client-py/src/client_example.py | 63 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 6691ce4..18a7508 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,4 +85,5 @@ grafana/data/test.csv
tsfile/src/test/resources/*.ts
### Apache release ###
-local-snapshots-dir/
\ No newline at end of file
+local-snapshots-dir/
+venv/
diff --git a/client-py/compile.bat b/client-py/compile.bat
new file mode 100644
index 0000000..19cea30
--- /dev/null
+++ b/client-py/compile.bat
@@ -0,0 +1,9 @@
+@echo off
+set THRIFT_EXE=C:\bin\thrift-0.12.0.exe
+set BAT_DIR=%~dp0
+set THRIFT_SCRIPT=%BAT_DIR%..\service-rpc\src\main\thrift\rpc.thrift
+set THRIFT_OUT=%BAT_DIR%target
+
+rm -rf %THRIFT_OUT%
+mkdir %THRIFT_OUT%
+%THRIFT_EXE% -gen py -out %THRIFT_OUT% %THRIFT_SCRIPT%
diff --git a/client-py/src/client_example.py b/client-py/src/client_example.py
new file mode 100644
index 0000000..0ac43d8
--- /dev/null
+++ b/client-py/src/client_example.py
@@ -0,0 +1,63 @@
+# 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.
+#
+
+import sys, struct
+sys.path.append("../target")
+
+from thrift.protocol import TBinaryProtocol
+from thrift.transport import TSocket, TTransport
+
+from rpc.TSIService import Client, TSCreateTimeseriesReq, TSInsertionReq, TSBatchInsertionReq, TSExecuteStatementReq,\
+ TS_SessionHandle, TSHandleIdentifier, TSOpenSessionReq, TSQueryDataSet
+if __name__ == '__main__':
+ # Make socket
+ transport = TSocket.TSocket("localhost", "6667")
+
+ # Buffering is critical. Raw sockets are very slow
+ transport = TTransport.TBufferedTransport(transport)
+
+ # Wrap in a protocol
+ protocol = TBinaryProtocol.TBinaryProtocol(transport)
+
+ # Create a client to use the protocol encoder
+ client = Client(protocol)
+
+ # Connect!
+ transport.open()
+
+ client.openSession(TSOpenSessionReq(username='root', password='root'))
+
+ handle = TS_SessionHandle(TSHandleIdentifier(b'1', b'1'))
+
+ client.setStorageGroup("root.group1")
+ client.createTimeseries(TSCreateTimeseriesReq("root.group1.s1", 2, 0, 0))
+ client.createTimeseries(TSCreateTimeseriesReq("root.group1.s2", 2, 0, 0))
+ client.createTimeseries(TSCreateTimeseriesReq("root.group1.s3", 2, 0, 0))
+
+ client.insertRow(TSInsertionReq("root.group1", ["s1", "s2", "s3"], ["1", "11", "111"], 1, 1))
+
+ values = bytearray()
+ times = bytearray()
+ values.extend(struct.pack('<qqqqqqqqq', 2, 3, 4, 22, 33, 44, 222, 333, 444))
+ times.extend(struct.pack('<qqq', 2, 3, 4))
+ client.insertBatch(TSBatchInsertionReq("root.group1", ["s1", "s2", "s3"], values, times, [2, 2, 2], 3))
+
+ rst = client.executeQueryStatement(TSExecuteStatementReq(handle, "SELECT * FROM root.group1"))
+ print rst
+
+