You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/05/02 17:49:44 UTC
arrow git commit: ARROW-931: [GLib] Reconstruct input stream
Repository: arrow
Updated Branches:
refs/heads/master 02a121f18 -> f1bd49d5b
ARROW-931: [GLib] Reconstruct input stream
* GArrowRandomAccessFile -> GArrowSeekableInputStream
* GArrowBufferReader -> GArrowBufferInputStream
* GArrowMemoryMappedFile -> GArrowMemoryMappedInputStream
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #628 from kou/glib-reconstruct-input-stream and squashes the following commits:
3488cad [Kouhei Sutou] [GLib] Reconstruct input stream
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/f1bd49d5
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/f1bd49d5
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/f1bd49d5
Branch: refs/heads/master
Commit: f1bd49d5bb32636f5a8bbe8d26b4269b678dec55
Parents: 02a121f
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Tue May 2 13:49:37 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Tue May 2 13:49:37 2017 -0400
----------------------------------------------------------------------
c_glib/arrow-glib/Makefile.am | 6 -
c_glib/arrow-glib/arrow-glib.h | 2 -
c_glib/arrow-glib/file-reader.cpp | 12 +-
c_glib/arrow-glib/file-reader.h | 6 +-
c_glib/arrow-glib/input-stream.cpp | 211 ++++++++++++---
c_glib/arrow-glib/input-stream.h | 163 +++++++++---
c_glib/arrow-glib/input-stream.hpp | 8 +-
c_glib/arrow-glib/memory-mapped-file.cpp | 270 --------------------
c_glib/arrow-glib/memory-mapped-file.h | 72 ------
c_glib/arrow-glib/memory-mapped-file.hpp | 28 --
c_glib/arrow-glib/random-access-file.cpp | 124 ---------
c_glib/arrow-glib/random-access-file.h | 53 ----
c_glib/arrow-glib/random-access-file.hpp | 38 ---
c_glib/doc/reference/arrow-glib-docs.sgml | 2 -
c_glib/example/lua/read-batch.lua | 2 +-
c_glib/example/lua/read-stream.lua | 2 +-
c_glib/example/read-batch.c | 9 +-
c_glib/example/read-stream.c | 6 +-
c_glib/test/test-buffer-input-stream.rb | 25 ++
c_glib/test/test-buffer-reader.rb | 25 --
c_glib/test/test-file-writer.rb | 2 +-
c_glib/test/test-memory-mapped-file.rb | 134 ----------
c_glib/test/test-memory-mapped-input-stream.rb | 82 ++++++
c_glib/test/test-stream-writer.rb | 2 +-
24 files changed, 442 insertions(+), 842 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/Makefile.am
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/Makefile.am b/c_glib/arrow-glib/Makefile.am
index 54fb7f8..2425072 100644
--- a/c_glib/arrow-glib/Makefile.am
+++ b/c_glib/arrow-glib/Makefile.am
@@ -60,9 +60,7 @@ libarrow_glib_la_headers += \
file.h \
file-mode.h \
input-stream.h \
- memory-mapped-file.h \
output-stream.h \
- random-access-file.h \
readable.h \
writeable.h \
writeable-file.h
@@ -102,9 +100,7 @@ libarrow_glib_la_sources += \
file.cpp \
file-mode.cpp \
input-stream.cpp \
- memory-mapped-file.cpp \
output-stream.cpp \
- random-access-file.cpp \
readable.cpp \
writeable.cpp \
writeable-file.cpp
@@ -136,9 +132,7 @@ libarrow_glib_la_cpp_headers += \
file.hpp \
file-mode.hpp \
input-stream.hpp \
- memory-mapped-file.hpp \
output-stream.hpp \
- random-access-file.hpp \
readable.hpp \
writeable.hpp \
writeable-file.hpp
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/arrow-glib.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/arrow-glib.h b/c_glib/arrow-glib/arrow-glib.h
index e88b66b..0a06cb8 100644
--- a/c_glib/arrow-glib/arrow-glib.h
+++ b/c_glib/arrow-glib/arrow-glib.h
@@ -36,9 +36,7 @@
#include <arrow-glib/file.h>
#include <arrow-glib/file-mode.h>
#include <arrow-glib/input-stream.h>
-#include <arrow-glib/memory-mapped-file.h>
#include <arrow-glib/output-stream.h>
-#include <arrow-glib/random-access-file.h>
#include <arrow-glib/readable.h>
#include <arrow-glib/writeable.h>
#include <arrow-glib/writeable-file.h>
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/file-reader.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/file-reader.cpp b/c_glib/arrow-glib/file-reader.cpp
index b952b52..bbba5a1 100644
--- a/c_glib/arrow-glib/file-reader.cpp
+++ b/c_glib/arrow-glib/file-reader.cpp
@@ -27,7 +27,7 @@
#include <arrow-glib/record-batch.hpp>
#include <arrow-glib/schema.hpp>
-#include <arrow-glib/random-access-file.hpp>
+#include <arrow-glib/input-stream.hpp>
#include <arrow-glib/file-reader.hpp>
#include <arrow-glib/metadata-version.hpp>
@@ -132,19 +132,21 @@ garrow_file_reader_class_init(GArrowFileReaderClass *klass)
/**
* garrow_file_reader_open:
- * @file: The file to be read.
+ * @input_stream: The seekable input stream to read data.
* @error: (nullable): Return locatipcn for a #GError or %NULL.
*
* Returns: (nullable) (transfer full): A newly opened
* #GArrowFileReader or %NULL on error.
*/
GArrowFileReader *
-garrow_file_reader_open(GArrowRandomAccessFile *file,
- GError **error)
+garrow_file_reader_open(GArrowSeekableInputStream *input_stream,
+ GError **error)
{
+ auto arrow_random_access_file =
+ garrow_seekable_input_stream_get_raw(input_stream);
std::shared_ptr<arrow::ipc::FileReader> arrow_file_reader;
auto status =
- arrow::ipc::FileReader::Open(garrow_random_access_file_get_raw(file),
+ arrow::ipc::FileReader::Open(arrow_random_access_file,
&arrow_file_reader);
if (garrow_error_check(error, status, "[ipc][file-reader][open]")) {
return garrow_file_reader_new_raw(&arrow_file_reader);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/file-reader.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/file-reader.h b/c_glib/arrow-glib/file-reader.h
index 084f714..b737269 100644
--- a/c_glib/arrow-glib/file-reader.h
+++ b/c_glib/arrow-glib/file-reader.h
@@ -22,7 +22,7 @@
#include <arrow-glib/record-batch.h>
#include <arrow-glib/schema.h>
-#include <arrow-glib/random-access-file.h>
+#include <arrow-glib/input-stream.h>
#include <arrow-glib/metadata-version.h>
@@ -70,8 +70,8 @@ struct _GArrowFileReaderClass
GType garrow_file_reader_get_type(void) G_GNUC_CONST;
-GArrowFileReader *garrow_file_reader_open(GArrowRandomAccessFile *file,
- GError **error);
+GArrowFileReader *garrow_file_reader_open(GArrowSeekableInputStream *input_stream,
+ GError **error);
GArrowSchema *garrow_file_reader_get_schema(GArrowFileReader *file_reader);
guint garrow_file_reader_get_n_record_batches(GArrowFileReader *file_reader);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/input-stream.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/input-stream.cpp b/c_glib/arrow-glib/input-stream.cpp
index 56b811a..b931cf8 100644
--- a/c_glib/arrow-glib/input-stream.cpp
+++ b/c_glib/arrow-glib/input-stream.cpp
@@ -28,7 +28,6 @@
#include <arrow-glib/error.hpp>
#include <arrow-glib/file.hpp>
#include <arrow-glib/input-stream.hpp>
-#include <arrow-glib/random-access-file.hpp>
#include <arrow-glib/readable.hpp>
G_BEGIN_DECLS
@@ -41,7 +40,13 @@ G_BEGIN_DECLS
*
* #GArrowInputStream is a base class for input stream.
*
- * #GArrowBufferReader is a class for buffer input stream.
+ * #GArrowSeekableInputStream is a base class for input stream that
+ * supports random access.
+ *
+ * #GArrowBufferInputStream is a class to read data on buffer.
+ *
+ * #GArrowMemoryMappedFile is a class to read data in file by mapping
+ * the file on memory. It supports zero copy.
*/
typedef struct GArrowInputStreamPrivate_ {
@@ -168,71 +173,174 @@ garrow_input_stream_class_init(GArrowInputStreamClass *klass)
}
-static std::shared_ptr<arrow::io::RandomAccessFile>
-garrow_buffer_reader_get_raw_random_access_file_interface(GArrowRandomAccessFile *random_access_file)
+G_DEFINE_TYPE(GArrowSeekableInputStream, \
+ garrow_seekable_input_stream, \
+ GARROW_TYPE_INPUT_STREAM);
+
+static void
+garrow_seekable_input_stream_init(GArrowSeekableInputStream *object)
{
- auto input_stream = GARROW_INPUT_STREAM(random_access_file);
- auto arrow_input_stream = garrow_input_stream_get_raw(input_stream);
- auto arrow_buffer_reader =
- std::static_pointer_cast<arrow::io::BufferReader>(arrow_input_stream);
- return arrow_buffer_reader;
}
static void
-garrow_buffer_reader_random_access_file_interface_init(GArrowRandomAccessFileInterface *iface)
+garrow_seekable_input_stream_class_init(GArrowSeekableInputStreamClass *klass)
+{
+}
+
+/**
+ * garrow_seekable_input_stream_get_size:
+ * @input_stream: A #GArrowSeekableInputStream.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The size of the file.
+ */
+guint64
+garrow_seekable_input_stream_get_size(GArrowSeekableInputStream *input_stream,
+ GError **error)
+{
+ auto arrow_random_access_file =
+ garrow_seekable_input_stream_get_raw(input_stream);
+ int64_t size;
+ auto status = arrow_random_access_file->GetSize(&size);
+ if (garrow_error_check(error, status, "[seekable-input-stream][get-size]")) {
+ return size;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * garrow_seekable_input_stream_get_support_zero_copy:
+ * @input_stream: A #GArrowSeekableInputStream.
+ *
+ * Returns: Whether zero copy read is supported or not.
+ */
+gboolean
+garrow_seekable_input_stream_get_support_zero_copy(GArrowSeekableInputStream *input_stream)
+{
+ auto arrow_random_access_file =
+ garrow_seekable_input_stream_get_raw(input_stream);
+ return arrow_random_access_file->supports_zero_copy();
+}
+
+/**
+ * garrow_seekable_input_stream_read_at:
+ * @input_stream: A #GArrowSeekableInputStream.
+ * @position: The read start position.
+ * @n_bytes: The number of bytes to be read.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full) (nullable): #GArrowBuffer that has read
+ * data on success, %NULL if there was an error.
+ */
+GArrowBuffer *
+garrow_seekable_input_stream_read_at(GArrowSeekableInputStream *input_stream,
+ gint64 position,
+ gint64 n_bytes,
+ GError **error)
{
- iface->get_raw = garrow_buffer_reader_get_raw_random_access_file_interface;
+ auto arrow_random_access_file =
+ garrow_seekable_input_stream_get_raw(input_stream);
+
+ std::shared_ptr<arrow::Buffer> arrow_buffer;
+ auto status = arrow_random_access_file->ReadAt(position,
+ n_bytes,
+ &arrow_buffer);
+ if (garrow_error_check(error, status, "[seekable-input-stream][read-at]")) {
+ return garrow_buffer_new_raw(&arrow_buffer);
+ } else {
+ return NULL;
+ }
}
-G_DEFINE_TYPE_WITH_CODE(GArrowBufferReader, \
- garrow_buffer_reader, \
- GARROW_TYPE_INPUT_STREAM,
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_RANDOM_ACCESS_FILE,
- garrow_buffer_reader_random_access_file_interface_init));
+
+G_DEFINE_TYPE(GArrowBufferInputStream, \
+ garrow_buffer_input_stream, \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM);
static void
-garrow_buffer_reader_init(GArrowBufferReader *object)
+garrow_buffer_input_stream_init(GArrowBufferInputStream *object)
{
}
static void
-garrow_buffer_reader_class_init(GArrowBufferReaderClass *klass)
+garrow_buffer_input_stream_class_init(GArrowBufferInputStreamClass *klass)
{
}
/**
- * garrow_buffer_reader_new:
+ * garrow_buffer_input_stream_new:
* @buffer: The buffer to be read.
*
- * Returns: A newly created #GArrowBufferReader.
+ * Returns: A newly created #GArrowBufferInputStream.
*/
-GArrowBufferReader *
-garrow_buffer_reader_new(GArrowBuffer *buffer)
+GArrowBufferInputStream *
+garrow_buffer_input_stream_new(GArrowBuffer *buffer)
{
auto arrow_buffer = garrow_buffer_get_raw(buffer);
auto arrow_buffer_reader =
std::make_shared<arrow::io::BufferReader>(arrow_buffer);
- return garrow_buffer_reader_new_raw(&arrow_buffer_reader);
+ return garrow_buffer_input_stream_new_raw(&arrow_buffer_reader);
}
/**
- * garrow_buffer_reader_get_buffer:
- * @buffer_reader: A #GArrowBufferReader.
+ * garrow_buffer_input_stream_get_buffer:
+ * @input_stream: A #GArrowBufferInputStream.
*
* Returns: (transfer full): The data of the array as #GArrowBuffer.
*/
GArrowBuffer *
-garrow_buffer_reader_get_buffer(GArrowBufferReader *buffer_reader)
+garrow_buffer_input_stream_get_buffer(GArrowBufferInputStream *input_stream)
{
- auto arrow_input_stream =
- garrow_input_stream_get_raw(GARROW_INPUT_STREAM(buffer_reader));
- auto arrow_buffer_reader =
- std::static_pointer_cast<arrow::io::BufferReader>(arrow_input_stream);
+ auto arrow_buffer_reader = garrow_buffer_input_stream_get_raw(input_stream);
auto arrow_buffer = arrow_buffer_reader->buffer();
return garrow_buffer_new_raw(&arrow_buffer);
}
+G_DEFINE_TYPE(GArrowMemoryMappedInputStream, \
+ garrow_memory_mapped_input_stream, \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM);
+
+static void
+garrow_memory_mapped_input_stream_init(GArrowMemoryMappedInputStream *object)
+{
+}
+
+static void
+garrow_memory_mapped_input_stream_class_init(GArrowMemoryMappedInputStreamClass *klass)
+{
+}
+
+/**
+ * garrow_memory_mapped_input_stream_new:
+ * @path: The path of the file to be mapped on memory.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable): A newly created #GArrowMemoryMappedInputStream
+ * or %NULL on error.
+ */
+GArrowMemoryMappedInputStream *
+garrow_memory_mapped_input_stream_new(const gchar *path,
+ GError **error)
+{
+ std::shared_ptr<arrow::io::MemoryMappedFile> arrow_memory_mapped_file;
+ auto status =
+ arrow::io::MemoryMappedFile::Open(std::string(path),
+ arrow::io::FileMode::READ,
+ &arrow_memory_mapped_file);
+ if (status.ok()) {
+ return garrow_memory_mapped_input_stream_new_raw(&arrow_memory_mapped_file);
+ } else {
+ std::string context("[memory-mapped-input-stream][open]: <");
+ context += path;
+ context += ">";
+ garrow_error_check(error, status, context.c_str());
+ return NULL;
+ }
+}
+
+
G_END_DECLS
GArrowInputStream *
@@ -254,13 +362,42 @@ garrow_input_stream_get_raw(GArrowInputStream *input_stream)
return priv->input_stream;
}
+std::shared_ptr<arrow::io::RandomAccessFile>
+garrow_seekable_input_stream_get_raw(GArrowSeekableInputStream *seekable_input_stream)
+{
+ auto arrow_input_stream =
+ garrow_input_stream_get_raw(GARROW_INPUT_STREAM(seekable_input_stream));
+ auto arrow_random_access_file =
+ std::static_pointer_cast<arrow::io::RandomAccessFile>(arrow_input_stream);
+ return arrow_random_access_file;
+}
+
+GArrowBufferInputStream *
+garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader)
+{
+ auto buffer_input_stream =
+ GARROW_BUFFER_INPUT_STREAM(g_object_new(GARROW_TYPE_BUFFER_INPUT_STREAM,
+ "input-stream", arrow_buffer_reader,
+ NULL));
+ return buffer_input_stream;
+}
+
+std::shared_ptr<arrow::io::BufferReader>
+garrow_buffer_input_stream_get_raw(GArrowBufferInputStream *buffer_input_stream)
+{
+ auto arrow_input_stream =
+ garrow_input_stream_get_raw(GARROW_INPUT_STREAM(buffer_input_stream));
+ auto arrow_buffer_reader =
+ std::static_pointer_cast<arrow::io::BufferReader>(arrow_input_stream);
+ return arrow_buffer_reader;
+}
-GArrowBufferReader *
-garrow_buffer_reader_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader)
+GArrowMemoryMappedInputStream *
+garrow_memory_mapped_input_stream_new_raw(std::shared_ptr<arrow::io::MemoryMappedFile> *arrow_memory_mapped_file)
{
- auto buffer_reader =
- GARROW_BUFFER_READER(g_object_new(GARROW_TYPE_BUFFER_READER,
- "input-stream", arrow_buffer_reader,
- NULL));
- return buffer_reader;
+ auto object = g_object_new(GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM,
+ "input-stream", arrow_memory_mapped_file,
+ NULL);
+ auto memory_mapped_input_stream = GARROW_MEMORY_MAPPED_INPUT_STREAM(object);
+ return memory_mapped_input_stream;
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/input-stream.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/input-stream.h b/c_glib/arrow-glib/input-stream.h
index caa11b5..5118828 100644
--- a/c_glib/arrow-glib/input-stream.h
+++ b/c_glib/arrow-glib/input-stream.h
@@ -70,54 +70,159 @@ struct _GArrowInputStreamClass
GType garrow_input_stream_get_type(void) G_GNUC_CONST;
-#define GARROW_TYPE_BUFFER_READER \
- (garrow_buffer_reader_get_type())
-#define GARROW_BUFFER_READER(obj) \
+#define GARROW_TYPE_SEEKABLE_INPUT_STREAM \
+ (garrow_seekable_input_stream_get_type())
+#define GARROW_SEEKABLE_INPUT_STREAM(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM, \
+ GArrowSeekableInputStream))
+#define GARROW_SEEKABLE_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM, \
+ GArrowSeekableInputStreamClass))
+#define GARROW_IS_SEEKABLE_INPUT_STREAM(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM))
+#define GARROW_IS_SEEKABLE_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM))
+#define GARROW_SEEKABLE_INPUT_STREAM_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM, \
+ GArrowSeekableInputStreamClass))
+
+typedef struct _GArrowSeekableInputStream GArrowSeekableInputStream;
+#ifndef __GTK_DOC_IGNORE__
+typedef struct _GArrowSeekableInputStreamClass GArrowSeekableInputStreamClass;
+#endif
+
+/**
+ * GArrowSeekableInputStream:
+ *
+ * It wraps `arrow::io::RandomAccessFile`.
+ */
+struct _GArrowSeekableInputStream
+{
+ /*< private >*/
+ GArrowInputStream parent_instance;
+};
+
+#ifndef __GTK_DOC_IGNORE__
+struct _GArrowSeekableInputStreamClass
+{
+ GArrowInputStreamClass parent_class;
+};
+#endif
+
+GType garrow_seekable_input_stream_get_type(void) G_GNUC_CONST;
+
+guint64 garrow_seekable_input_stream_get_size(GArrowSeekableInputStream *input_stream,
+ GError **error);
+gboolean garrow_seekable_input_stream_get_support_zero_copy(GArrowSeekableInputStream *input_stream);
+GArrowBuffer *garrow_seekable_input_stream_read_at(GArrowSeekableInputStream *input_stream,
+ gint64 position,
+ gint64 n_bytes,
+ GError **error);
+
+
+#define GARROW_TYPE_BUFFER_INPUT_STREAM \
+ (garrow_buffer_input_stream_get_type())
+#define GARROW_BUFFER_INPUT_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
- GARROW_TYPE_BUFFER_READER, \
- GArrowBufferReader))
-#define GARROW_BUFFER_READER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), \
- GARROW_TYPE_BUFFER_READER, \
- GArrowBufferReaderClass))
-#define GARROW_IS_BUFFER_READER(obj) \
+ GARROW_TYPE_BUFFER_INPUT_STREAM, \
+ GArrowBufferInputStream))
+#define GARROW_BUFFER_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_BUFFER_INPUT_STREAM, \
+ GArrowBufferInputStreamClass))
+#define GARROW_IS_BUFFER_INPUT_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
- GARROW_TYPE_BUFFER_READER))
-#define GARROW_IS_BUFFER_READER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE((klass), \
- GARROW_TYPE_BUFFER_READER))
-#define GARROW_BUFFER_READER_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS((obj), \
- GARROW_TYPE_BUFFER_READER, \
- GArrowBufferReaderClass))
-
-typedef struct _GArrowBufferReader GArrowBufferReader;
+ GARROW_TYPE_BUFFER_INPUT_STREAM))
+#define GARROW_IS_BUFFER_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_BUFFER_INPUT_STREAM))
+#define GARROW_BUFFER_INPUT_STREAM_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_BUFFER_INPUT_STREAM, \
+ GArrowBufferInputStreamClass))
+
+typedef struct _GArrowBufferInputStream GArrowBufferInputStream;
#ifndef __GTK_DOC_IGNORE__
-typedef struct _GArrowBufferReaderClass GArrowBufferReaderClass;
+typedef struct _GArrowBufferInputStreamClass GArrowBufferInputStreamClass;
#endif
/**
- * GArrowBufferReader:
+ * GArrowBufferInputStream:
*
* It wraps `arrow::io::BufferReader`.
*/
-struct _GArrowBufferReader
+struct _GArrowBufferInputStream
{
/*< private >*/
- GArrowInputStream parent_instance;
+ GArrowSeekableInputStream parent_instance;
};
#ifndef __GTK_DOC_IGNORE__
-struct _GArrowBufferReaderClass
+struct _GArrowBufferInputStreamClass
{
- GArrowInputStreamClass parent_class;
+ GArrowSeekableInputStreamClass parent_class;
};
#endif
-GType garrow_buffer_reader_get_type(void) G_GNUC_CONST;
+GType garrow_buffer_input_stream_get_type(void) G_GNUC_CONST;
+
+GArrowBufferInputStream *garrow_buffer_input_stream_new(GArrowBuffer *buffer);
+
+GArrowBuffer *garrow_buffer_input_stream_get_buffer(GArrowBufferInputStream *input_stream);
+
+
+#define GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM \
+ (garrow_memory_mapped_input_stream_get_type())
+#define GARROW_MEMORY_MAPPED_INPUT_STREAM(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM, \
+ GArrowMemoryMappedInputStream))
+#define GARROW_MEMORY_MAPPED_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM, \
+ GArrowMemoryMappedInputStreamClass))
+#define GARROW_IS_MEMORY_MAPPED_INPUT_STREAM(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM))
+#define GARROW_IS_MEMORY_MAPPED_INPUT_STREAM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM))
+#define GARROW_MEMORY_MAPPED_INPUT_STREAM_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_MEMORY_MAPPED_INPUT_STREAM, \
+ GArrowMemoryMappedInputStreamClass))
+
+typedef struct _GArrowMemoryMappedInputStream GArrowMemoryMappedInputStream;
+#ifndef __GTK_DOC_IGNORE__
+typedef struct _GArrowMemoryMappedInputStreamClass GArrowMemoryMappedInputStreamClass;
+#endif
+
+/**
+ * GArrowMemoryMappedInputStream:
+ *
+ * It wraps `arrow::io::MemoryMappedFile`.
+ */
+struct _GArrowMemoryMappedInputStream
+{
+ /*< private >*/
+ GArrowSeekableInputStream parent_instance;
+};
+
+#ifndef __GTK_DOC_IGNORE__
+struct _GArrowMemoryMappedInputStreamClass
+{
+ GArrowSeekableInputStreamClass parent_class;
+};
+#endif
-GArrowBufferReader *garrow_buffer_reader_new(GArrowBuffer *buffer);
+GType garrow_memory_mapped_input_stream_get_type(void) G_GNUC_CONST;
-GArrowBuffer *garrow_buffer_reader_get_buffer(GArrowBufferReader *buffer_reader);
+GArrowMemoryMappedInputStream *garrow_memory_mapped_input_stream_new(const gchar *path,
+ GError **error);
G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/input-stream.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/input-stream.hpp b/c_glib/arrow-glib/input-stream.hpp
index 008f5f2..17d2bd9 100644
--- a/c_glib/arrow-glib/input-stream.hpp
+++ b/c_glib/arrow-glib/input-stream.hpp
@@ -19,6 +19,7 @@
#pragma once
+#include <arrow/io/file.h>
#include <arrow/io/interfaces.h>
#include <arrow/io/memory.h>
@@ -27,4 +28,9 @@
GArrowInputStream *garrow_input_stream_new_raw(std::shared_ptr<arrow::io::InputStream> *arrow_input_stream);
std::shared_ptr<arrow::io::InputStream> garrow_input_stream_get_raw(GArrowInputStream *input_stream);
-GArrowBufferReader *garrow_buffer_reader_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader);
+std::shared_ptr<arrow::io::RandomAccessFile> garrow_seekable_input_stream_get_raw(GArrowSeekableInputStream *input_stream);
+
+GArrowBufferInputStream *garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader);
+std::shared_ptr<arrow::io::BufferReader> garrow_buffer_input_stream_get_raw(GArrowBufferInputStream *input_stream);
+
+GArrowMemoryMappedInputStream *garrow_memory_mapped_input_stream_new_raw(std::shared_ptr<arrow::io::MemoryMappedFile> *arrow_memory_mapped_file);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/memory-mapped-file.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/memory-mapped-file.cpp b/c_glib/arrow-glib/memory-mapped-file.cpp
deleted file mode 100644
index 71a9a6d..0000000
--- a/c_glib/arrow-glib/memory-mapped-file.cpp
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * 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.
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <arrow/io/file.h>
-
-#include <arrow-glib/error.hpp>
-#include <arrow-glib/file.hpp>
-#include <arrow-glib/file-mode.hpp>
-#include <arrow-glib/input-stream.hpp>
-#include <arrow-glib/memory-mapped-file.hpp>
-#include <arrow-glib/readable.hpp>
-#include <arrow-glib/random-access-file.hpp>
-#include <arrow-glib/writeable.hpp>
-#include <arrow-glib/writeable-file.hpp>
-
-G_BEGIN_DECLS
-
-/**
- * SECTION: memory-mapped-file
- * @short_description: Memory mapped file class
- *
- * #GArrowMemoryMappedFile is a class for memory mapped file. It's
- * readable and writeable. It supports zero copy.
- */
-
-typedef struct GArrowMemoryMappedFilePrivate_ {
- std::shared_ptr<arrow::io::MemoryMappedFile> memory_mapped_file;
-} GArrowMemoryMappedFilePrivate;
-
-enum {
- PROP_0,
- PROP_MEMORY_MAPPED_FILE
-};
-
-static std::shared_ptr<arrow::io::FileInterface>
-garrow_memory_mapped_file_get_raw_file_interface(GArrowFile *file)
-{
- auto memory_mapped_file = GARROW_MEMORY_MAPPED_FILE(file);
- auto arrow_memory_mapped_file =
- garrow_memory_mapped_file_get_raw(memory_mapped_file);
- return arrow_memory_mapped_file;
-}
-
-static void
-garrow_file_interface_init(GArrowFileInterface *iface)
-{
- iface->get_raw = garrow_memory_mapped_file_get_raw_file_interface;
-}
-
-static std::shared_ptr<arrow::io::Readable>
-garrow_memory_mapped_file_get_raw_readable_interface(GArrowReadable *readable)
-{
- auto memory_mapped_file = GARROW_MEMORY_MAPPED_FILE(readable);
- auto arrow_memory_mapped_file =
- garrow_memory_mapped_file_get_raw(memory_mapped_file);
- return arrow_memory_mapped_file;
-}
-
-static void
-garrow_readable_interface_init(GArrowReadableInterface *iface)
-{
- iface->get_raw = garrow_memory_mapped_file_get_raw_readable_interface;
-}
-
-static std::shared_ptr<arrow::io::RandomAccessFile>
-garrow_memory_mapped_file_get_raw_random_access_file_interface(GArrowRandomAccessFile *file)
-{
- auto memory_mapped_file = GARROW_MEMORY_MAPPED_FILE(file);
- auto arrow_memory_mapped_file =
- garrow_memory_mapped_file_get_raw(memory_mapped_file);
- return arrow_memory_mapped_file;
-}
-
-static void
-garrow_random_access_file_interface_init(GArrowRandomAccessFileInterface *iface)
-{
- iface->get_raw = garrow_memory_mapped_file_get_raw_random_access_file_interface;
-}
-
-static std::shared_ptr<arrow::io::Writeable>
-garrow_memory_mapped_file_get_raw_writeable_interface(GArrowWriteable *writeable)
-{
- auto memory_mapped_file = GARROW_MEMORY_MAPPED_FILE(writeable);
- auto arrow_memory_mapped_file =
- garrow_memory_mapped_file_get_raw(memory_mapped_file);
- return arrow_memory_mapped_file;
-}
-
-static void
-garrow_writeable_interface_init(GArrowWriteableInterface *iface)
-{
- iface->get_raw = garrow_memory_mapped_file_get_raw_writeable_interface;
-}
-
-static std::shared_ptr<arrow::io::WriteableFile>
-garrow_memory_mapped_file_get_raw_writeable_file_interface(GArrowWriteableFile *file)
-{
- auto memory_mapped_file = GARROW_MEMORY_MAPPED_FILE(file);
- auto arrow_memory_mapped_file =
- garrow_memory_mapped_file_get_raw(memory_mapped_file);
- return arrow_memory_mapped_file;
-}
-
-static void
-garrow_writeable_file_interface_init(GArrowWriteableFileInterface *iface)
-{
- iface->get_raw = garrow_memory_mapped_file_get_raw_writeable_file_interface;
-}
-
-G_DEFINE_TYPE_WITH_CODE(GArrowMemoryMappedFile,
- garrow_memory_mapped_file,
- G_TYPE_OBJECT,
- G_ADD_PRIVATE(GArrowMemoryMappedFile)
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_FILE,
- garrow_file_interface_init)
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_READABLE,
- garrow_readable_interface_init)
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_RANDOM_ACCESS_FILE,
- garrow_random_access_file_interface_init)
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_WRITEABLE,
- garrow_writeable_interface_init)
- G_IMPLEMENT_INTERFACE(GARROW_TYPE_WRITEABLE_FILE,
- garrow_writeable_file_interface_init));
-
-#define GARROW_MEMORY_MAPPED_FILE_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
- GARROW_TYPE_MEMORY_MAPPED_FILE, \
- GArrowMemoryMappedFilePrivate))
-
-static void
-garrow_memory_mapped_file_finalize(GObject *object)
-{
- GArrowMemoryMappedFilePrivate *priv;
-
- priv = GARROW_MEMORY_MAPPED_FILE_GET_PRIVATE(object);
-
- priv->memory_mapped_file = nullptr;
-
- G_OBJECT_CLASS(garrow_memory_mapped_file_parent_class)->finalize(object);
-}
-
-static void
-garrow_memory_mapped_file_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GArrowMemoryMappedFilePrivate *priv;
-
- priv = GARROW_MEMORY_MAPPED_FILE_GET_PRIVATE(object);
-
- switch (prop_id) {
- case PROP_MEMORY_MAPPED_FILE:
- priv->memory_mapped_file =
- *static_cast<std::shared_ptr<arrow::io::MemoryMappedFile> *>(g_value_get_pointer(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-garrow_memory_mapped_file_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-garrow_memory_mapped_file_init(GArrowMemoryMappedFile *object)
-{
-}
-
-static void
-garrow_memory_mapped_file_class_init(GArrowMemoryMappedFileClass *klass)
-{
- GObjectClass *gobject_class;
- GParamSpec *spec;
-
- gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->finalize = garrow_memory_mapped_file_finalize;
- gobject_class->set_property = garrow_memory_mapped_file_set_property;
- gobject_class->get_property = garrow_memory_mapped_file_get_property;
-
- spec = g_param_spec_pointer("memory-mapped-file",
- "io::MemoryMappedFile",
- "The raw std::shared<arrow::io::MemoryMappedFile> *",
- static_cast<GParamFlags>(G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property(gobject_class, PROP_MEMORY_MAPPED_FILE, spec);
-}
-
-/**
- * garrow_memory_mapped_file_open:
- * @path: The path of the memory mapped file.
- * @mode: The mode of the memory mapped file.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: (nullable) (transfer full): A newly opened
- * #GArrowMemoryMappedFile or %NULL on error.
- */
-GArrowMemoryMappedFile *
-garrow_memory_mapped_file_open(const gchar *path,
- GArrowFileMode mode,
- GError **error)
-{
- std::shared_ptr<arrow::io::MemoryMappedFile> arrow_memory_mapped_file;
- auto status =
- arrow::io::MemoryMappedFile::Open(std::string(path),
- garrow_file_mode_to_raw(mode),
- &arrow_memory_mapped_file);
- if (status.ok()) {
- return garrow_memory_mapped_file_new_raw(&arrow_memory_mapped_file);
- } else {
- std::string context("[io][memory-mapped-file][open]: <");
- context += path;
- context += ">";
- garrow_error_check(error, status, context.c_str());
- return NULL;
- }
-}
-
-G_END_DECLS
-
-GArrowMemoryMappedFile *
-garrow_memory_mapped_file_new_raw(std::shared_ptr<arrow::io::MemoryMappedFile> *arrow_memory_mapped_file)
-{
- auto memory_mapped_file =
- GARROW_MEMORY_MAPPED_FILE(g_object_new(GARROW_TYPE_MEMORY_MAPPED_FILE,
- "memory-mapped-file", arrow_memory_mapped_file,
- NULL));
- return memory_mapped_file;
-}
-
-std::shared_ptr<arrow::io::MemoryMappedFile>
-garrow_memory_mapped_file_get_raw(GArrowMemoryMappedFile *memory_mapped_file)
-{
- GArrowMemoryMappedFilePrivate *priv;
-
- priv = GARROW_MEMORY_MAPPED_FILE_GET_PRIVATE(memory_mapped_file);
- return priv->memory_mapped_file;
-}
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/memory-mapped-file.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/memory-mapped-file.h b/c_glib/arrow-glib/memory-mapped-file.h
deleted file mode 100644
index 40b8de0..0000000
--- a/c_glib/arrow-glib/memory-mapped-file.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.
- */
-
-#pragma once
-
-#include <arrow-glib/file-mode.h>
-
-G_BEGIN_DECLS
-
-#define GARROW_TYPE_MEMORY_MAPPED_FILE \
- (garrow_memory_mapped_file_get_type())
-#define GARROW_MEMORY_MAPPED_FILE(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj), \
- GARROW_TYPE_MEMORY_MAPPED_FILE, \
- GArrowMemoryMappedFile))
-#define GARROW_MEMORY_MAPPED_FILE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), \
- GARROW_TYPE_MEMORY_MAPPED_FILE, \
- GArrowMemoryMappedFileClass))
-#define GARROW_IS_MEMORY_MAPPED_FILE(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
- GARROW_TYPE_MEMORY_MAPPED_FILE))
-#define GARROW_IS_MEMORY_MAPPED_FILE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE((klass), \
- GARROW_TYPE_MEMORY_MAPPED_FILE))
-#define GARROW_MEMORY_MAPPED_FILE_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS((obj), \
- GARROW_TYPE_MEMORY_MAPPED_FILE, \
- GArrowMemoryMappedFileClass))
-
-typedef struct _GArrowMemoryMappedFile GArrowMemoryMappedFile;
-typedef struct _GArrowMemoryMappedFileClass GArrowMemoryMappedFileClass;
-
-/**
- * GArrowMemoryMappedFile:
- *
- * It wraps `arrow::io::MemoryMappedFile`.
- */
-struct _GArrowMemoryMappedFile
-{
- /*< private >*/
- GObject parent_instance;
-};
-
-struct _GArrowMemoryMappedFileClass
-{
- GObjectClass parent_class;
-};
-
-GType garrow_memory_mapped_file_get_type(void) G_GNUC_CONST;
-
-GArrowMemoryMappedFile *garrow_memory_mapped_file_open(const gchar *path,
- GArrowFileMode mode,
- GError **error);
-
-G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/memory-mapped-file.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/memory-mapped-file.hpp b/c_glib/arrow-glib/memory-mapped-file.hpp
deleted file mode 100644
index 522e43d..0000000
--- a/c_glib/arrow-glib/memory-mapped-file.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.
- */
-
-#pragma once
-
-#include <arrow/api.h>
-#include <arrow/io/file.h>
-
-#include <arrow-glib/memory-mapped-file.h>
-
-GArrowMemoryMappedFile *garrow_memory_mapped_file_new_raw(std::shared_ptr<arrow::io::MemoryMappedFile> *arrow_memory_mapped_file);
-std::shared_ptr<arrow::io::MemoryMappedFile> garrow_memory_mapped_file_get_raw(GArrowMemoryMappedFile *memory_mapped_file);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/random-access-file.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/random-access-file.cpp b/c_glib/arrow-glib/random-access-file.cpp
deleted file mode 100644
index 7441316..0000000
--- a/c_glib/arrow-glib/random-access-file.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <arrow/api.h>
-
-#include <arrow-glib/buffer.hpp>
-#include <arrow-glib/error.hpp>
-#include <arrow-glib/random-access-file.hpp>
-
-G_BEGIN_DECLS
-
-/**
- * SECTION: random-access-file
- * @title: GArrowRandomAccessFile
- * @short_description: File input interface
- *
- * #GArrowRandomAccessFile is an interface for file input.
- */
-
-G_DEFINE_INTERFACE(GArrowRandomAccessFile,
- garrow_random_access_file,
- G_TYPE_OBJECT)
-
-static void
-garrow_random_access_file_default_init (GArrowRandomAccessFileInterface *iface)
-{
-}
-
-/**
- * garrow_random_access_file_get_size:
- * @file: A #GArrowRandomAccessFile.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The size of the file.
- */
-guint64
-garrow_random_access_file_get_size(GArrowRandomAccessFile *file,
- GError **error)
-{
- auto *iface = GARROW_RANDOM_ACCESS_FILE_GET_IFACE(file);
- auto arrow_random_access_file = iface->get_raw(file);
- int64_t size;
-
- auto status = arrow_random_access_file->GetSize(&size);
- if (garrow_error_check(error, status, "[io][random-access-file][get-size]")) {
- return size;
- } else {
- return 0;
- }
-}
-
-/**
- * garrow_random_access_file_get_support_zero_copy:
- * @file: A #GArrowRandomAccessFile.
- *
- * Returns: Whether zero copy read is supported or not.
- */
-gboolean
-garrow_random_access_file_get_support_zero_copy(GArrowRandomAccessFile *file)
-{
- auto *iface = GARROW_RANDOM_ACCESS_FILE_GET_IFACE(file);
- auto arrow_random_access_file = iface->get_raw(file);
-
- return arrow_random_access_file->supports_zero_copy();
-}
-
-/**
- * garrow_random_access_file_read_at:
- * @file: A #GArrowRandomAccessFile.
- * @position: The read start position.
- * @n_bytes: The number of bytes to be read.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: (transfer full) (nullable): #GArrowBuffer that has read
- * data on success, %NULL if there was an error.
- */
-GArrowBuffer *
-garrow_random_access_file_read_at(GArrowRandomAccessFile *file,
- gint64 position,
- gint64 n_bytes,
- GError **error)
-{
- const auto arrow_random_access_file =
- garrow_random_access_file_get_raw(file);
-
- std::shared_ptr<arrow::Buffer> arrow_buffer;
- auto status = arrow_random_access_file->ReadAt(position,
- n_bytes,
- &arrow_buffer);
- if (garrow_error_check(error, status, "[io][random-access-file][read-at]")) {
- return garrow_buffer_new_raw(&arrow_buffer);
- } else {
- return NULL;
- }
-}
-
-G_END_DECLS
-
-std::shared_ptr<arrow::io::RandomAccessFile>
-garrow_random_access_file_get_raw(GArrowRandomAccessFile *random_access_file)
-{
- auto *iface = GARROW_RANDOM_ACCESS_FILE_GET_IFACE(random_access_file);
- return iface->get_raw(random_access_file);
-}
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/random-access-file.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/random-access-file.h b/c_glib/arrow-glib/random-access-file.h
deleted file mode 100644
index 83a7d8c..0000000
--- a/c_glib/arrow-glib/random-access-file.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.
- */
-
-#pragma once
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GARROW_TYPE_RANDOM_ACCESS_FILE \
- (garrow_random_access_file_get_type())
-#define GARROW_RANDOM_ACCESS_FILE(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj), \
- GARROW_TYPE_RANDOM_ACCESS_FILE, \
- GArrowRandomAccessFile))
-#define GARROW_IS_RANDOM_ACCESS_FILE(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
- GARROW_TYPE_RANDOM_ACCESS_FILE))
-#define GARROW_RANDOM_ACCESS_FILE_GET_IFACE(obj) \
- (G_TYPE_INSTANCE_GET_INTERFACE((obj), \
- GARROW_TYPE_RANDOM_ACCESS_FILE, \
- GArrowRandomAccessFileInterface))
-
-typedef struct _GArrowRandomAccessFile GArrowRandomAccessFile;
-typedef struct _GArrowRandomAccessFileInterface GArrowRandomAccessFileInterface;
-
-GType garrow_random_access_file_get_type(void) G_GNUC_CONST;
-
-guint64 garrow_random_access_file_get_size(GArrowRandomAccessFile *file,
- GError **error);
-gboolean garrow_random_access_file_get_support_zero_copy(GArrowRandomAccessFile *file);
-GArrowBuffer *garrow_random_access_file_read_at(GArrowRandomAccessFile *file,
- gint64 position,
- gint64 n_bytes,
- GError **error);
-
-G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/arrow-glib/random-access-file.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/random-access-file.hpp b/c_glib/arrow-glib/random-access-file.hpp
deleted file mode 100644
index 6d6fed7..0000000
--- a/c_glib/arrow-glib/random-access-file.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.
- */
-
-#pragma once
-
-#include <arrow/io/interfaces.h>
-
-#include <arrow-glib/random-access-file.h>
-
-/**
- * GArrowRandomAccessFileInterface:
- *
- * It wraps `arrow::io::RandomAccessFile`.
- */
-struct _GArrowRandomAccessFileInterface
-{
- GTypeInterface parent_iface;
-
- std::shared_ptr<arrow::io::RandomAccessFile> (*get_raw)(GArrowRandomAccessFile *file);
-};
-
-std::shared_ptr<arrow::io::RandomAccessFile> garrow_random_access_file_get_raw(GArrowRandomAccessFile *random_access_file);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/doc/reference/arrow-glib-docs.sgml
----------------------------------------------------------------------
diff --git a/c_glib/doc/reference/arrow-glib-docs.sgml b/c_glib/doc/reference/arrow-glib-docs.sgml
index 7ba37b4..8c691de 100644
--- a/c_glib/doc/reference/arrow-glib-docs.sgml
+++ b/c_glib/doc/reference/arrow-glib-docs.sgml
@@ -82,7 +82,6 @@
<title>Input</title>
<xi:include href="xml/readable.xml"/>
<xi:include href="xml/input-stream.xml"/>
- <xi:include href="xml/random-access-file.xml"/>
</chapter>
<chapter id="output">
<title>Output</title>
@@ -93,7 +92,6 @@
<chapter id="input-output">
<title>Input and output</title>
<xi:include href="xml/file.xml"/>
- <xi:include href="xml/memory-mapped-file.xml"/>
</chapter>
</part>
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/example/lua/read-batch.lua
----------------------------------------------------------------------
diff --git a/c_glib/example/lua/read-batch.lua b/c_glib/example/lua/read-batch.lua
index b28d346..8b129c9 100644
--- a/c_glib/example/lua/read-batch.lua
+++ b/c_glib/example/lua/read-batch.lua
@@ -20,7 +20,7 @@ local Arrow = lgi.Arrow
local input_path = arg[1] or "/tmp/batch.arrow";
-local input = Arrow.MemoryMappedFile.open(input_path, Arrow.FileMode.READ)
+local input = Arrow.MemoryMappedInputStream.new(input_path)
local reader = Arrow.FileReader.open(input)
for i = 0, reader:get_n_record_batches() - 1 do
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/example/lua/read-stream.lua
----------------------------------------------------------------------
diff --git a/c_glib/example/lua/read-stream.lua b/c_glib/example/lua/read-stream.lua
index 3b08206..e744bed 100644
--- a/c_glib/example/lua/read-stream.lua
+++ b/c_glib/example/lua/read-stream.lua
@@ -20,7 +20,7 @@ local Arrow = lgi.Arrow
local input_path = arg[1] or "/tmp/stream.arrow";
-local input = Arrow.MemoryMappedFile.open(input_path, Arrow.FileMode.READ)
+local input = Arrow.MemoryMappedInputStream.new(input_path)
local reader = Arrow.StreamReader.open(input)
local i = 0
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/example/read-batch.c
----------------------------------------------------------------------
diff --git a/c_glib/example/read-batch.c b/c_glib/example/read-batch.c
index dce96b8..25f19b2 100644
--- a/c_glib/example/read-batch.c
+++ b/c_glib/example/read-batch.c
@@ -87,14 +87,13 @@ int
main(int argc, char **argv)
{
const char *input_path = "/tmp/batch.arrow";
- GArrowMemoryMappedFile *input;
+ GArrowMemoryMappedInputStream *input;
GError *error = NULL;
if (argc > 1)
input_path = argv[1];
- input = garrow_memory_mapped_file_open(input_path,
- GARROW_FILE_MODE_READ,
- &error);
+ input = garrow_memory_mapped_input_stream_new(input_path,
+ &error);
if (!input) {
g_print("failed to open file: %s\n", error->message);
g_error_free(error);
@@ -104,7 +103,7 @@ main(int argc, char **argv)
{
GArrowFileReader *reader;
- reader = garrow_file_reader_open(GARROW_RANDOM_ACCESS_FILE(input),
+ reader = garrow_file_reader_open(GARROW_SEEKABLE_INPUT_STREAM(input),
&error);
if (!reader) {
g_print("failed to open file reader: %s\n", error->message);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/example/read-stream.c
----------------------------------------------------------------------
diff --git a/c_glib/example/read-stream.c b/c_glib/example/read-stream.c
index ba461e3..ca5b9d9 100644
--- a/c_glib/example/read-stream.c
+++ b/c_glib/example/read-stream.c
@@ -87,14 +87,12 @@ int
main(int argc, char **argv)
{
const char *input_path = "/tmp/stream.arrow";
- GArrowMemoryMappedFile *input;
+ GArrowMemoryMappedInputStream *input;
GError *error = NULL;
if (argc > 1)
input_path = argv[1];
- input = garrow_memory_mapped_file_open(input_path,
- GARROW_FILE_MODE_READ,
- &error);
+ input = garrow_memory_mapped_input_stream_new(input_path, &error);
if (!input) {
g_print("failed to open file: %s\n", error->message);
g_error_free(error);
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-buffer-input-stream.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-buffer-input-stream.rb b/c_glib/test/test-buffer-input-stream.rb
new file mode 100644
index 0000000..51ed8b3
--- /dev/null
+++ b/c_glib/test/test-buffer-input-stream.rb
@@ -0,0 +1,25 @@
+# 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.
+
+class TestBufferInputStream < Test::Unit::TestCase
+ def test_read
+ buffer = Arrow::Buffer.new("Hello World")
+ buffer_input_stream = Arrow::BufferInputStream.new(buffer)
+ read_buffer = buffer_input_stream.read(5)
+ assert_equal("Hello", read_buffer.data.to_s)
+ end
+end
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-buffer-reader.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-buffer-reader.rb b/c_glib/test/test-buffer-reader.rb
deleted file mode 100644
index d05ed06..0000000
--- a/c_glib/test/test-buffer-reader.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# 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.
-
-class TestBufferReader < Test::Unit::TestCase
- def test_read
- buffer = Arrow::Buffer.new("Hello World")
- buffer_reader = Arrow::BufferReader.new(buffer)
- read_buffer = buffer_reader.read(5)
- assert_equal("Hello", read_buffer.data.to_s)
- end
-end
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-file-writer.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-file-writer.rb b/c_glib/test/test-file-writer.rb
index 31c094d..6d4100a 100644
--- a/c_glib/test/test-file-writer.rb
+++ b/c_glib/test/test-file-writer.rb
@@ -33,7 +33,7 @@ class TestFileWriter < Test::Unit::TestCase
output.close
end
- input = Arrow::MemoryMappedFile.open(tempfile.path, :read)
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
begin
file_reader = Arrow::FileReader.open(input)
assert_equal(["enabled"],
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-memory-mapped-file.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-memory-mapped-file.rb b/c_glib/test/test-memory-mapped-file.rb
deleted file mode 100644
index e09e369..0000000
--- a/c_glib/test/test-memory-mapped-file.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-# 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.
-
-class TestMemoryMappedFile < Test::Unit::TestCase
- def test_open
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
- begin
- buffer = file.read(5)
- assert_equal("Hello", buffer.data.to_s)
- ensure
- file.close
- end
- end
-
- def test_size
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
- begin
- assert_equal(5, file.size)
- ensure
- file.close
- end
- end
-
- def test_read
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello World")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
- begin
- buffer = file.read(5)
- assert_equal("Hello", buffer.data.to_s)
- ensure
- file.close
- end
- end
-
- def test_read_at
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello World")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
- begin
- buffer = file.read_at(6, 5)
- assert_equal("World", buffer.data.to_s)
- ensure
- file.close
- end
- end
-
- def test_write
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :readwrite)
- begin
- file.write("World")
- ensure
- file.close
- end
- assert_equal("World", File.read(tempfile.path))
- end
-
- def test_write_at
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :readwrite)
- begin
- file.write_at(2, "rld")
- ensure
- file.close
- end
- assert_equal("Herld", File.read(tempfile.path))
- end
-
- def test_flush
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :readwrite)
- begin
- file.write("World")
- file.flush
- assert_equal("World", File.read(tempfile.path))
- ensure
- file.close
- end
- end
-
- def test_tell
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello World")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
- begin
- file.read(5)
- assert_equal(5, file.tell)
- ensure
- file.close
- end
- end
-
- def test_mode
- tempfile = Tempfile.open("arrow-io-memory-mapped-file")
- tempfile.write("Hello World")
- tempfile.close
- file = Arrow::MemoryMappedFile.open(tempfile.path, :readwrite)
- begin
- assert_equal(Arrow::FileMode::READWRITE, file.mode)
- ensure
- file.close
- end
- end
-end
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-memory-mapped-input-stream.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-memory-mapped-input-stream.rb b/c_glib/test/test-memory-mapped-input-stream.rb
new file mode 100644
index 0000000..c3a5f62
--- /dev/null
+++ b/c_glib/test/test-memory-mapped-input-stream.rb
@@ -0,0 +1,82 @@
+# 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.
+
+class TestMemoryMappedInputStream < Test::Unit::TestCase
+ def test_new
+ tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+ tempfile.write("Hello")
+ tempfile.close
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+ begin
+ buffer = input.read(5)
+ assert_equal("Hello", buffer.data.to_s)
+ ensure
+ input.close
+ end
+ end
+
+ def test_size
+ tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+ tempfile.write("Hello")
+ tempfile.close
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+ begin
+ assert_equal(5, input.size)
+ ensure
+ input.close
+ end
+ end
+
+ def test_read
+ tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+ tempfile.write("Hello World")
+ tempfile.close
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+ begin
+ buffer = input.read(5)
+ assert_equal("Hello", buffer.data.to_s)
+ ensure
+ input.close
+ end
+ end
+
+ def test_read_at
+ tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+ tempfile.write("Hello World")
+ tempfile.close
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+ begin
+ buffer = input.read_at(6, 5)
+ assert_equal("World", buffer.data.to_s)
+ ensure
+ input.close
+ end
+ end
+
+
+ def test_mode
+ tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+ tempfile.write("Hello World")
+ tempfile.close
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+ begin
+ assert_equal(Arrow::FileMode::READWRITE, input.mode)
+ ensure
+ input.close
+ end
+ end
+end
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1bd49d5/c_glib/test/test-stream-writer.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-stream-writer.rb b/c_glib/test/test-stream-writer.rb
index 306115e..4280c1b 100644
--- a/c_glib/test/test-stream-writer.rb
+++ b/c_glib/test/test-stream-writer.rb
@@ -38,7 +38,7 @@ class TestStreamWriter < Test::Unit::TestCase
output.close
end
- input = Arrow::MemoryMappedFile.open(tempfile.path, :read)
+ input = Arrow::MemoryMappedInputStream.new(tempfile.path)
begin
stream_reader = Arrow::StreamReader.open(input)
assert_equal(["enabled"],