Coverage Report

Created: 2026-07-07 17:25

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
12.7k
                                    RowsetSharedPtr* rowset) {
42
12.7k
    if (rowset_meta->rowset_type() == ALPHA_ROWSET) {
43
0
        return Status::Error<ROWSET_INVALID>("invalid rowset_type");
44
0
    }
45
12.7k
    if (rowset_meta->rowset_type() == BETA_ROWSET) {
46
12.7k
        rowset->reset(new BetaRowset(schema, rowset_meta, tablet_path));
47
12.7k
        return (*rowset)->init();
48
12.7k
    }
49
0
    return Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type"); // should never happen
50
12.7k
}
51
52
Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer(
53
2.05k
        StorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) {
54
2.05k
    if (context.rowset_type == ALPHA_ROWSET) {
55
0
        return ResultError(Status::Error<ROWSET_INVALID>("invalid rowset_type"));
56
0
    }
57
58
2.05k
    if (context.write_binlog_opt().enable) {
59
20
        std::unique_ptr<RowsetWriter> writer;
60
20
        if (is_vertical) {
61
0
            writer = std::make_unique<VerticalBetaRowsetWriter<RowBinlogRowsetWriter>>(engine);
62
0
            RETURN_IF_ERROR_RESULT(writer->init(context));
63
0
            return writer;
64
20
        } else {
65
20
            writer = std::make_unique<RowBinlogRowsetWriter>(engine);
66
20
            RETURN_IF_ERROR_RESULT(writer->init(context));
67
20
            return writer;
68
20
        }
69
20
    }
70
2.03k
    if (context.rowset_type == BETA_ROWSET) {
71
2.03k
        std::unique_ptr<RowsetWriter> writer;
72
2.03k
        if (is_vertical) {
73
736
            writer = std::make_unique<VerticalBetaRowsetWriter<BetaRowsetWriter>>(engine);
74
1.29k
        } else {
75
1.29k
            writer = std::make_unique<BetaRowsetWriter>(engine);
76
1.29k
        }
77
2.03k
        RETURN_IF_ERROR_RESULT(writer->init(context));
78
2.03k
        return writer;
79
2.03k
    }
80
81
0
    return ResultError(Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type"));
82
2.03k
}
83
84
Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer(
85
2
        CloudStorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) {
86
2
    DCHECK_EQ(context.rowset_type, BETA_ROWSET);
87
    // TODO(plat1ko): cloud vertical rowset writer
88
2
    std::unique_ptr<RowsetWriter> writer;
89
2
    if (is_vertical) {
90
0
        writer = std::make_unique<VerticalBetaRowsetWriter<CloudRowsetWriter>>(engine);
91
2
    } else {
92
2
        writer = std::make_unique<CloudRowsetWriter>(engine);
93
2
    }
94
95
2
    RETURN_IF_ERROR_RESULT(writer->init(context));
96
2
    return writer;
97
2
}
98
99
14
Status RowsetFactory::create_empty_group_rowset_writer(std::unique_ptr<GroupRowsetWriter>* output) {
100
14
    output->reset(new GroupRowsetWriter());
101
14
    return Status::OK();
102
14
}
103
104
} // namespace doris