paleolimbot commented on code in PR #388:
URL: https://github.com/apache/arrow-nanoarrow/pull/388#discussion_r1497713286


##########
python/src/nanoarrow/_ipc_lib.pyx:
##########
@@ -0,0 +1,145 @@
+# 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.
+
+# cython: language_level = 3
+# cython: linetrace=True
+
+from libc.stdint cimport uint8_t, int64_t, uintptr_t
+from libc.errno cimport EIO
+from libc.stdio cimport snprintf
+from cpython.ref cimport PyObject, Py_INCREF, Py_DECREF
+from cpython cimport Py_buffer, PyBuffer_FillInfo
+
+from nanoarrow_c cimport (
+    ArrowErrorCode,
+    ArrowError,
+    NANOARROW_OK,
+    ArrowArrayStream,
+)
+
+
+cdef extern from "nanoarrow_ipc.h" nogil:
+    struct ArrowIpcInputStream:
+        ArrowErrorCode (*read)(ArrowIpcInputStream* stream, uint8_t* buf,
+                               int64_t buf_size_bytes, int64_t* size_read_out,
+                               ArrowError* error)
+        void (*release)(ArrowIpcInputStream* stream)
+        void* private_data
+
+    struct ArrowIpcArrayStreamReaderOptions:
+        int64_t field_index
+        int use_shared_buffers
+
+    ArrowErrorCode ArrowIpcArrayStreamReaderInit(
+        ArrowArrayStream* out, ArrowIpcInputStream* input_stream,
+        ArrowIpcArrayStreamReaderOptions* options)
+
+
+cdef class PyInputStreamPrivate:
+    cdef object obj
+    cdef object obj_method
+    cdef void* addr
+    cdef Py_ssize_t size_bytes
+    cdef int close_stream
+
+    def __cinit__(self, obj, close_stream=False):
+        self.obj = obj
+        self.obj_method = obj.readinto
+        self.addr = NULL
+        self.size_bytes = 0
+        self.close_stream = close_stream
+
+    def __getbuffer__(self, Py_buffer* buffer, int flags):
+        PyBuffer_FillInfo(buffer, self, self.addr, self.size_bytes, 0, flags)
+
+    def __releasebuffer__(self, Py_buffer* buffer):
+        pass

Review Comment:
   Yes, that's basically unimplemented in the `ArrowIpcArrayStreamReader`...you 
will always need to pull the whole stream from start to finish and there is 
only a basic level of sharedness in the body buffer bytes such that there is at 
least a shared buffer between arrays in the same batch.
   
   The `ArrowInputStream` would need something like the `DoRead()` overload 
that returns a `Buffer` to implement what you're talking about (which would be 
a good idea):
   
   
https://github.com/apache/arrow/blob/6a22a1dee78b0f7daa7e4d8793d663e29a5712a6/cpp/src/arrow/io/file.h#L124
   
   ...or to wrap the `ArrowIpcDecoder`, which doesn't issue any read calls at 
all.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to