Coverage Report

Created: 2026-03-13 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/file_factory.h
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
#pragma once
18
19
#include <gen_cpp/PlanNodes_types.h>
20
#include <gen_cpp/Types_types.h>
21
#include <glog/logging.h>
22
#include <stdint.h>
23
24
#include <map>
25
#include <memory>
26
#include <string>
27
28
#include "common/factory_creator.h"
29
#include "common/status.h"
30
#include "io/fs/file_reader.h"
31
#include "io/fs/file_reader_writer_fwd.h"
32
#include "io/fs/file_system.h"
33
34
namespace doris {
35
namespace io {
36
class FileSystem;
37
class FileWriter;
38
39
struct FileSystemProperties {
40
    TFileType::type system_type;
41
    std::map<std::string, std::string> properties;
42
    THdfsParams hdfs_params;
43
    std::vector<TNetworkAddress> broker_addresses;
44
};
45
46
struct FSPropertiesRef {
47
    TFileType::type type;
48
    const std::map<std::string, std::string>* properties {nullptr};
49
    const THdfsParams* hdfs_params {nullptr};
50
    const std::vector<TNetworkAddress>* broker_addresses {nullptr};
51
52
4.28k
    FSPropertiesRef(TFileType::type type_) : type(type_) {}
53
54
    FSPropertiesRef(const FileSystemProperties& fs_properties)
55
            : type(fs_properties.system_type),
56
              properties(&fs_properties.properties),
57
              hdfs_params(&fs_properties.hdfs_params),
58
0
              broker_addresses(&fs_properties.broker_addresses) {}
59
};
60
61
struct FileDescription {
62
    std::string path;
63
    // length of the file in bytes.
64
    // -1 means unset.
65
    // If the file length is not set, the file length will be fetched from the file system.
66
    int64_t file_size = -1;
67
    // modification time of this file.
68
    // 0 means unset.
69
    int64_t mtime = 0;
70
    // for hdfs, eg: hdfs://nameservices1/
71
    // because for a hive table, differenet partitions may have different
72
    // locations(or fs), so different files may have different fs.
73
    std::string fs_name;
74
};
75
76
} // namespace io
77
class ExecEnv;
78
class RuntimeProfile;
79
class RuntimeState;
80
81
class FileFactory {
82
    ENABLE_FACTORY_CREATOR(FileFactory);
83
84
public:
85
    static io::FileReaderOptions get_reader_options(RuntimeState* state,
86
                                                    const io::FileDescription& fd);
87
88
    /// Create a temporary FileSystem for accessing file corresponding to `file_description`
89
    /// FIXME(plat1ko): Declare the path formats supported by each file system
90
    static Result<io::FileSystemSPtr> create_fs(const io::FSPropertiesRef& fs_properties,
91
                                                const io::FileDescription& file_description);
92
93
    /// Create FileWriter without FS
94
    static Result<io::FileWriterPtr> create_file_writer(
95
            TFileType::type type, ExecEnv* env,
96
            const std::vector<TNetworkAddress>& broker_addresses,
97
            const std::map<std::string, std::string>& properties, const std::string& path,
98
            const io::FileWriterOptions& options);
99
100
    /// Create FileReader without FS
101
    static Result<io::FileReaderSPtr> create_file_reader(
102
            const io::FileSystemProperties& system_properties,
103
            const io::FileDescription& file_description,
104
            const io::FileReaderOptions& reader_options, RuntimeProfile* profile = nullptr);
105
106
    // Create FileReader for stream load pipe
107
    static Status create_pipe_reader(const TUniqueId& load_id, io::FileReaderSPtr* file_reader,
108
                                     RuntimeState* runtime_state, bool need_schema);
109
110
491
    static Result<TFileType::type> convert_storage_type(TStorageBackendType::type type) {
111
491
        switch (type) {
112
89
        case TStorageBackendType::LOCAL:
113
89
            return TFileType::FILE_LOCAL;
114
302
        case TStorageBackendType::S3:
115
302
            return TFileType::FILE_S3;
116
0
        case TStorageBackendType::AZURE:
117
0
            return TFileType::FILE_S3;
118
2
        case TStorageBackendType::BROKER:
119
2
            return TFileType::FILE_BROKER;
120
98
        case TStorageBackendType::HDFS:
121
98
            return TFileType::FILE_HDFS;
122
0
        default:
123
0
            return ResultError(Status::FatalError("not match type to convert, from type:{}", type));
124
491
        }
125
491
    }
126
127
private:
128
    static std::string _get_fs_name(const io::FileDescription& file_description);
129
130
    /// Create FileReader without FS
131
    static Result<io::FileReaderSPtr> _create_file_reader_internal(
132
            const io::FileSystemProperties& system_properties,
133
            const io::FileDescription& file_description,
134
            const io::FileReaderOptions& reader_options, RuntimeProfile* profile = nullptr);
135
};
136
137
} // namespace doris