Coverage Report

Created: 2026-05-12 18:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/rowset/rowset_factory.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "storage/rowset/rowset_factory.h"
19
20
#include <gen_cpp/olap_file.pb.h>
21
22
#include <memory>
23
24
#include "cloud/cloud_rowset_writer.h"
25
#include "cloud/config.h"
26
#include "io/fs/file_writer.h" // IWYU pragma: keep
27
#include "runtime/exec_env.h"
28
#include "storage/rowset/beta_rowset.h"
29
#include "storage/rowset/beta_rowset_writer.h"
30
#include "storage/rowset/group_rowset_writer.h"
31
#include "storage/rowset/rowset_writer.h"
32
#include "storage/rowset/rowset_writer_context.h"
33
#include "storage/rowset/vertical_beta_rowset_writer.h"
34
#include "storage/storage_engine.h"
35
36
namespace doris {
37
using namespace ErrorCode;
38
39
Status RowsetFactory::create_rowset(const TabletSchemaSPtr& schema, const std::string& tablet_path,
40
                                    const RowsetMetaSharedPtr& rowset_meta,
41
6.24k
                                    RowsetSharedPtr* rowset) {
42
6.24k
    if (rowset_meta->rowset_type() == ALPHA_ROWSET) {
43
0
        return Status::Error<ROWSET_INVALID>("invalid rowset_type");
44
0
    }
45
6.24k
    if (rowset_meta->rowset_type() == BETA_ROWSET) {
46
6.24k
        rowset->reset(new BetaRowset(schema, rowset_meta, tablet_path));
47
6.24k
        return (*rowset)->init();
48
6.24k
    }
49
0
    return Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type"); // should never happen
50
6.24k
}
51
52
Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer(
53
997
        StorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) {
54
997
    if (context.rowset_type == ALPHA_ROWSET) {
55
0
        return ResultError(Status::Error<ROWSET_INVALID>("invalid rowset_type"));
56
0
    }
57
58
997
    if (context.write_binlog_opt().is_binlog_writer()) {
59
0
        std::unique_ptr<RowsetWriter> writer;
60
0
        if (is_vertical) {
61
0
            writer = std::make_unique<VerticalRowBinlogRowsetWriter<BetaRowsetWriter>>(engine);
62
0
            RETURN_IF_ERROR_RESULT(writer->init(context));
63
0
            return writer;
64
0
        } else {
65
0
            writer = std::make_unique<RowBinlogRowsetWriter>(engine);
66
0
            RETURN_IF_ERROR_RESULT(writer->init(context));
67
0
            return writer;
68
0
        }
69
0
    }
70
997
    if (context.rowset_type == BETA_ROWSET) {
71
997
        std::unique_ptr<RowsetWriter> writer;
72
997
        if (is_vertical) {
73
336
            writer = std::make_unique<VerticalBetaRowsetWriter<BetaRowsetWriter>>(engine);
74
661
        } else {
75
661
            writer = std::make_unique<BetaRowsetWriter>(engine);
76
661
        }
77
997
        RETURN_IF_ERROR_RESULT(writer->init(context));
78
997
        return writer;
79
997
    }
80
81
0
    return ResultError(Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type"));
82
997
}
83
84
Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer(
85
1
        CloudStorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) {
86
1
    DCHECK_EQ(context.rowset_type, BETA_ROWSET);
87
    // TODO(plat1ko): cloud vertical rowset writer
88
1
    std::unique_ptr<RowsetWriter> writer;
89
1
    if (is_vertical) {
90
0
        writer = std::make_unique<VerticalBetaRowsetWriter<CloudRowsetWriter>>(engine);
91
1
    } else {
92
1
        writer = std::make_unique<CloudRowsetWriter>(engine);
93
1
    }
94
95
1
    RETURN_IF_ERROR_RESULT(writer->init(context));
96
1
    return writer;
97
1
}
98
99
0
Status RowsetFactory::create_empty_group_rowset_writer(std::unique_ptr<GroupRowsetWriter>* output) {
100
0
    output->reset(new GroupRowsetWriter());
101
0
    return Status::OK();
102
0
}
103
104
} // namespace doris