]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 | #pragma once | |
19 | ||
20 | #include <memory> | |
21 | #include <string> | |
22 | #include <vector> | |
23 | ||
24 | #include "arrow/filesystem/filesystem.h" | |
25 | #include "arrow/python/common.h" | |
26 | #include "arrow/python/visibility.h" | |
27 | #include "arrow/util/macros.h" | |
28 | ||
29 | namespace arrow { | |
30 | namespace py { | |
31 | namespace fs { | |
32 | ||
33 | class ARROW_PYTHON_EXPORT PyFileSystemVtable { | |
34 | public: | |
35 | std::function<void(PyObject*, std::string* out)> get_type_name; | |
36 | std::function<bool(PyObject*, const arrow::fs::FileSystem& other)> equals; | |
37 | ||
38 | std::function<void(PyObject*, const std::string& path, arrow::fs::FileInfo* out)> | |
39 | get_file_info; | |
40 | std::function<void(PyObject*, const std::vector<std::string>& paths, | |
41 | std::vector<arrow::fs::FileInfo>* out)> | |
42 | get_file_info_vector; | |
43 | std::function<void(PyObject*, const arrow::fs::FileSelector&, | |
44 | std::vector<arrow::fs::FileInfo>* out)> | |
45 | get_file_info_selector; | |
46 | ||
47 | std::function<void(PyObject*, const std::string& path, bool)> create_dir; | |
48 | std::function<void(PyObject*, const std::string& path)> delete_dir; | |
49 | std::function<void(PyObject*, const std::string& path)> delete_dir_contents; | |
50 | std::function<void(PyObject*)> delete_root_dir_contents; | |
51 | std::function<void(PyObject*, const std::string& path)> delete_file; | |
52 | std::function<void(PyObject*, const std::string& src, const std::string& dest)> move; | |
53 | std::function<void(PyObject*, const std::string& src, const std::string& dest)> | |
54 | copy_file; | |
55 | ||
56 | std::function<void(PyObject*, const std::string& path, | |
57 | std::shared_ptr<io::InputStream>* out)> | |
58 | open_input_stream; | |
59 | std::function<void(PyObject*, const std::string& path, | |
60 | std::shared_ptr<io::RandomAccessFile>* out)> | |
61 | open_input_file; | |
62 | std::function<void(PyObject*, const std::string& path, | |
63 | const std::shared_ptr<const KeyValueMetadata>&, | |
64 | std::shared_ptr<io::OutputStream>* out)> | |
65 | open_output_stream; | |
66 | std::function<void(PyObject*, const std::string& path, | |
67 | const std::shared_ptr<const KeyValueMetadata>&, | |
68 | std::shared_ptr<io::OutputStream>* out)> | |
69 | open_append_stream; | |
70 | ||
71 | std::function<void(PyObject*, const std::string& path, std::string* out)> | |
72 | normalize_path; | |
73 | }; | |
74 | ||
75 | class ARROW_PYTHON_EXPORT PyFileSystem : public arrow::fs::FileSystem { | |
76 | public: | |
77 | PyFileSystem(PyObject* handler, PyFileSystemVtable vtable); | |
78 | ~PyFileSystem() override; | |
79 | ||
80 | static std::shared_ptr<PyFileSystem> Make(PyObject* handler, PyFileSystemVtable vtable); | |
81 | ||
82 | std::string type_name() const override; | |
83 | ||
84 | bool Equals(const FileSystem& other) const override; | |
85 | ||
86 | Result<arrow::fs::FileInfo> GetFileInfo(const std::string& path) override; | |
87 | Result<std::vector<arrow::fs::FileInfo>> GetFileInfo( | |
88 | const std::vector<std::string>& paths) override; | |
89 | Result<std::vector<arrow::fs::FileInfo>> GetFileInfo( | |
90 | const arrow::fs::FileSelector& select) override; | |
91 | ||
92 | Status CreateDir(const std::string& path, bool recursive = true) override; | |
93 | ||
94 | Status DeleteDir(const std::string& path) override; | |
95 | Status DeleteDirContents(const std::string& path) override; | |
96 | Status DeleteRootDirContents() override; | |
97 | ||
98 | Status DeleteFile(const std::string& path) override; | |
99 | ||
100 | Status Move(const std::string& src, const std::string& dest) override; | |
101 | ||
102 | Status CopyFile(const std::string& src, const std::string& dest) override; | |
103 | ||
104 | Result<std::shared_ptr<io::InputStream>> OpenInputStream( | |
105 | const std::string& path) override; | |
106 | Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( | |
107 | const std::string& path) override; | |
108 | Result<std::shared_ptr<io::OutputStream>> OpenOutputStream( | |
109 | const std::string& path, | |
110 | const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; | |
111 | Result<std::shared_ptr<io::OutputStream>> OpenAppendStream( | |
112 | const std::string& path, | |
113 | const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; | |
114 | ||
115 | Result<std::string> NormalizePath(std::string path) override; | |
116 | ||
117 | PyObject* handler() const { return handler_.obj(); } | |
118 | ||
119 | private: | |
120 | OwnedRefNoGIL handler_; | |
121 | PyFileSystemVtable vtable_; | |
122 | }; | |
123 | ||
124 | } // namespace fs | |
125 | } // namespace py | |
126 | } // namespace arrow |