Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
io.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 PYARROW_IO_H
19 #define PYARROW_IO_H
20 
21 #include "arrow/io/interfaces.h"
22 #include "arrow/io/memory.h"
23 #include "arrow/util/visibility.h"
24 
25 #include "arrow/python/config.h"
26 
27 #include "arrow/python/common.h"
28 
29 namespace arrow {
30 
31 class MemoryPool;
32 
33 namespace py {
34 
36 
37 class ARROW_EXPORT PyReadableFile : public io::RandomAccessFile {
38  public:
39  explicit PyReadableFile(PyObject* file);
40  virtual ~PyReadableFile();
41 
42  Status Close() override;
43 
44  Status Read(int64_t nbytes, int64_t* bytes_read, uint8_t* out) override;
45  Status Read(int64_t nbytes, std::shared_ptr<Buffer>* out) override;
46 
47  // Thread-safe version
48  Status ReadAt(int64_t position, int64_t nbytes, int64_t* bytes_read,
49  uint8_t* out) override;
50 
51  // Thread-safe version
52  Status ReadAt(int64_t position, int64_t nbytes, std::shared_ptr<Buffer>* out) override;
53 
54  Status GetSize(int64_t* size) override;
55 
56  Status Seek(int64_t position) override;
57 
58  Status Tell(int64_t* position) const override;
59 
60  bool supports_zero_copy() const override;
61 
62  private:
63  std::unique_ptr<PythonFile> file_;
64 };
65 
66 class ARROW_EXPORT PyOutputStream : public io::OutputStream {
67  public:
68  explicit PyOutputStream(PyObject* file);
69  virtual ~PyOutputStream();
70 
71  Status Close() override;
72  Status Tell(int64_t* position) const override;
73  Status Write(const uint8_t* data, int64_t nbytes) override;
74 
75  private:
76  std::unique_ptr<PythonFile> file_;
77  int64_t position_;
78 };
79 
80 // A zero-copy reader backed by a PyBuffer object
81 class ARROW_EXPORT PyBytesReader : public io::BufferReader {
82  public:
83  explicit PyBytesReader(PyObject* obj);
84  virtual ~PyBytesReader();
85 };
86 
87 // TODO(wesm): seekable output files
88 
89 } // namespace py
90 } // namespace arrow
91 
92 #endif // PYARROW_IO_H
Definition: interfaces.h:111
class ARROW_NO_EXPORT PythonFile
Definition: io.h:35
#define ARROW_NO_EXPORT
Definition: visibility.h:40
Definition: interfaces.h:121
Random access zero-copy reads on an arrow::Buffer.
Definition: memory.h:107
Definition: io.h:37
Definition: status.h:106
Definition: io.h:81
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
Definition: io.h:66