This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new 0285193 Fix SessionDataSet bug when reading value buffer in "select
last" with C++ client (#2538)
0285193 is described below
commit 0285193868a446501e4a23fa4f313e2df0dba40f
Author: wshao08 <[email protected]>
AuthorDate: Thu Jan 21 17:22:06 2021 +0800
Fix SessionDataSet bug when reading value buffer in "select last" with C++
client (#2538)
---
.../client-cpp-example/src/SessionExample.cpp | 13 +++++++++++++
client-cpp/src/main/IOTDBSession.cpp | 21 ++++++++++-----------
client-cpp/src/main/IOTDBSession.h | 4 ++++
client-cpp/src/test/cpp/sessionIT.cpp | 22 ++++++++++++++++++++++
4 files changed, 49 insertions(+), 11 deletions(-)
diff --git a/client-cpp/client-cpp-example/src/SessionExample.cpp
b/client-cpp/client-cpp-example/src/SessionExample.cpp
index 440c0ee..c2264b5 100644
--- a/client-cpp/client-cpp-example/src/SessionExample.cpp
+++ b/client-cpp/client-cpp-example/src/SessionExample.cpp
@@ -255,6 +255,17 @@ void deleteTimeseries() {
session->deleteTimeseries(paths);
}
+void queryLast() {
+ SessionDataSet *dataSet = session->executeQueryStatement("select last
s1,s2,s3 from root.sg1.d1");
+ for (string name: dataSet->getColumnNames()) {
+ cout << name << " ";
+ }
+ cout << endl;
+ while (dataSet->hasNext()) {
+ cout << dataSet->next()->toString();
+ }
+}
+
int main() {
session = new Session("127.0.0.1", 6667, "root", "root");
session->open(false);
@@ -276,6 +287,8 @@ int main() {
insertRecord();
+ queryLast();
+
insertTablet();
insertRecords();
diff --git a/client-cpp/src/main/IOTDBSession.cpp
b/client-cpp/src/main/IOTDBSession.cpp
index baf183e..30f9815 100644
--- a/client-cpp/src/main/IOTDBSession.cpp
+++ b/client-cpp/src/main/IOTDBSession.cpp
@@ -262,46 +262,45 @@ void SessionDataSet::constructOneRow() {
if (duplicateLocation.find(i) != duplicateLocation.end()) {
field = new Field(*outFields[duplicateLocation[i]]);
- }
- else {
- MyStringBuffer bitmapBuffer =
MyStringBuffer(tsQueryDataSet->bitmapList[loc]);
+ } else {
+ MyStringBuffer *bitmapBuffer = bitmapBuffers[loc].get();
// another new 8 row, should move the bitmap buffer position to
next byte
if (rowsIndex % 8 == 0) {
- currentBitmap[loc] = bitmapBuffer.getChar();
+ currentBitmap[loc] = bitmapBuffer->getChar();
}
if (!isNull(loc, rowsIndex)) {
- MyStringBuffer valueBuffer =
MyStringBuffer(tsQueryDataSet->valueList[loc]);
+ MyStringBuffer *valueBuffer = valueBuffers[loc].get();
TSDataType::TSDataType dataType =
getTSDataTypeFromString(columnTypeDeduplicatedList[loc]);
field = new Field(dataType);
switch (dataType) {
case TSDataType::BOOLEAN: {
- bool booleanValue = valueBuffer.getBool();
+ bool booleanValue = valueBuffer->getBool();
field->boolV = booleanValue;
break;
}
case TSDataType::INT32: {
- int intValue = valueBuffer.getInt();
+ int intValue = valueBuffer->getInt();
field->intV = intValue;
break;
}
case TSDataType::INT64: {
- int64_t longValue = valueBuffer.getLong();
+ int64_t longValue = valueBuffer->getLong();
field->longV = longValue;
break;
}
case TSDataType::FLOAT: {
- float floatValue = valueBuffer.getFloat();
+ float floatValue = valueBuffer->getFloat();
field->floatV = floatValue;
break;
}
case TSDataType::DOUBLE: {
- double doubleValue = valueBuffer.getDouble();
+ double doubleValue = valueBuffer->getDouble();
field->doubleV = doubleValue;
break;
}
case TSDataType::TEXT: {
- string stringValue = valueBuffer.getString();
+ string stringValue = valueBuffer->getString();
field->stringV = stringValue;
break;
}
diff --git a/client-cpp/src/main/IOTDBSession.h
b/client-cpp/src/main/IOTDBSession.h
index 6defcd8..ca5f428 100644
--- a/client-cpp/src/main/IOTDBSession.h
+++ b/client-cpp/src/main/IOTDBSession.h
@@ -523,6 +523,8 @@ private:
int rowsIndex = 0; // used to record the row index in current
TSQueryDataSet
std::shared_ptr<TSQueryDataSet> tsQueryDataSet;
MyStringBuffer tsQueryDataSetTimeBuffer;
+ std::vector<std::unique_ptr<MyStringBuffer>> valueBuffers;
+ std::vector<std::unique_ptr<MyStringBuffer>> bitmapBuffers;
RowRecord rowRecord;
char* currentBitmap; // used to cache the current bitmap for every column
static const int flag = 0x80; // used to do `or` operation with bitmap to
judge whether the value is null
@@ -550,6 +552,8 @@ public:
this->columnMap[name] = i;
this->columnTypeDeduplicatedList.push_back(columnTypeList[i]);
}
+ this->valueBuffers.push_back(std::unique_ptr<MyStringBuffer>(new
MyStringBuffer(queryDataSet->valueList[i])));
+ this->bitmapBuffers.push_back(std::unique_ptr<MyStringBuffer>(new
MyStringBuffer(queryDataSet->bitmapList[i])));
}
this->tsQueryDataSet = queryDataSet;
}
diff --git a/client-cpp/src/test/cpp/sessionIT.cpp
b/client-cpp/src/test/cpp/sessionIT.cpp
index 9fa1101..b9a66f9 100644
--- a/client-cpp/src/test/cpp/sessionIT.cpp
+++ b/client-cpp/src/test/cpp/sessionIT.cpp
@@ -169,3 +169,25 @@ TEST_CASE( "Test insertTablet ", "[testInsertTablet]") {
}
REQUIRE( count == 100 );
}
+
+TEST_CASE( "Test Last query ", "[testLastQuery]") {
+ prepareTimeseries();
+ string deviceId = "root.test.d1";
+ vector<string> measurements = { "s1", "s2", "s3" };
+
+ for (long time = 0; time < 100; time++) {
+ vector<string> values = { "1", "2", "3" };
+ session->insertRecord(deviceId, time, measurements, values);
+ }
+
+ vector<string> measurementValues = { "1", "2", "3" };
+ SessionDataSet *sessionDataSet = session->executeQueryStatement("select last
s1,s2,s3 from root.test.d1");
+ sessionDataSet->setBatchSize(1024);
+ long index = 0;
+ while (sessionDataSet->hasNext()) {
+ vector<Field*> fields = sessionDataSet->next()->fields;
+ REQUIRE( fields[0]->stringV == deviceId + "." + measurements[index] );
+ REQUIRE( fields[1]->stringV == measurementValues[index] );
+ index++;
+ }
+}