|
5 | 5 | #include "duckdb/common/multi_file_reader.hpp" |
6 | 6 | #include "duckdb/function/table_function.hpp" |
7 | 7 | #include "duckdb/main/extension_util.hpp" |
| 8 | +#include "duckdb/common/file_system.hpp" |
8 | 9 | #include "vortex_extension.hpp" |
9 | 10 |
|
10 | | -#include <filesystem> |
| 11 | +#include <regex> |
11 | 12 |
|
12 | 13 | #include "vortex_common.hpp" |
13 | 14 | #include "expr/expr.hpp" |
@@ -150,23 +151,20 @@ static void ExtractVortexSchema(const vx_dtype *file_dtype, vector<LogicalType> |
150 | 151 | } |
151 | 152 | } |
152 | 153 |
|
153 | | -std::string EnsureFileProtocol(const std::string &path) { |
154 | | - auto absolute_path = path; |
155 | | - const std::string prefix = "file://"; |
| 154 | +const std::regex schema_prefix = std::regex("^[^/]*:\\/\\/.*$"); |
156 | 155 |
|
157 | | - std::filesystem::path p = absolute_path; |
158 | | - if (!p.is_absolute()) { |
159 | | - try { |
160 | | - absolute_path = absolute(p).string(); |
161 | | - } catch (const std::exception &e) { |
162 | | - throw InternalException(std::string("Error making path absolute: ") + e.what()); |
163 | | - } |
| 156 | +std::string EnsureFileProtocol(FileSystem &fs, const std::string &path) { |
| 157 | + // If the path is a URL then don't change it, otherwise try to make the path an absolute path |
| 158 | + if (std::regex_match(path, schema_prefix)) { |
| 159 | + return path; |
164 | 160 | } |
165 | 161 |
|
166 | | - // Check if the string already starts with "file://" |
167 | | - if (absolute_path.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), absolute_path.begin())) { |
168 | | - return absolute_path; |
| 162 | + const std::string prefix = "file://"; |
| 163 | + if (fs.IsPathAbsolute(path)) { |
| 164 | + return prefix + path; |
169 | 165 | } |
| 166 | + |
| 167 | + const auto absolute_path = fs.JoinPath(fs.GetWorkingDirectory(), path); |
170 | 168 | return prefix + absolute_path; |
171 | 169 | } |
172 | 170 |
|
@@ -209,13 +207,14 @@ static void VerifyNewFile(const VortexBindData &bind_data, vector<LogicalType> & |
209 | 207 | } |
210 | 208 | } |
211 | 209 |
|
212 | | -static unique_ptr<VortexFileReader> OpenFileAndVerify(const std::string &filename, const VortexBindData &bind_data) { |
| 210 | +static unique_ptr<VortexFileReader> OpenFileAndVerify(FileSystem &fs, const std::string &filename, |
| 211 | + const VortexBindData &bind_data) { |
213 | 212 | auto new_column_names = vector<string>(); |
214 | 213 | new_column_names.reserve(bind_data.column_names.size()); |
215 | 214 | auto new_column_types = vector<LogicalType>(); |
216 | 215 | new_column_names.reserve(bind_data.columns_types.size()); |
217 | 216 |
|
218 | | - auto file = OpenFile(EnsureFileProtocol(filename), new_column_types, new_column_names); |
| 217 | + auto file = OpenFile(EnsureFileProtocol(fs, filename), new_column_types, new_column_names); |
219 | 218 | VerifyNewFile(bind_data, new_column_types, new_column_names); |
220 | 219 | return file; |
221 | 220 | } |
@@ -268,7 +267,7 @@ static void VortexScanFunction(ClientContext &context, TableFunctionInput &data, |
268 | 267 | } |
269 | 268 |
|
270 | 269 | auto file_name = global_state.expanded_files[file_idx]; |
271 | | - auto file = OpenFileAndVerify(file_name, bind_data); |
| 270 | + auto file = OpenFileAndVerify(FileSystem::GetFileSystem(context), file_name, bind_data); |
272 | 271 |
|
273 | 272 | slot.array_stream = OpenArrayStream(bind_data, global_state, file.get()); |
274 | 273 | } |
@@ -309,7 +308,7 @@ static unique_ptr<FunctionData> VortexBind(ClientContext &context, TableFunction |
309 | 308 | auto vec = duckdb::vector<string> {input.inputs[0].GetValue<string>()}; |
310 | 309 | result->file_list = make_shared_ptr<GlobMultiFileList>(context, vec, FileGlobOptions::DISALLOW_EMPTY); |
311 | 310 |
|
312 | | - auto filename = EnsureFileProtocol(result->file_list->GetFirstFile()); |
| 311 | + auto filename = EnsureFileProtocol(FileSystem::GetFileSystem(context), result->file_list->GetFirstFile()); |
313 | 312 |
|
314 | 313 | result->initial_file = OpenFile(filename, column_types, column_names); |
315 | 314 |
|
@@ -366,7 +365,7 @@ void RegisterVortexScanFunction(DatabaseInstance &instance) { |
366 | 365 |
|
367 | 366 | // Most expressions are extracted from `PushdownComplexFilter`, the final filters come from `input.filters`. |
368 | 367 | vector<vortex::expr::Expr *> conjuncts; |
369 | | - std::ranges::copy(bind.conjuncts, std::back_inserter(conjuncts)); |
| 368 | + std::copy(bind.conjuncts.begin(), bind.conjuncts.end(), std::back_inserter(conjuncts)); |
370 | 369 | CreateFilterExpression(*bind.arena, bind.column_names, input.filters, input.column_ids, conjuncts); |
371 | 370 |
|
372 | 371 | auto column_names = std::vector<char const *>(); |
|
0 commit comments