mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 09:05:47 +08:00
Draft API for Arrow IO wrappers for Python files
Change-Id: I712800f68cd0c9b0de1cca0d511f3f7d297c05b2
This commit is contained in:
1 parent
391ab64d05
commit
20a3f28744
3 files changed
+153
-2
No files matched your search
@@ -19,9 +19,7 @@
|
||||
#define PYARROW_COMMON_H
|
||||
|
||||
#include "pyarrow/config.h"
|
||||
|
||||
#include "arrow/util/buffer.h"
|
||||
|
||||
#include "pyarrow/visibility.h"
|
||||
|
||||
namespace arrow { class MemoryPool; }
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "pyarrow/common.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
|
||||
#include <arrow/util/memory-pool.h>
|
||||
#include <arrow/util/status.h>
|
||||
#include "pyarrow/status.h"
|
||||
|
||||
namespace pyarrow {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Seekable input stream
|
||||
|
||||
PyReadableFile::PyReadableFile(PyObject* file)
|
||||
: file_(file) {
|
||||
Py_INCREF(file);
|
||||
}
|
||||
|
||||
PyReadableFile::~PyReadableFile() {
|
||||
Py_DECREF();
|
||||
}
|
||||
|
||||
arrow::Status PyReadableFile::ReadAt(
|
||||
int64_t position, int64_t nbytes, int64_t* bytes_read, uint8_t* out) override {
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
arrow::Status PyReadableFile::GetSize(int64_t* size) override {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// Does not copy if not necessary
|
||||
Status PyReadableFile::ReadAt(
|
||||
int64_t position, int64_t nbytes, std::shared_ptr<Buffer>* out) override {
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
bool PyReadableFile::supports_zero_copy() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Output stream
|
||||
|
||||
PyOutputStream::PyOutputStream(PyObject* file)
|
||||
: file_(file) {
|
||||
Py_INCREF(file);
|
||||
}
|
||||
|
||||
PyOutputStream::~PyOutputStream() {
|
||||
Py_DECREF(file_);
|
||||
}
|
||||
|
||||
Status PyOutputStream::Close() override {
|
||||
return arrow::Status::OK();
|
||||
}
|
||||
|
||||
Status PyOutputStream::Tell(int64_t* position) {
|
||||
return arrow::Status::OK();
|
||||
}
|
||||
|
||||
Status PyOutputStream::Write(const uint8_t* data, int64_t nbytes) {
|
||||
return arrow::Status::OK();
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* file_;
|
||||
};
|
||||
|
||||
} // namespace pyarrow
|
||||
@@ -0,0 +1,63 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#ifndef PYARROW_COMMON_H
|
||||
#define PYARROW_COMMON_H
|
||||
|
||||
#include "arrow/io/interfaces.h"
|
||||
|
||||
#include "pyarrow/config.h"
|
||||
#include "pyarrow/visibility.h"
|
||||
|
||||
namespace arrow { class MemoryPool; }
|
||||
|
||||
namespace pyarrow {
|
||||
|
||||
class PYARROW_EXPORT PyReadableFile : public arrow::io::ReadableFileInterface {
|
||||
public:
|
||||
explicit PyReadableFile(PyObject* file);
|
||||
~PyReadableFile();
|
||||
|
||||
arrow::Status ReadAt(
|
||||
int64_t position, int64_t nbytes, int64_t* bytes_read, uint8_t* out) override;
|
||||
|
||||
arrow::Status GetSize(int64_t* size) override;
|
||||
|
||||
// Does not copy if not necessary
|
||||
arrow::Status ReadAt(
|
||||
int64_t position, int64_t nbytes, std::shared_ptr<Buffer>* out) override;
|
||||
|
||||
bool supports_zero_copy() const override;
|
||||
|
||||
private:
|
||||
PyObject* file_;
|
||||
};
|
||||
|
||||
class PYARROW_EXPORT PyOutputStream : public arrow::io::OutputStream {
|
||||
public:
|
||||
explicit PyOutputStream(PyObject* file);
|
||||
~PyOutputStream();
|
||||
|
||||
arrow::Status Close() override;
|
||||
arrow::Status Tell(int64_t* position) override;
|
||||
arrow::Status Write(const uint8_t* data, int64_t nbytes) override;
|
||||
|
||||
private:
|
||||
PyObject* file_;
|
||||
};
|
||||
|
||||
} // namespace pyarrow
|
||||
Reference in new issue
Block a user