github-actions[bot] commented on code in PR #19063:
URL: https://github.com/apache/doris/pull/19063#discussion_r1189797741


##########
be/src/olap/task/build_inverted_index.cpp:
##########
@@ -0,0 +1,437 @@
+// 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 "olap/task/build_inverted_index.h"
+
+#include "common/status.h"
+#include "olap/rowset/beta_rowset.h"
+#include "olap/rowset/rowset_writer.h"
+#include "olap/rowset/rowset_writer_context.h"
+#include "olap/segment_loader.h"
+#include "olap/storage_engine.h"
+#include "olap/tablet_schema.h"
+#include "runtime/memory/mem_tracker.h"
+#include "runtime/thread_context.h"
+
+namespace doris {
+
+BuildInvertedIndex::BuildInvertedIndex(const TabletSharedPtr& tablet,
+                const std::vector<TColumn>& columns,
+                const std::vector<TOlapTableIndex> exist_indexes,
+                const std::vector<doris::TOlapTableIndex>& 
alter_inverted_indexes,
+                bool is_drop_op)
+                : _tablet(tablet),
+                _columns(columns),
+                _exist_indexes(exist_indexes),
+                _alter_inverted_indexes(alter_inverted_indexes),
+                _is_drop_op(is_drop_op) {
+    _olap_data_convertor = 
std::make_unique<vectorized::OlapBlockDataConvertor>();
+}
+
+BuildInvertedIndex::~BuildInvertedIndex() {

Review Comment:
   warning: use '= default' to define a trivial destructor 
[modernize-use-equals-default]
   ```cpp
   BuildInvertedIndex::~BuildInvertedIndex() {
                       ^
   ```
   



##########
be/src/olap/task/build_inverted_index.cpp:
##########
@@ -0,0 +1,437 @@
+// 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 "olap/task/build_inverted_index.h"
+
+#include "common/status.h"
+#include "olap/rowset/beta_rowset.h"
+#include "olap/rowset/rowset_writer.h"
+#include "olap/rowset/rowset_writer_context.h"
+#include "olap/segment_loader.h"
+#include "olap/storage_engine.h"
+#include "olap/tablet_schema.h"
+#include "runtime/memory/mem_tracker.h"
+#include "runtime/thread_context.h"
+
+namespace doris {
+
+BuildInvertedIndex::BuildInvertedIndex(const TabletSharedPtr& tablet,
+                const std::vector<TColumn>& columns,
+                const std::vector<TOlapTableIndex> exist_indexes,
+                const std::vector<doris::TOlapTableIndex>& 
alter_inverted_indexes,
+                bool is_drop_op)
+                : _tablet(tablet),
+                _columns(columns),
+                _exist_indexes(exist_indexes),
+                _alter_inverted_indexes(alter_inverted_indexes),
+                _is_drop_op(is_drop_op) {
+    _olap_data_convertor = 
std::make_unique<vectorized::OlapBlockDataConvertor>();
+}
+
+BuildInvertedIndex::~BuildInvertedIndex() {
+    _olap_data_convertor.reset();
+    _inverted_index_builders.clear();
+}
+
+Status BuildInvertedIndex::init() {
+    _cur_tablet_schema = std::make_shared<TabletSchema>();
+    _cur_tablet_schema->update_tablet_columns(*_tablet->tablet_schema(), 
_columns);
+    for (auto inverted_index : _alter_inverted_indexes) {
+        auto column_name = inverted_index.columns[0];
+        auto column_idx = _cur_tablet_schema->field_index(column_name);
+        if (column_idx < 0) {
+            LOG(WARNING) << "referenced column was missing. "
+                         << "[column=" << column_name << " referenced_column=" 
<< column_idx
+                         << "]";
+            return Status::Error<ErrorCode::CE_CMD_PARAMS_ERROR>();
+        }
+        auto column = _cur_tablet_schema->column(column_idx);
+        _alter_column_uids.emplace_back(column.unique_id());
+    }
+    return Status::OK();
+}
+
+Status BuildInvertedIndex::update_inverted_index_info() {
+    // just do link files
+    LOG(INFO) << "begin to update_inverted_index_info, tablet=" << 
_tablet->tablet_id()
+            << ", is_drop_op=" << _is_drop_op;
+    for (auto i = 0; i < _input_rowsets.size(); ++i) {
+        auto input_rowset = _input_rowsets[i];
+        TabletSchemaSPtr output_rs_tablet_schema = 
std::make_shared<TabletSchema>();
+        output_rs_tablet_schema->copy_from(*input_rowset->tablet_schema());
+        if (_is_drop_op) {
+            
output_rs_tablet_schema->update_indexes_from_thrift(_exist_indexes);
+        } else {
+            for (auto t_inverted_index : _alter_inverted_indexes) {
+                TabletIndex index;
+                index.init_from_thrift(t_inverted_index, *_cur_tablet_schema);
+                output_rs_tablet_schema->append_index(std::move(index));
+            }
+        }
+        // construct input rowset reader
+        RowsetReaderSharedPtr input_rs_reader;
+        RETURN_NOT_OK(input_rowset->create_reader(&input_rs_reader));
+        
+        // construct output rowset writer
+        std::unique_ptr<RowsetWriter> output_rs_writer;
+        RowsetWriterContext context;
+        context.version = input_rs_reader->version();
+        context.rowset_state = VISIBLE;
+        context.segments_overlap = 
input_rs_reader->rowset()->rowset_meta()->segments_overlap();
+        context.tablet_schema = output_rs_tablet_schema;
+        context.newest_write_timestamp = 
input_rs_reader->newest_write_timestamp();
+        context.fs = input_rs_reader->rowset()->rowset_meta()->fs();
+        Status status = _tablet->create_rowset_writer(context, 
&output_rs_writer);
+        if (!status.ok()) {
+            return Status::Error<ErrorCode::ROWSET_BUILDER_INIT>();
+        }
+        std::set<int32_t> alter_column_ids_set(_alter_column_uids.begin(), 
_alter_column_uids.end());
+        RETURN_NOT_OK(input_rowset->link_files_without_index_to(
+                        _tablet->tablet_path(), output_rs_writer->rowset_id(), 
alter_column_ids_set)); // build output rowset
+        
+        auto input_rowset_meta = input_rowset->rowset_meta();
+        RowsetMetaSharedPtr rowset_meta = std::make_shared<RowsetMeta>();
+        rowset_meta->set_num_rows(input_rowset_meta->num_rows());
+        rowset_meta->set_total_disk_size(input_rowset_meta->total_disk_size());
+        rowset_meta->set_data_disk_size(input_rowset_meta->data_disk_size());
+        rowset_meta->set_index_disk_size(input_rowset_meta->index_disk_size());
+        rowset_meta->set_empty(input_rowset_meta->empty());
+        rowset_meta->set_num_segments(input_rowset_meta->num_segments());
+        
rowset_meta->set_segments_overlap(input_rowset_meta->segments_overlap());
+        rowset_meta->set_rowset_state(input_rowset_meta->rowset_state());
+        if (input_rowset_meta->has_delete_predicate()) {
+            
rowset_meta->set_delete_predicate(input_rowset_meta->delete_predicate());
+        }
+        std::vector<KeyBoundsPB> key_bounds;
+        input_rowset->get_segments_key_bounds(&key_bounds);
+        rowset_meta->set_segments_key_bounds(key_bounds);
+        auto output_rowset = output_rs_writer->manual_build(rowset_meta);
+        _output_rowsets.push_back(output_rowset);
+    }
+
+    return Status::OK();
+}
+
+Status BuildInvertedIndex::handle_single_rowset(RowsetMetaSharedPtr 
output_rowset_meta,

Review Comment:
   warning: method 'handle_single_rowset' can be made const 
[readability-make-member-function-const]
   
   be/src/olap/task/build_inverted_index.cpp:129:
   ```diff
   -                                 std::vector<segment_v2::SegmentSharedPtr>& 
segments) {
   +                                 std::vector<segment_v2::SegmentSharedPtr>& 
segments) const {
   ```
   



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