ColinLeeo commented on code in PR #769:
URL: https://github.com/apache/tsfile/pull/769#discussion_r3056195862


##########
cpp/src/cwrapper/tsfile_cwrapper.cc:
##########
@@ -970,6 +970,79 @@ int fill_timeseries_statistic(storage::Statistic* st,
     return common::E_OK;
 }
 
+int fill_timeline_statistic(storage::ITimeseriesIndex* idx,
+                            TimeseriesStatistic* out) {
+    clear_timeseries_statistic(out);
+    if (idx == nullptr) {
+        return common::E_OK;
+    }
+
+    auto* aligned_idx = dynamic_cast<storage::AlignedTimeseriesIndex*>(idx);
+    if (aligned_idx != nullptr && aligned_idx->time_ts_idx_ != nullptr &&
+        aligned_idx->time_ts_idx_->get_statistic() != nullptr) {
+        auto* st = aligned_idx->time_ts_idx_->get_statistic();
+        TsFileStatisticBase* b = tsfile_statistic_base(out);
+        b->has_statistic = true;
+        b->type = TS_DATATYPE_INVALID;
+        b->row_count = st->get_count();
+        b->start_time = st->start_time_;
+        b->end_time = st->get_end_time();
+        return common::E_OK;
+    }
+
+    if (idx->get_statistic() != nullptr && idx->get_time_chunk_meta_list() == 
nullptr) {
+        auto* st = idx->get_statistic();
+        TsFileStatisticBase* b = tsfile_statistic_base(out);
+        b->has_statistic = true;
+        b->type = TS_DATATYPE_INVALID;
+        b->row_count = st->get_count();
+        b->start_time = st->start_time_;
+        b->end_time = st->get_end_time();
+        return common::E_OK;
+    }
+
+    auto* list = idx->get_time_chunk_meta_list();
+    if (list == nullptr) {
+        list = idx->get_chunk_meta_list();
+    }
+    if (list == nullptr) {
+        return common::E_OK;
+    }
+
+    int64_t row_count = 0;
+    int64_t start_time = 0;
+    int64_t end_time = 0;
+    bool has_statistic = false;
+    for (auto it = list->begin(); it != list->end(); it++) {
+        auto* chunk_meta = it.get();
+        if (chunk_meta == nullptr || chunk_meta->statistic_ == nullptr ||
+            chunk_meta->statistic_->count_ <= 0) {
+            continue;
+        }
+        if (!has_statistic) {
+            start_time = chunk_meta->statistic_->start_time_;
+            end_time = chunk_meta->statistic_->end_time_;
+            has_statistic = true;
+        } else {
+            start_time = std::min(start_time, 
chunk_meta->statistic_->start_time_);
+            end_time = std::max(end_time, chunk_meta->statistic_->end_time_);
+        }
+        row_count += chunk_meta->statistic_->count_;
+    }
+
+    if (!has_statistic) {
+        return common::E_OK;
+    }
+
+    TsFileStatisticBase* b = tsfile_statistic_base(out);
+    b->has_statistic = true;
+    b->type = TS_DATATYPE_INVALID;
+    b->row_count = row_count;

Review Comment:
   Should be int64/ timestamp.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to