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/12/10 07:38:33 UTC
[incubator-iotdb] branch master updated: Python example next (#636)
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new b70fcc5 Python example next (#636)
b70fcc5 is described below
commit b70fcc554b4a9ea7c8754d5c4fa6410cae55951f
Author: Jackie Tien <Ja...@foxmail.com>
AuthorDate: Tue Dec 10 15:38:24 2019 +0800
Python example next (#636)
* upgrade python-example
---
client-py/compile.bat | 4 +-
client-py/compile.sh | 4 +-
client-py/src/client_example.py | 78 ++++++++++++++--------
.../org/apache/iotdb/session/SessionDataSet.java | 1 +
4 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/client-py/compile.bat b/client-py/compile.bat
index a9081c0..a8de20e 100644
--- a/client-py/compile.bat
+++ b/client-py/compile.bat
@@ -21,8 +21,8 @@
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
+set THRIFT_OUT=%BAT_DIR%target\iotdb
rm -rf %THRIFT_OUT%
-mkdir %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
index 628ca82..93b107c 100644
--- a/client-py/compile.sh
+++ b/client-py/compile.sh
@@ -21,8 +21,8 @@
export THRIFT_EXE=thrift
export SH_DIR=$(dirname $0)/
export THRIFT_SCRIPT=${SH_DIR}../service-rpc/src/main/thrift/rpc.thrift
-export THRIFT_OUT=${SH_DIR}target
+export THRIFT_OUT=${SH_DIR}target/iotdb
rm -rf ${THRIFT_OUT}
-mkdir ${THRIFT_OUT}
+mkdir -p ${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
index 8749d74..397d0e4 100644
--- a/client-py/src/client_example.py
+++ b/client-py/src/client_example.py
@@ -60,12 +60,27 @@ Compressor = {
'PLA': 6
}
+# used to do `and` operation with bitmap to judge whether the value is null
+flag = 0x80
+
+INT32_BYTE_LEN = 4
+BOOL_BYTE_LEN = 1
+INT64_BYTE_LEN = 8
+FLOAT_BYTE_LEN = 4
+DOUBLE_BYTE_LEN = 8
+
+
+def is_null(bitmap_bytes, rowNum):
+ bitmap = bitmap_bytes[rowNum // 8]
+ shift = rowNum % 8
+ return ((flag >> shift) & bitmap) == 0
+
def convertQueryDataSet(queryDataSet, dataTypeList):
- bytes = queryDataSet.values
- row_count = queryDataSet.rowCount
- time_bytes = bytes[:8 * row_count]
- value_bytes = bytes[8 * row_count:]
+ time_bytes = queryDataSet.time
+ value_bytes_list = queryDataSet.valueList
+ bitmap_list = queryDataSet.bitmapList
+ row_count = len(time_bytes) // 8
time_unpack_str = '>' + str(row_count) + 'q'
records = []
times = struct.unpack(time_unpack_str, time_bytes)
@@ -73,39 +88,44 @@ def convertQueryDataSet(queryDataSet, dataTypeList):
records.append([times[i]])
for i in range(len(dataTypeList)):
- type = dataTypeList[i]
+ value_type = dataTypeList[i]
+ value_bytes = value_bytes_list[i]
+ bitmap = bitmap_list[i]
+ # the actual number of value
+ if value_type == 'BOOLEAN':
+ value_count = len(value_bytes) // BOOL_BYTE_LEN
+ values_list = struct.unpack('>' + str(value_count) + '?', value_bytes)
+ elif value_type == 'INT32':
+ value_count = len(value_bytes) // INT32_BYTE_LEN
+ values_list = struct.unpack('>' + str(value_count) + 'i', value_bytes)
+ elif value_type == 'INT64':
+ value_count = len(value_bytes) // INT64_BYTE_LEN
+ values_list = struct.unpack('>' + str(value_count) + 'q', value_bytes)
+ elif value_type == 'FLOAT':
+ value_count = len(value_bytes) // FLOAT_BYTE_LEN
+ values_list = struct.unpack('>' + str(value_count) + 'f', value_bytes)
+ elif value_type == 'DOUBLE':
+ value_count = len(value_bytes) // DOUBLE_BYTE_LEN
+ values_list = struct.unpack('>' + str(value_count) + 'd', value_bytes)
+ elif value_type == 'TEXT':
+ values_list = []
+
+ # current index for value in values_list
+ value_index = 0
for j in range(row_count):
- is_null = value_bytes[0]
- value_bytes = value_bytes[1:]
- if is_null == 1:
+ if is_null(bitmap, j):
records[j].append('null')
else:
- if type == 'BOOLEAN':
- value = value_bytes[:1]
- value_bytes = value_bytes[1:]
- records[j].append(struct.unpack('>?', value)[0])
- elif type == 'INT32':
- value = value_bytes[:4]
- value_bytes = value_bytes[4:]
- records[j].append(struct.unpack('>i', value)[0])
- elif type == 'INT64':
- value = value_bytes[:8]
- value_bytes = value_bytes[8:]
- records[j].append(struct.unpack('>q', value)[0])
- elif type == 'FLOAT':
- value = value_bytes[:4]
- value_bytes = value_bytes[4:]
- records[j].append(struct.unpack('>f', value)[0])
- elif type == 'DOUBLE':
- value = value_bytes[:8]
- value_bytes = value_bytes[8:]
- records[j].append(struct.unpack('>d', value)[0])
- elif type == 'TEXT':
+ if value_type != 'TEXT':
+ records[j].append(values_list[value_index])
+ else:
size = value_bytes[:4]
value_bytes = value_bytes[4:]
size = struct.unpack('>i', size)[0]
records[j].append(value_bytes[:size])
value_bytes = value_bytes[size:]
+ value_index += 1
+
return records
diff --git a/session/src/main/java/org/apache/iotdb/session/SessionDataSet.java b/session/src/main/java/org/apache/iotdb/session/SessionDataSet.java
index 6c2ac10..4ae34d4 100644
--- a/session/src/main/java/org/apache/iotdb/session/SessionDataSet.java
+++ b/session/src/main/java/org/apache/iotdb/session/SessionDataSet.java
@@ -59,6 +59,7 @@ public class SessionDataSet {
this.queryId = queryId;
this.client = client;
this.operationHandle = operationHandle;
+ currentBitmap = new byte[columnNameList.size()];
// deduplicate columnTypeList according to columnNameList
this.columnTypeDeduplicatedList = new ArrayList<>();