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