You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/01/06 11:59:48 UTC

[iotdb] branch master updated: [IOTDB-2290] Incorrect query result in C++ client (#4721)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 853ff47  [IOTDB-2290] Incorrect query result in C++ client (#4721)
853ff47 is described below

commit 853ff4771e36505bd6082b17b4b49af7a866329b
Author: liuminghui233 <36...@users.noreply.github.com>
AuthorDate: Thu Jan 6 19:59:07 2022 +0800

    [IOTDB-2290] Incorrect query result in C++ client (#4721)
---
 client-cpp/src/main/CMakeLists.txt                 |   2 +-
 client-cpp/src/main/Session.cpp                    |  12 +-
 client-cpp/src/main/Session.h                      |  39 ++++-
 .../src/AlignedTimeseriesSessionExample.cpp        | 114 ++++++++++---
 example/client-cpp-example/src/SessionExample.cpp  | 182 ++++++++++++---------
 5 files changed, 232 insertions(+), 117 deletions(-)

diff --git a/client-cpp/src/main/CMakeLists.txt b/client-cpp/src/main/CMakeLists.txt
index efba9b0..b05cb26 100644
--- a/client-cpp/src/main/CMakeLists.txt
+++ b/client-cpp/src/main/CMakeLists.txt
@@ -21,7 +21,7 @@ PROJECT(iotdb_session CXX)
 SET(CMAKE_CXX_STANDARD 11)
 SET(CMAKE_CXX_STANDARD_REQUIRED ON)
 SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 SET(TOOLS_DIR "${CMAKE_SOURCE_DIR}/../../../../compile-tools")
 
 # Add Thrift include directory
diff --git a/client-cpp/src/main/Session.cpp b/client-cpp/src/main/Session.cpp
index d021ea0..2f4468d 100644
--- a/client-cpp/src/main/Session.cpp
+++ b/client-cpp/src/main/Session.cpp
@@ -313,7 +313,12 @@ void SessionDataSet::constructOneRow() {
         outFields.push_back(field);
     }
 
-    rowRecord = RowRecord(tsQueryDataSetTimeBuffer.getLong(), outFields);
+    if(!this->isIgnoreTimeStamp) {
+        rowRecord = RowRecord(tsQueryDataSetTimeBuffer.getLong(), outFields);
+    } else {
+        tsQueryDataSetTimeBuffer.getLong();
+        rowRecord = RowRecord(outFields);
+    }
     rowsIndex++;
 }
 
@@ -1291,7 +1296,8 @@ bool Session::checkTimeseriesExists(const string &path) {
         dataset->closeOperationHandle();
         return isExisted;
     }
-    catch (exception e) {
+    catch (exception &e) {
+        std::cout << e.what() << std::endl;
         throw IoTDBConnectionException(e.what());
     }
 }
@@ -1342,7 +1348,7 @@ unique_ptr <SessionDataSet> Session::executeQueryStatement(const string &sql) {
     }
     shared_ptr <TSQueryDataSet> queryDataSet(new TSQueryDataSet(resp->queryDataSet));
     return unique_ptr<SessionDataSet>(new SessionDataSet(
-            sql, resp->columns, resp->dataTypeList, resp->queryId, statementId, client, sessionId, queryDataSet));
+            sql, resp->columns, resp->dataTypeList, resp->columnNameIndexMap, resp->ignoreTimeStamp, resp->queryId, statementId, client, sessionId, queryDataSet));
 }
 
 void Session::executeNonQueryStatement(const string &sql) {
diff --git a/client-cpp/src/main/Session.h b/client-cpp/src/main/Session.h
index 8f54ad4..c4b3b01 100644
--- a/client-cpp/src/main/Session.h
+++ b/client-cpp/src/main/Session.h
@@ -440,6 +440,10 @@ public:
             : timestamp(timestamp), fields(fields) {
     }
 
+    RowRecord(const std::vector <Field> &fields)
+            : timestamp(-1), fields(fields) {
+    }
+
     RowRecord() {
         this->timestamp = -1;
     }
@@ -449,9 +453,15 @@ public:
     }
 
     std::string toString() {
-        std::string ret = std::to_string(timestamp);
-        for (size_t i = 0; i < fields.size(); i++) {
+        std::string ret = "";
+        if(this->timestamp != -1) {
+            ret.append(std::to_string(timestamp));
             ret.append("\t");
+        }
+        for (size_t i = 0; i < fields.size(); i++) {
+            if(i != 0) {
+                ret.append("\t");
+            }
             TSDataType::TSDataType dataType = fields[i].dataType;
             switch (dataType) {
                 case TSDataType::BOOLEAN: {
@@ -506,6 +516,7 @@ private:
     std::map<std::string, int> columnMap;
     // column size
     int columnSize = 0;
+    bool isIgnoreTimeStamp = false;
 
     int rowsIndex = 0; // used to record the row index in current TSQueryDataSet
     std::shared_ptr <TSQueryDataSet> tsQueryDataSet;
@@ -519,8 +530,12 @@ private:
 public:
     SessionDataSet() {}
 
-    SessionDataSet(const std::string &sql, const std::vector <std::string> &columnNameList,
-                   const std::vector <std::string> &columnTypeList, int64_t queryId, int64_t statementId,
+    SessionDataSet(const std::string &sql,
+                   const std::vector<std::string> &columnNameList,
+                   const std::vector<std::string> &columnTypeList,
+                   std::map<std::string, int> &columnNameIndexMap,
+                   bool isIgnoreTimeStamp,
+                   int64_t queryId, int64_t statementId,
                    std::shared_ptr <TSIServiceIf> client, int64_t sessionId,
                    std::shared_ptr <TSQueryDataSet> queryDataSet) : tsQueryDataSetTimeBuffer(queryDataSet->time) {
         this->sessionId = sessionId;
@@ -531,6 +546,7 @@ public:
         this->columnNameList = columnNameList;
         this->currentBitmap = new char[columnNameList.size()];
         this->columnSize = columnNameList.size();
+        this->isIgnoreTimeStamp = isIgnoreTimeStamp;
 
         // column name -> column location
         for (size_t i = 0; i < columnNameList.size(); i++) {
@@ -541,10 +557,17 @@ public:
                 this->columnMap[name] = i;
                 this->columnTypeDeduplicatedList.push_back(columnTypeList[i]);
             }
-            this->valueBuffers.push_back(
-                    std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->valueList[columnMap[name]])));
-            this->bitmapBuffers.push_back(
-                    std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->bitmapList[columnMap[name]])));
+            if(!columnNameIndexMap.empty()) {
+                this->valueBuffers.push_back(
+                        std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->valueList[columnNameIndexMap[name]])));
+                this->bitmapBuffers.push_back(
+                        std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->bitmapList[columnNameIndexMap[name]])));
+            } else {
+                this->valueBuffers.push_back(
+                        std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->valueList[columnMap[name]])));
+                this->bitmapBuffers.push_back(
+                        std::unique_ptr<MyStringBuffer>(new MyStringBuffer(queryDataSet->bitmapList[columnMap[name]])));
+            }
         }
         this->tsQueryDataSet = queryDataSet;
     }
