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


##########
cpp/src/common/schema.h:
##########
@@ -84,5 +113,147 @@ struct MeasurementSchemaGroup {
     TimeChunkWriter *time_chunk_writer_ = nullptr;
 };
 
+enum class ColumnCategory { ID, MEASUREMENT };
+
+class TableSchema {
+   public:
+    TableSchema() = default;
+    TableSchema(const std::string &table_name,
+                const std::vector<std::shared_ptr<MeasurementSchema>>
+                    &measurement_schemas,
+                const std::vector<ColumnCategory> &column_categories)
+        : table_name_(table_name),
+          measurement_schemas_(measurement_schemas),
+          column_categories_(column_categories) {
+        int idx = 0;
+        for (auto &measurement_schema : measurement_schemas_) {
+            column_pos_index_.insert(
+                std::make_pair(measurement_schema->measurement_name_, idx++));
+        }
+    }
+
+    TableSchema(TableSchema &&other) noexcept
+        : table_name_(std::move(other.table_name_)),
+          measurement_schemas_(std::move(other.measurement_schemas_)),
+          column_categories_(std::move(other.column_categories_)) {}
+
+    TableSchema(const TableSchema &other) = default;
+
+    int serialize_to(common::ByteStream &out) {
+        int ret = common::E_OK;
+        if (RET_FAIL(common::SerializationUtil::write_var_uint(
+                measurement_schemas_.size(), out))) {
+        } else {
+            for (size_t i = 0; IS_SUCC(ret) && i < measurement_schemas_.size();
+                 i++) {
+                auto column_schema = measurement_schemas_[i];
+                auto column_category = column_categories_[i];
+                // column_schema-
+                common::SerializationUtil::write_i32(
+                    static_cast<int32_t>(column_category), out);
+            }
+        }
+        return ret;
+    }
+
+    ~TableSchema() = default;
+
+    std::string get_table_name() { return table_name_; }
+
+    std::vector<std::string> get_measurement_names() const {
+        std::vector<std::string> ret;
+        for (const auto &measurement_schema : measurement_schemas_) {
+            ret.emplace_back(measurement_schema->measurement_name_);
+        }
+        return ret;
+    }
+
+    int find_column_index(std::string column_name) {
+        std::string lower_case_column_name = to_lower(column_name);
+        auto it = column_pos_index_.find(lower_case_column_name);
+        if (it != column_pos_index_.end()) {
+            return it->second;
+        } else {
+            int index = -1;
+            for (size_t i = 0; i < measurement_schemas_.size(); ++i) {
+                if (to_lower(measurement_schemas_[i]->measurement_name_) ==
+                    lower_case_column_name) {
+                    index = static_cast<int>(i);
+                    break;
+                }
+            }
+            column_pos_index_[lower_case_column_name] = index;
+            return index;
+        }
+    }
+
+    void update(ChunkGroupMeta *chunk_group_meta) {
+        for (auto iter = chunk_group_meta->chunk_meta_list_.begin();
+             iter != chunk_group_meta->chunk_meta_list_.end(); iter++) {
+            auto &chunk_meta = iter.get();
+            int column_idx =
+                find_column_index(chunk_meta->measurement_name_.to_string());
+            if (column_idx == -1) {
+                auto measurement_schema = std::make_shared<MeasurementSchema>(
+                    chunk_meta->measurement_name_.to_string(),
+                    chunk_meta->data_type_, chunk_meta->encoding_,
+                    chunk_meta->compression_type_);
+                measurement_schemas_.emplace_back(measurement_schema);
+                column_categories_.emplace_back(ColumnCategory::MEASUREMENT);
+                column_pos_index_.insert(
+                    std::make_pair(chunk_meta->measurement_name_.to_string(),
+                                   measurement_schemas_.size() - 1));
+            } else {
+                auto origin_measurement_schema =
+                    measurement_schemas_.at(column_idx);
+                if (origin_measurement_schema->data_type_ !=
+                    chunk_meta->data_type_) {
+                    origin_measurement_schema->data_type_ =
+                        common::TSDataType::STRING;
+                }

Review Comment:
   Why need to change it to STRING?



##########
cpp/src/common/global.cc:
##########
@@ -46,6 +46,32 @@ void init_config_value() {
     g_config_value_.time_compress_type_ = LZ4;
 }
 
+extern TSEncoding get_value_encoder(TSDataType data_type) {
+    switch (data_type) {
+        case BOOLEAN:
+            return TSEncoding::RLE;
+        case INT32:
+            return TSEncoding::TS_2DIFF;
+        case INT64:
+            return TSEncoding::TS_2DIFF;
+        case FLOAT:
+            return TSEncoding::GORILLA;
+        case DOUBLE:
+            return TSEncoding::GORILLA;
+        case TEXT:
+            return TSEncoding::PLAIN;
+        case VECTOR:
+            break;
+        case NULL_TYPE:
+            break;
+        case INVALID_DATATYPE:
+            break;
+        default:
+            break;
+    }
+    return TSEncoding::PLAIN;

Review Comment:
   Note that silently converting unsupported encoding formats to PLAIN may 
cause issues. Some form of feedback or notification is needed.



##########
cpp/src/file/tsfile_io_writer.h:
##########
@@ -68,7 +70,19 @@ class TsFileIOWriter {
           cur_device_name_(),
           file_(nullptr),
           ts_time_index_vector_(),
-          write_file_created_(false) {}
+          write_file_created_(false),
+          generate_table_schema_(false),
+          schema_(std::make_shared<Schema>()) {
+        if (common::g_config_value_.encrypt_flag_) {
+            // TODO: support encrypt
+            encrypt_level_ = "2";
+            encrypt_type_ = "";
+            encrypt_type_ = "";

Review Comment:
   double encrypt_type_



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