blob: e3b536f54614a7f8dde957e340b909371f095e49 [file]
// 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.
#pragma once
#include "storage/field.h"
#include "storage/index/index_file_writer.h"
#include "storage/index/inverted/inverted_index_desc.h"
#include "storage/iterator/olap_data_convertor.h"
#include "storage/merger.h"
#include "storage/olap_common.h"
#include "storage/olap_define.h"
#include "storage/rowset/pending_rowset_helper.h"
#include "storage/rowset/rowset_fwd.h"
#include "storage/segment/segment.h"
#include "storage/tablet/tablet_fwd.h"
namespace doris {
namespace segment_v2 {
class IndexColumnWriter;
class IndexFileWriter;
} // namespace segment_v2
class OlapBlockDataConvertor;
class StorageField;
class StorageEngine;
class RowsetWriter;
using RowsetWriterUniquePtr = std::unique_ptr<RowsetWriter>;
class IndexBuilder {
public:
IndexBuilder(StorageEngine& engine, TabletSharedPtr tablet, const std::vector<TColumn>& columns,
const std::vector<doris::TOlapTableIndex>& alter_inverted_indexes,
bool is_drop_op = false);
virtual ~IndexBuilder();
virtual Status init();
virtual Status do_build_inverted_index();
virtual Status update_inverted_index_info();
virtual Status handle_inverted_index_data();
virtual Status handle_single_rowset(RowsetMetaSharedPtr output_rowset_meta,
std::vector<segment_v2::SegmentSharedPtr>& segments);
virtual Status modify_rowsets(const Merger::Statistics* stats = nullptr);
virtual void gc_output_rowset();
private:
Status _write_inverted_index_data(TabletSchemaSPtr tablet_schema, int64_t segment_idx,
Block* block);
Status _add_data(const std::string& column_name,
const std::pair<int64_t, int64_t>& index_writer_sign, StorageField* field,
const uint8_t** ptr, size_t num_rows);
Status _add_nullable(const std::string& column_name,
const std::pair<int64_t, int64_t>& index_writer_sign, StorageField* field,
const uint8_t* null_map, const uint8_t** ptr, size_t num_rows);
private:
StorageEngine& _engine;
TabletSharedPtr _tablet;
std::vector<TColumn> _columns;
std::vector<doris::TOlapTableIndex> _alter_inverted_indexes;
std::vector<TabletIndex> _dropped_inverted_indexes;
bool _is_drop_op;
std::set<int64_t> _alter_index_ids;
std::vector<RowsetSharedPtr> _input_rowsets;
std::vector<RowsetSharedPtr> _output_rowsets;
std::vector<PendingRowsetGuard> _pending_rs_guards;
std::vector<RowsetReaderSharedPtr> _input_rs_readers;
std::unique_ptr<OlapBlockDataConvertor> _olap_data_convertor;
// "<segment_id, index_id>" -> IndexColumnWriter
std::unordered_map<std::pair<int64_t, int64_t>, std::unique_ptr<segment_v2::IndexColumnWriter>>
_index_column_writers;
std::unordered_map<int64_t, std::unique_ptr<IndexFileWriter>> _index_file_writers;
// <rowset_id, segment_id>
std::unordered_map<std::pair<std::string, int64_t>, std::unique_ptr<IndexFileReader>>
_index_file_readers;
};
using IndexBuilderSharedPtr = std::shared_ptr<IndexBuilder>;
} // namespace doris