Tanya-W commented on code in PR #16371:
URL: https://github.com/apache/doris/pull/16371#discussion_r1098508480


##########
be/src/olap/schema_change.cpp:
##########
@@ -576,6 +583,248 @@ Status 
VSchemaChangeWithSorting::_external_sorting(vector<RowsetSharedPtr>& src_
     return Status::OK();
 }
 
+SchemaChangeForInvertedIndex::SchemaChangeForInvertedIndex(
+        const std::vector<TOlapTableIndex>& alter_inverted_indexs,
+        const TabletSchemaSPtr& tablet_schema)
+        : SchemaChange(),
+          _alter_inverted_indexs(alter_inverted_indexs),
+          _tablet_schema(tablet_schema) {}
+
+SchemaChangeForInvertedIndex::~SchemaChangeForInvertedIndex() {
+    VLOG_NOTICE << "~SchemaChangeForInvertedIndex()";
+    _inverted_index_builders.clear();
+    _index_metas.clear();
+}
+
+Status SchemaChangeForInvertedIndex::process(RowsetReaderSharedPtr 
rowset_reader,
+                                             RowsetWriter* rowset_writer,
+                                             TabletSharedPtr new_tablet,
+                                             TabletSharedPtr base_tablet,
+                                             TabletSchemaSPtr 
base_tablet_schema) {
+    Status res = Status::OK();
+    if (rowset_reader->rowset()->empty() || 
rowset_reader->rowset()->num_rows() == 0) {
+        return Status::OK();
+    }
+
+    std::vector<ColumnId> return_columns;
+    for (auto& inverted_index : _alter_inverted_indexs) {
+        DCHECK_EQ(inverted_index.columns.size(), 1);
+        auto column_name = inverted_index.columns[0];
+        auto idx = _tablet_schema->field_index(column_name);
+        return_columns.emplace_back(idx);
+    }
+
+    // create inverted index writer
+    auto rowset_meta = rowset_reader->rowset()->rowset_meta();
+    std::string segment_dir = base_tablet->tablet_path();
+    auto fs = rowset_meta->fs();
+    for (auto i = 0; i < rowset_meta->num_segments(); ++i) {
+        std::string segment_filename =
+                fmt::format("{}_{}.dat", rowset_meta->rowset_id().to_string(), 
i);
+        for (auto& inverted_index : _alter_inverted_indexs) {
+            DCHECK_EQ(inverted_index.columns.size(), 1);
+            auto column_name = inverted_index.columns[0];
+            auto column = _tablet_schema->column(column_name);
+            auto index_id = inverted_index.index_id;
+
+            std::unique_ptr<Field> field(FieldFactory::create(column));
+            _index_metas.emplace_back(new TabletIndex());
+            _index_metas.back()->init_from_thrift(inverted_index, 
*_tablet_schema);
+            std::unique_ptr<segment_v2::InvertedIndexColumnWriter> 
inverted_index_builder;
+            try {
+                RETURN_IF_ERROR(segment_v2::InvertedIndexColumnWriter::create(
+                        field.get(), &inverted_index_builder, 
segment_filename, segment_dir,
+                        _index_metas.back().get(), fs));
+            } catch (const std::exception& e) {
+                LOG(WARNING) << "CLuceneError occured: " << e.what();
+                return Status::Error<IO_ERROR>();
+            }
+
+            if (inverted_index_builder) {
+                std::string writer_sign = fmt::format("{}_{}", i, index_id);

Review Comment:
   you are right, use pair as key  is better.



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to