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

rong 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 96b5269  [IOTDB-1730] client-cpp, enhance session::insertTablet() 
etc.'s performance (#4022)
96b5269 is described below

commit 96b5269f0fc6e02927563d4481da3bfb310fc7b1
Author: Jamber <[email protected]>
AuthorDate: Fri Sep 24 17:58:59 2021 +0800

    [IOTDB-1730] client-cpp, enhance session::insertTablet() etc.'s performance 
(#4022)
    
    Co-authored-by: haiyi.zb <[email protected]>
---
 client-cpp/src/main/Session.cpp | 26 +++++++++-----------------
 client-cpp/src/main/Session.h   |  6 ++++++
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/client-cpp/src/main/Session.cpp b/client-cpp/src/main/Session.cpp
index 4389a10..2eec6eb 100644
--- a/client-cpp/src/main/Session.cpp
+++ b/client-cpp/src/main/Session.cpp
@@ -18,6 +18,7 @@
  */
 
 #include "Session.h"
+#include <algorithm>
 
 using namespace std;
 
@@ -387,6 +388,7 @@ void Session::sortTablet(Tablet &tablet) {
     }
 
     this->sortIndexByTimestamp(index, tablet.timestamps, tablet.rowSize);
+    tablet.timestamps = sortList(tablet.timestamps, index, tablet.rowSize);
     for (size_t i = 0; i < tablet.schemas.size(); i++) {
         tablet.values[i] = sortList(tablet.values[i], index, tablet.rowSize);
     }
@@ -395,23 +397,12 @@ void Session::sortTablet(Tablet &tablet) {
 }
 
 void Session::sortIndexByTimestamp(int *index, std::vector <int64_t> 
&timestamps, int length) {
-    // Use Insert Sort Algorithm
-    if (length >= 2) {
-        for (int i = 1; i < length; i++) {
-            int x = timestamps[i];
-            int tmpIndex = index[i];
-            int j = i - 1;
-
-            while (j >= 0 && timestamps[j] > x) {
-                timestamps[j + 1] = timestamps[j];
-                index[j + 1] = index[j];
-                j--;
-            }
-
-            timestamps[j + 1] = x;
-            index[j + 1] = tmpIndex;
-        }
+    if ( length <= 1 ) {
+        return;
     }
+
+    TsCompare tsCompareObj(timestamps);
+    std::sort(&index[0], &index[length], tsCompareObj);
 }
 
 /**
@@ -698,6 +689,7 @@ void Session::insertRecordsOfOneDevice(const string 
&deviceId,
         }
 
         this->sortIndexByTimestamp(index, times, times.size());
+        times = sortList(times, index, times.size());
         measurementsList = sortList(measurementsList, index, times.size());
         typesList = sortList(typesList, index, times.size());
         valuesList = sortList(valuesList, index, times.size());
@@ -785,7 +777,7 @@ void Session::insertTablets(map<string, Tablet *> &tablets, 
bool sorted) {
                 throw BatchExecutionException("Times in Tablet are not in 
ascending order");
             }
         } else {
-            sortTablet(*(tablets[item.first]));
+            sortTablet(*(item.second));
         }
 
         request.deviceIds.push_back(item.second->deviceId);
diff --git a/client-cpp/src/main/Session.h b/client-cpp/src/main/Session.h
index e5395fe..93cafe5 100644
--- a/client-cpp/src/main/Session.h
+++ b/client-cpp/src/main/Session.h
@@ -613,6 +613,12 @@ private:
 
     int8_t getDataTypeNumber(TSDataType::TSDataType type);
 
+    struct TsCompare {
+        std::vector <int64_t> &timestamps;
+        TsCompare(std::vector <int64_t> 
&inTimestamps):timestamps(inTimestamps) {};
+        bool operator() (int i, int j) { return (timestamps[i] < 
timestamps[j]) ;};
+    };
+
 public:
     Session(const std::string &host, int rpcPort) : username("user"), 
password("password") {
         this->host = host;

Reply via email to