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/rowset_writer.h" |
31 | | #include "storage/rowset/rowset_writer_context.h" |
32 | | #include "storage/rowset/vertical_beta_rowset_writer.h" |
33 | | #include "storage/storage_engine.h" |
34 | | |
35 | | namespace doris { |
36 | | using namespace ErrorCode; |
37 | | |
38 | | Status RowsetFactory::create_rowset(const TabletSchemaSPtr& schema, const std::string& tablet_path, |
39 | | const RowsetMetaSharedPtr& rowset_meta, |
40 | 6.08k | RowsetSharedPtr* rowset) { |
41 | 6.08k | if (rowset_meta->rowset_type() == ALPHA_ROWSET) { |
42 | 0 | return Status::Error<ROWSET_INVALID>("invalid rowset_type"); |
43 | 0 | } |
44 | 6.08k | if (rowset_meta->rowset_type() == BETA_ROWSET) { |
45 | 6.08k | rowset->reset(new BetaRowset(schema, rowset_meta, tablet_path)); |
46 | 6.08k | return (*rowset)->init(); |
47 | 6.08k | } |
48 | 0 | return Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type"); // should never happen |
49 | 6.08k | } |
50 | | |
51 | | Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer( |
52 | 984 | StorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) { |
53 | 984 | if (context.rowset_type == ALPHA_ROWSET) { |
54 | 0 | return ResultError(Status::Error<ROWSET_INVALID>("invalid rowset_type")); |
55 | 0 | } |
56 | | |
57 | 984 | if (context.rowset_type == BETA_ROWSET) { |
58 | 984 | std::unique_ptr<RowsetWriter> writer; |
59 | 984 | if (is_vertical) { |
60 | 329 | writer = std::make_unique<VerticalBetaRowsetWriter<BetaRowsetWriter>>(engine); |
61 | 655 | } else { |
62 | 655 | writer = std::make_unique<BetaRowsetWriter>(engine); |
63 | 655 | } |
64 | 984 | RETURN_IF_ERROR_RESULT(writer->init(context)); |
65 | 984 | return writer; |
66 | 984 | } |
67 | | |
68 | 0 | return ResultError(Status::Error<ROWSET_TYPE_NOT_FOUND>("invalid rowset_type")); |
69 | 984 | } |
70 | | |
71 | | Result<std::unique_ptr<RowsetWriter>> RowsetFactory::create_rowset_writer( |
72 | 1 | CloudStorageEngine& engine, const RowsetWriterContext& context, bool is_vertical) { |
73 | 1 | DCHECK_EQ(context.rowset_type, BETA_ROWSET); |
74 | | // TODO(plat1ko): cloud vertical rowset writer |
75 | 1 | std::unique_ptr<RowsetWriter> writer; |
76 | 1 | if (is_vertical) { |
77 | 0 | writer = std::make_unique<VerticalBetaRowsetWriter<CloudRowsetWriter>>(engine); |
78 | 1 | } else { |
79 | 1 | writer = std::make_unique<CloudRowsetWriter>(engine); |
80 | 1 | } |
81 | | |
82 | 1 | RETURN_IF_ERROR_RESULT(writer->init(context)); |
83 | 1 | return writer; |
84 | 1 | } |
85 | | |
86 | | } // namespace doris |