Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
interfaces.h
Go to the documentation of this file.
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 #ifndef ARROW_IO_INTERFACES_H
19 #define ARROW_IO_INTERFACES_H
20 
21 #include <cstdint>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "arrow/util/macros.h"
27 #include "arrow/util/visibility.h"
28 
29 namespace arrow {
30 
31 class Buffer;
32 class Status;
33 
34 namespace io {
35 
36 struct FileMode {
37  enum type { READ, WRITE, READWRITE };
38 };
39 
40 struct ObjectType {
41  enum type { FILE, DIRECTORY };
42 };
43 
44 struct ARROW_EXPORT FileStatistics {
46  int64_t size;
48 };
49 
50 class ARROW_EXPORT FileSystem {
51  public:
52  virtual ~FileSystem() = default;
53 
54  virtual Status MakeDirectory(const std::string& path) = 0;
55 
56  virtual Status DeleteDirectory(const std::string& path) = 0;
57 
58  virtual Status GetChildren(const std::string& path,
59  std::vector<std::string>* listing) = 0;
60 
61  virtual Status Rename(const std::string& src, const std::string& dst) = 0;
62 
63  virtual Status Stat(const std::string& path, FileStatistics* stat) = 0;
64 };
65 
66 class ARROW_EXPORT FileInterface {
67  public:
68  virtual ~FileInterface() = 0;
69  virtual Status Close() = 0;
70  virtual Status Tell(int64_t* position) const = 0;
71 
72  FileMode::type mode() const { return mode_; }
73 
74  protected:
75  FileInterface() : mode_(FileMode::READ) {}
77  void set_mode(FileMode::type mode) { mode_ = mode; }
78 
79  private:
81 };
82 
83 class ARROW_EXPORT Seekable {
84  public:
85  virtual ~Seekable() = default;
86  virtual Status Seek(int64_t position) = 0;
87 };
88 
89 class ARROW_EXPORT Writeable {
90  public:
91  virtual ~Writeable() = default;
92 
93  virtual Status Write(const uint8_t* data, int64_t nbytes) = 0;
94 
96  virtual Status Flush();
97 
98  Status Write(const std::string& data);
99 };
100 
101 class ARROW_EXPORT Readable {
102  public:
103  virtual ~Readable() = default;
104 
105  virtual Status Read(int64_t nbytes, int64_t* bytes_read, uint8_t* out) = 0;
106 
107  // Does not copy if not necessary
108  virtual Status Read(int64_t nbytes, std::shared_ptr<Buffer>* out) = 0;
109 };
110 
111 class ARROW_EXPORT OutputStream : virtual public FileInterface, public Writeable {
112  protected:
113  OutputStream() = default;
114 };
115 
116 class ARROW_EXPORT InputStream : virtual public FileInterface, public Readable {
117  protected:
118  InputStream() = default;
119 };
120 
121 class ARROW_EXPORT RandomAccessFile : public InputStream, public Seekable {
122  public:
124  ~RandomAccessFile() override;
125 
126  virtual Status GetSize(int64_t* size) = 0;
127 
128  virtual bool supports_zero_copy() const = 0;
129 
140  virtual Status ReadAt(int64_t position, int64_t nbytes, int64_t* bytes_read,
141  uint8_t* out) = 0;
142 
152  virtual Status ReadAt(int64_t position, int64_t nbytes,
153  std::shared_ptr<Buffer>* out) = 0;
154 
155  protected:
157 
158  private:
159  struct ARROW_NO_EXPORT RandomAccessFileImpl;
160  std::unique_ptr<RandomAccessFileImpl> impl_;
161 };
162 
163 class ARROW_EXPORT WriteableFile : public OutputStream, public Seekable {
164  public:
165  virtual Status WriteAt(int64_t position, const uint8_t* data, int64_t nbytes) = 0;
166 
167  protected:
168  WriteableFile() = default;
169 };
170 
171 class ARROW_EXPORT ReadWriteFileInterface : public RandomAccessFile,
172  public WriteableFile {
173  protected:
175 };
176 
178 
179 } // namespace io
180 } // namespace arrow
181 
182 #endif // ARROW_IO_INTERFACES_H
Definition: interfaces.h:40
FileMode::type mode() const
Definition: interfaces.h:72
Definition: interfaces.h:111
Definition: interfaces.h:44
type
Definition: interfaces.h:41
Definition: interfaces.h:163
Definition: interfaces.h:83
Definition: interfaces.h:89
Definition: interfaces.h:116
#define ARROW_NO_EXPORT
Definition: visibility.h:40
Definition: interfaces.h:121
FileInterface()
Definition: interfaces.h:75
FileMode::type mode_
Definition: interfaces.h:76
ObjectType::type kind
Definition: interfaces.h:47
Definition: interfaces.h:66
Definition: interfaces.h:37
Definition: status.h:106
Definition: interfaces.h:36
Definition: interfaces.h:171
Definition: interfaces.h:37
void set_mode(FileMode::type mode)
Definition: interfaces.h:77
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
Definition: interfaces.h:50
ReadWriteFileInterface()
Definition: interfaces.h:174
type
Definition: interfaces.h:37
Definition: interfaces.h:101
int64_t size
Size of file, -1 if finding length is unsupported.
Definition: interfaces.h:46
#define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:23
Definition: interfaces.h:37