diff --git a/example/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp b/example/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp
index 31c5a8d..4d78f04 100644
--- a/example/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp
+++ b/example/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp
@@ -26,12 +26,12 @@ Session *session;
 void createAlignedTimeseries() {
     string alignedDeviceId = "root.sg1.d1";
     vector<string> measurements = {"s1", "s2", "s3"};
-    vector<string> alignedTimeseries = {"root.sg1.d1.s1","root.sg1.d1.s2","root.sg1.d1.s3"};
+    vector<string> alignedTimeseries = {"root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3"};
     vector<TSDataType::TSDataType> dataTypes = {TSDataType::INT32, TSDataType::DOUBLE, TSDataType::BOOLEAN};
     vector<TSEncoding::TSEncoding> encodings = {TSEncoding::PLAIN, TSEncoding::GORILLA, TSEncoding::RLE};
     vector<CompressionType::CompressionType> compressors = {
-        CompressionType::SNAPPY, CompressionType::UNCOMPRESSED, CompressionType::SNAPPY};
-    for (string timeseries : alignedTimeseries) {
+            CompressionType::SNAPPY, CompressionType::UNCOMPRESSED, CompressionType::SNAPPY};
+    for (const string &timeseries: alignedTimeseries) {
         if (session->checkTimeseriesExists(timeseries)) {
             session->deleteTimeseries(timeseries);
         }
@@ -39,18 +39,34 @@ void createAlignedTimeseries() {
     session->createAlignedTimeseries(alignedDeviceId, measurements, dataTypes, encodings, compressors);
 }
 
+void showTimeseries() {
+    unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement("show timeseries");
+    for (const string &name: dataSet->getColumnNames()) {
+        cout << name << "  ";
+    }
+    cout << endl;
+
+    dataSet->setBatchSize(1024);
+    while (dataSet->hasNext()) {
+        cout << dataSet->next()->toString();
+    }
+    cout << endl;
+
+    dataSet->closeOperationHandle();
+}
+
 void insertAlignedRecord() {
     string deviceId = "root.sg1.d1";
     vector<string> measurements;
-    measurements.push_back("s1");
-    measurements.push_back("s2");
-    measurements.push_back("s3");
+    measurements.emplace_back("s1");
+    measurements.emplace_back("s2");
+    measurements.emplace_back("s3");
 
-    for (int64_t time = 0; time < 100; time++) {
+    for (int64_t time = 0; time < 10; time++) {
         vector<string> values;
-        values.push_back("1");
-        values.push_back("1.0");
-        values.push_back("true");
+        values.emplace_back("1");
+        values.emplace_back("1.0");
+        values.emplace_back("true");
         session->insertAlignedRecord(deviceId, time, measurements, values);
     }
 }
@@ -58,26 +74,26 @@ void insertAlignedRecord() {
 void insertAlignedRecords() {
     string deviceId = "root.sg1.d1";
     vector<string> measurements;
-    measurements.push_back("s1");
-    measurements.push_back("s2");
-    measurements.push_back("s3");
+    measurements.emplace_back("s1");
+    measurements.emplace_back("s2");
+    measurements.emplace_back("s3");
 
     vector<string> deviceIds;
     vector<vector<string>> measurementsList;
     vector<vector<string>> valuesList;
     vector<int64_t> timestamps;
 
-    for (int64_t time = 100; time < 200; time++) {
+    for (int64_t time = 10; time < 20; time++) {
         vector<string> values;
-        values.push_back("1");
-        values.push_back("1.0");
-        values.push_back("true");
+        values.emplace_back("1");
+        values.emplace_back("1.0");
+        values.emplace_back("true");
 
         deviceIds.push_back(deviceId);
         measurementsList.push_back(measurements);
         valuesList.push_back(values);
         timestamps.push_back(time);
-        if (time != 100 && time % 100 == 0) {
+        if (time != 10 && time % 10 == 0) {
             session->insertAlignedRecords(deviceIds, timestamps, measurementsList, valuesList);
             deviceIds.clear();
             measurementsList.clear();
@@ -98,10 +114,10 @@ void insertAlignedTablet() {
     schemas.push_back(pairB);
     schemas.push_back(pairC);
 
-    Tablet tablet("root.sg1.d1", schemas, 100);
+    Tablet tablet("root.sg1.d1", schemas, 10);
     tablet.setAligned(true);
 
-    for (int64_t time = 200; time < 300; time++) {
+    for (int64_t time = 20; time < 30; time++) {
         int row = tablet.rowSize++;
         tablet.timestamps[row] = time;
         tablet.values[0][row] = "1";
@@ -128,16 +144,16 @@ void insertAlignedTablets() {
     schemas.push_back(pairB);
     schemas.push_back(pairC);
 
-    Tablet tablet1("root.sg1.d1", schemas, 100);
-    Tablet tablet2("root.sg1.d2", schemas, 100);
-    Tablet tablet3("root.sg1.d3", schemas, 100);
+    Tablet tablet1("root.sg1.d1", schemas, 10);
+    Tablet tablet2("root.sg1.d2", schemas, 10);
+    Tablet tablet3("root.sg1.d3", schemas, 10);
 
-    map<string, Tablet*> tabletMap;
+    map<string, Tablet *> tabletMap;
     tabletMap["root.sg1.d1"] = &tablet1;
     tabletMap["root.sg1.d2"] = &tablet2;
     tabletMap["root.sg1.d3"] = &tablet3;
 
-    for (int64_t time = 300; time < 400; time++) {
+    for (int64_t time = 30; time < 40; time++) {
         int row1 = tablet1.rowSize++;
         int row2 = tablet2.rowSize++;
         int row3 = tablet3.rowSize++;
@@ -174,6 +190,40 @@ void insertAlignedTablets() {
     }
 }
 
+void query() {
+    unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement("select * from root.sg1.d1");
+    cout << "timestamp" << "  ";
+    for (const string &name: dataSet->getColumnNames()) {
+        cout << name << "  ";
+    }
+    cout << endl;
+
+    dataSet->setBatchSize(1024);
+    while (dataSet->hasNext()) {
+        cout << dataSet->next()->toString();
+    }
+    cout << endl;
+
+    dataSet->closeOperationHandle();
+}
+
+void deleteData() {
+    string path = "root.sg1.d1.s1";
+    int64_t deleteTime = 39;
+    session->deleteData(path, deleteTime);
+}
+
+void deleteTimeseries() {
+    vector<string> paths;
+    vector<string> alignedTimeseries = {"root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3"};
+    for (const string &timeseries: alignedTimeseries) {
+        if (session->checkTimeseriesExists(timeseries)) {
+            paths.push_back(timeseries);
+        }
+    }
+    session->deleteTimeseries(paths);
+}
+
 int main() {
     session = new Session("127.0.0.1", 6667, "root", "root");
 
@@ -184,7 +234,7 @@ int main() {
     try {
         session->setStorageGroup("root.sg1");
     }
-    catch (IoTDBConnectionException e){
+    catch (IoTDBConnectionException &e) {
         string errorMessage(e.what());
         if (errorMessage.find("StorageGroupAlreadySetException") == string::npos) {
             cout << errorMessage << endl;
@@ -195,6 +245,9 @@ int main() {
     cout << "createAlignedTimeseries\n" << endl;
     createAlignedTimeseries();
 
+    cout << "showTimeseries\n" << endl;
+    showTimeseries();
+
     cout << "insertAlignedRecord\n" << endl;
     insertAlignedRecord();
 
@@ -207,6 +260,15 @@ int main() {
     cout << "insertAlignedTablets\n" << endl;
     insertAlignedTablets();
 
+    cout << "query\n" << endl;
+    query();
+
+    cout << "deleteData\n" << endl;
+    deleteData();
+
+    cout << "deleteTimeseries\n" << endl;
+    deleteTimeseries();
+
     cout << "session close\n" << endl;
     session->close();
 
diff --git a/example/client-cpp-example/src/SessionExample.cpp b/example/client-cpp-example/src/SessionExample.cpp
index 84230c2..72e37ed 100644
--- a/example/client-cpp-example/src/SessionExample.cpp
+++ b/example/client-cpp-example/src/SessionExample.cpp
@@ -26,15 +26,15 @@ Session *session;
 void createTimeseries() {
     if (!session->checkTimeseriesExists("root.sg1.d1.s1")) {
         session->createTimeseries("root.sg1.d1.s1", TSDataType::INT64, TSEncoding::RLE,
-        CompressionType::SNAPPY);
+                                  CompressionType::SNAPPY);
     }
     if (!session->checkTimeseriesExists("root.sg1.d1.s2")) {
         session->createTimeseries("root.sg1.d1.s2", TSDataType::INT64, TSEncoding::RLE,
-        CompressionType::SNAPPY);
+                                  CompressionType::SNAPPY);
     }
     if (!session->checkTimeseriesExists("root.sg1.d1.s3")) {
         session->createTimeseries("root.sg1.d1.s3", TSDataType::INT64, TSEncoding::RLE,
-        CompressionType::SNAPPY);
+                                  CompressionType::SNAPPY);
     }
 
     // create timeseries with tags and attributes
@@ -44,15 +44,15 @@ void createTimeseries() {
         map<string, string> attributes;
         attributes["description"] = "v1";
         session->createTimeseries("root.sg1.d1.s4", TSDataType::INT64, TSEncoding::RLE,
-            CompressionType::SNAPPY, NULL, &tags, &attributes, "temperature");
+                                  CompressionType::SNAPPY, nullptr, &tags, &attributes, "temperature");
     }
 }
 
 void createMultiTimeseries() {
     if (!session->checkTimeseriesExists("root.sg1.d2.s1") && !session->checkTimeseriesExists("root.sg1.d2.s1")) {
         vector<string> paths;
-        paths.push_back("root.sg1.d2.s1");
-        paths.push_back("root.sg1.d2.s2");
+        paths.emplace_back("root.sg1.d2.s1");
+        paths.emplace_back("root.sg1.d2.s2");
         vector<TSDataType::TSDataType> tsDataTypes;
         tsDataTypes.push_back(TSDataType::INT64);
         tsDataTypes.push_back(TSDataType::INT64);
@@ -63,38 +63,55 @@ void createMultiTimeseries() {
         compressionTypes.push_back(CompressionType::SNAPPY);
         compressionTypes.push_back(CompressionType::SNAPPY);
 
-        vector<map<string,string>> tagsList;
-        map<string,string> tags;
+        vector<map<string, string>> tagsList;
+        map<string, string> tags;
         tags["unit"] = "kg";
         tagsList.push_back(tags);
         tagsList.push_back(tags);
 
-        vector<map<string,string>> attributesList;
-        map<string,string> attributes;
+        vector<map<string, string>> attributesList;
+        map<string, string> attributes;
         attributes["minValue"] = "1";
         attributes["maxValue"] = "100";
         attributesList.push_back(attributes);
         attributesList.push_back(attributes);
 
         vector<string> alias;
-        alias.push_back("weight1");
-        alias.push_back("weight2");
+        alias.emplace_back("weight1");
+        alias.emplace_back("weight2");
 
-        session->createMultiTimeseries(paths, tsDataTypes, tsEncodings, compressionTypes, NULL, &tagsList, &attributesList, &alias);
+        session->createMultiTimeseries(paths, tsDataTypes, tsEncodings, compressionTypes, nullptr, &tagsList,
+                                       &attributesList, &alias);
     }
 }
 
+void showTimeseries() {
+    unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement("show timeseries");
+    for (const string &name: dataSet->getColumnNames()) {
+        cout << name << "  ";
+    }
+    cout << endl;
+
+    dataSet->setBatchSize(1024);
+    while (dataSet->hasNext()) {
+        cout << dataSet->next()->toString();
+    }
+    cout << endl;
+
+    dataSet->closeOperationHandle();
+}
+
 void insertRecord() {
     string deviceId = "root.sg1.d1";
     vector<string> measurements;
-    measurements.push_back("s1");
-    measurements.push_back("s2");
-    measurements.push_back("s3");
-    for (int64_t time = 0; time < 100; time++) {
+    measurements.emplace_back("s1");
+    measurements.emplace_back("s2");
+    measurements.emplace_back("s3");
+    for (int64_t time = 0; time < 10; time++) {
         vector<string> values;
-        values.push_back("11");
-        values.push_back("22");
-        values.push_back("33");
+        values.emplace_back("1");
+        values.emplace_back("2");
+        values.emplace_back("3");
         session->insertRecord(deviceId, time, measurements, values);
     }
 }
@@ -108,9 +125,9 @@ void insertTablet() {
     schemas.push_back(pairB);
     schemas.push_back(pairC);
 
-    Tablet tablet("root.sg1.d1", schemas, 100);
+    Tablet tablet("root.sg1.d1", schemas, 10);
 
-    for (int64_t time = 100; time < 200; time++) {
+    for (int64_t time = 10; time < 20; time++) {
         int row = tablet.rowSize++;
         tablet.timestamps[row] = time;
         for (int i = 0; i < 3; i++) {
@@ -128,6 +145,40 @@ void insertTablet() {
     }
 }
 
+void insertRecords() {
+    string deviceId = "root.sg1.d1";
+    vector<string> measurements;
+    measurements.emplace_back("s1");
+    measurements.emplace_back("s2");
+    measurements.emplace_back("s3");
+
+    vector<string> deviceIds;
+    vector<vector<string>> measurementsList;
+    vector<vector<string>> valuesList;
+    vector<int64_t> timestamps;
+
+    for (int64_t time = 20; time < 30; time++) {
+        vector<string> values;
+        values.emplace_back("1");
+        values.emplace_back("2");
+        values.emplace_back("3");
+
+        deviceIds.push_back(deviceId);
+        measurementsList.push_back(measurements);
+        valuesList.push_back(values);
+        timestamps.push_back(time);
+        if (time != 20 && time % 10 == 0) {
+            session->insertRecords(deviceIds, timestamps, measurementsList, valuesList);
+            deviceIds.clear();
+            measurementsList.clear();
+            valuesList.clear();
+            timestamps.clear();
+        }
+    }
+
+    session->insertRecords(deviceIds, timestamps, measurementsList, valuesList);
+}
+
 void insertTablets() {
     pair<string, TSDataType::TSDataType> pairA("s1", TSDataType::INT64);
     pair<string, TSDataType::TSDataType> pairB("s2", TSDataType::INT64);
@@ -137,16 +188,16 @@ void insertTablets() {
     schemas.push_back(pairB);
     schemas.push_back(pairC);
 
-    Tablet tablet1("root.sg1.d1", schemas, 100);
-    Tablet tablet2("root.sg1.d2", schemas, 100);
-    Tablet tablet3("root.sg1.d3", schemas, 100);
+    Tablet tablet1("root.sg1.d1", schemas, 10);
+    Tablet tablet2("root.sg1.d2", schemas, 10);
+    Tablet tablet3("root.sg1.d3", schemas, 10);
 
-    map<string, Tablet*> tabletMap;
+    map<string, Tablet *> tabletMap;
     tabletMap["root.sg1.d1"] = &tablet1;
     tabletMap["root.sg1.d2"] = &tablet2;
     tabletMap["root.sg1.d3"] = &tablet3;
 
-    for (int64_t time = 200; time < 300; time++) {
+    for (int64_t time = 30; time < 40; time++) {
         int row1 = tablet1.rowSize++;
         int row2 = tablet2.rowSize++;
         int row3 = tablet3.rowSize++;
@@ -176,55 +227,23 @@ void insertTablets() {
     }
 }
 
-void insertRecords() {
-    string deviceId = "root.sg1.d1";
-    vector<string> measurements;
-    measurements.push_back("s1");
-    measurements.push_back("s2");
-    measurements.push_back("s3");
-
-    vector<string> deviceIds;
-    vector<vector<string>> measurementsList;
-    vector<vector<string>> valuesList;
-    vector<int64_t> timestamps;
-
-    for (int64_t time = 300; time < 400; time++) {
-        vector<string> values;
-        values.push_back("1");
-        values.push_back("2");
-        values.push_back("3");
-
-        deviceIds.push_back(deviceId);
-        measurementsList.push_back(measurements);
-        valuesList.push_back(values);
-        timestamps.push_back(time);
-        if (time != 300 && time % 100 == 0) {
-            session->insertRecords(deviceIds, timestamps, measurementsList, valuesList);
-            deviceIds.clear();
-            measurementsList.clear();
-            valuesList.clear();
-            timestamps.clear();
-        }
-    }
-
-    session->insertRecords(deviceIds, timestamps, measurementsList, valuesList);
-}
-
 void nonQuery() {
-    session->executeNonQueryStatement("insert into root.sg1.d1(timestamp,s1) values(200, 1);");
+    session->executeNonQueryStatement("insert into root.sg1.d1(timestamp,s1) values(50, 1);");
 }
 
 void query() {
     unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement("select * from root.sg1.d1");
     cout << "timestamp" << "  ";
-    for (string name : dataSet->getColumnNames()) {
-      cout << name << "  ";
+    for (const string &name: dataSet->getColumnNames()) {
+        cout << name << "  ";
     }
     cout << endl;
+
     dataSet->setBatchSize(1024);
     while (dataSet->hasNext()) {
-      cout << dataSet->next()->toString();
+        cout << dataSet->next()->toString();
     }
+    cout << endl;
 
     dataSet->closeOperationHandle();
 }
@@ -238,30 +257,32 @@ void deleteData() {
 void deleteTimeseries() {
     vector<string> paths;
     if (session->checkTimeseriesExists("root.sg1.d1.s1")) {
-      paths.push_back("root.sg1.d1.s1");
+        paths.emplace_back("root.sg1.d1.s1");
     }
     if (session->checkTimeseriesExists("root.sg1.d1.s2")) {
-      paths.push_back("root.sg1.d1.s2");
+        paths.emplace_back("root.sg1.d1.s2");
     }
     if (session->checkTimeseriesExists("root.sg1.d1.s3")) {
-      paths.push_back("root.sg1.d1.s3");
+        paths.emplace_back("root.sg1.d1.s3");
     }
     if (session->checkTimeseriesExists("root.sg1.d1.s4")) {
-      paths.push_back("root.sg1.d1.s4");
+        paths.emplace_back("root.sg1.d1.s4");
     }
     session->deleteTimeseries(paths);
 }
 
 void queryLast() {
     unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement("select last s1,s2,s3 from root.sg1.d1");
-    for (string name: dataSet->getColumnNames()) {
+    for (const string &name: dataSet->getColumnNames()) {
         cout << name << "  ";
     }
     cout << endl;
+
     while (dataSet->hasNext()) {
         cout << dataSet->next()->toString();
     }
     cout << endl;
+
     dataSet->closeOperationHandle();
 }
 
@@ -271,14 +292,14 @@ int main() {
 
     cout << "setStorageGroup\n" << endl;
     try {
-      session->setStorageGroup("root.sg1");
+        session->setStorageGroup("root.sg1");
     }
-    catch (IoTDBConnectionException e){
-      string errorMessage(e.what());
-      if (errorMessage.find("StorageGroupAlreadySetException") == string::npos) {
-        cout << errorMessage << endl;
+    catch (IoTDBConnectionException &e) {
+        string errorMessage(e.what());
+        if (errorMessage.find("StorageGroupAlreadySetException") == string::npos) {
+            cout << errorMessage << endl;
+        }
         throw e;
-      }
     }
 
     cout << "createTimeseries\n" << endl;
@@ -287,12 +308,12 @@ int main() {
     cout << "createMultiTimeseries\n" << endl;
     createMultiTimeseries();
 
+    cout << "showTimeseries\n" << endl;
+    showTimeseries();
+
     cout << "insertRecord\n" << endl;
     insertRecord();
 
-    cout << "queryLast\n" << endl;
-    queryLast();
-
     cout << "insertTablet\n" << endl;
     insertTablet();
 
@@ -305,6 +326,9 @@ int main() {
     cout << "nonQuery\n" << endl;
     nonQuery();
 
+    cout << "queryLast\n" << endl;
+    queryLast();
+
     cout << "query\n" << endl;
     query();