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


##########
cpp/src/writer/tsfile_writer.cc:
##########
@@ -384,6 +386,99 @@ int TsFileWriter::do_check_schema_aligned(
     return ret;
 }
 
+int TsFileWriter::do_check_schema_table(
+    std::shared_ptr<IDeviceID> device_id,
+    Tablet &tablet,
+    storage::TimeChunkWriter *&time_chunk_writer,
+    common::SimpleVector<storage::ValueChunkWriter *> &value_chunk_writers) {
+    int ret = E_OK;
+
+    auto dev_it = schemas_.find(device_id);
+    MeasurementSchemaGroup *device_schema = NULL;
+
+    auto &schema_map = io_writer_->get_schema()->table_schema_map_;
+    auto table_schema_it = schema_map.find(tablet.get_table_name());
+    if (UNLIKELY(table_schema_it == schema_map.end())) {
+        return E_TABLE_NOT_EXIST;
+    }
+    auto table_schema = table_schema_it->second;
+
+    if (UNLIKELY(dev_it == schemas_.end()) ||
+        IS_NULL(device_schema = dev_it->second)) {
+
+        device_schema = new MeasurementSchemaGroup;
+        device_schema->is_aligned_ = true;
+        device_schema->time_chunk_writer_ = new TimeChunkWriter();
+        device_schema->time_chunk_writer_->init(
+            "", g_config_value_.time_encoding_type_,
+            g_config_value_.time_compress_type_);
+
+        for (int i = 0; i < table_schema->get_measurement_schemas().size(); 
++i) {
+            if (table_schema->get_column_categories().at(i) == 
common::ColumnCategory::FIELD) {
+                auto table_column_schema = 
table_schema->get_measurement_schemas().at(i);
+                auto device_column_schema = new 
MeasurementSchema(table_column_schema->measurement_name_,
+                        table_column_schema->data_type_, 
table_column_schema->encoding_,
+                        table_column_schema->compression_type_);
+                if (!table_column_schema->props_.empty()) {
+                    device_column_schema->props_ = table_column_schema->props_;
+                }
+                
device_schema->measurement_schema_map_[device_column_schema->measurement_name_] 
= device_column_schema;
+            }
+        }
+        schemas_[device_id] = device_schema;
+    }
+
+    uint32_t column_cnt = tablet.get_column_count();
+    if (tablet.column_categories_.empty()) {
+        for (uint32_t i = 0; i < column_cnt; i++) {
+            auto& col_name = tablet.get_column_name(i);
+            int col_index = table_schema->find_column_index(col_name);
+            const common::ColumnCategory column_category = 
table_schema->get_column_categories()[col_index];
+            tablet.column_categories_.emplace_back(column_category);

Review Comment:
   If col_name is not exist in table_schema, col_index will be -1, which will 
lead to overflow.



##########
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;
+        }

Review Comment:
   It's ok, when has_next is false, returning common::NO_MORE_DATA would be a 
better approach, just do it in future.



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