zwhzzz0821 commented on code in PR #409:
URL: https://github.com/apache/tsfile/pull/409#discussion_r1962972698


##########
cpp/src/reader/block/device_ordered_tsblock_reader.cc:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "reader/block/device_ordered_tsblock_reader.h"
+
+namespace storage {
+
+bool DeviceOrderedTsBlockReader::has_next() {
+    if (current_reader_ != nullptr && current_reader_->has_next()) {
+        return true;
+    }
+    if (current_reader_ != nullptr) {
+        delete current_reader_;
+        current_reader_ = nullptr;
+    }
+    while (device_task_iterator_->has_next()) {
+        DeviceQueryTask *task = nullptr;
+        if (IS_FAIL(device_task_iterator_->next(task))) {
+            return false;
+        }
+        assert(task != nullptr);
+        if (current_reader_) {
+            delete current_reader_;
+            current_reader_ = nullptr;
+        }
+        current_reader_ = new SingleDeviceTsBlockReader(
+            task, block_size_, metadata_querier_, tsfile_io_reader_, 
time_filter_,
+            field_filter_);
+        if (current_reader_->has_next()) {
+            return true;
+        }
+    }
+    return false;
+}
+
+int DeviceOrderedTsBlockReader::next(common::TsBlock *&ret_block) {
+    int ret = common::E_OK;
+    if (UNLIKELY(!has_next())) {
+        return common::E_NO_MORE_DATA;
+    } else if (RET_FAIL(current_reader_->next(ret_block))) {
+    }
+    return ret;
+}
+
+void DeviceOrderedTsBlockReader::close() {
+    if (current_reader_) {
+        delete current_reader_;
+        current_reader_ = nullptr;
+    }
+    if (time_filter_ != nullptr) {
+        delete time_filter_;
+        time_filter_ = nullptr;
+    }
+    if (field_filter_ != nullptr) {
+        delete field_filter_;
+        field_filter_ = nullptr;
+    }
+}

Review Comment:
   `    int query(const std::string &table_name,
                 const std::vector<std::string> &columns_names, int64_t 
start_time,
                 int64_t end_time, ResultSet *&result_set);`
   In this interface, we construct a time_filter internally after passing in 
the time, so I think it should be destructed internally as well.



-- 
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