Skip to content

Commit

Permalink
make it possible to get single objects
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz committed Aug 27, 2017
1 parent 36f67d6 commit 20b119e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
32 changes: 19 additions & 13 deletions python/pyarrow/plasma.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from libcpp.vector cimport vector as c_vector
from libc.stdint cimport int64_t, uint8_t, uintptr_t
from cpython.pycapsule cimport *

import collections
import pyarrow

from pyarrow.lib cimport Buffer, NativeFile, check_status, SerializedPyObject
Expand All @@ -43,6 +44,9 @@ cdef extern from "plasma/common.h" nogil:
@staticmethod
CUniqueID from_binary(const c_string& binary)

@staticmethod
CUniqueID from_random()

c_bool operator==(const CUniqueID& rhs) const

c_string hex() const
Expand Down Expand Up @@ -161,9 +165,8 @@ cdef class ObjectID:

@staticmethod
def from_random():
cdef ObjectID result
result.data = CUniqueID.from_random()
return result
cdef CUniqueID data = CUniqueID.from_random()
return ObjectID(data.binary())


cdef class ObjectNotAvailable:
Expand Down Expand Up @@ -652,13 +655,16 @@ def get(PlasmaClient client, object_ids, timeout_ms=-1):
List of Python values for the data associated with the object_ids
and ObjectNotAvailable if the object was not available.
"""
results = []
buffers = client.get(object_ids, timeout_ms)
for i in range(len(object_ids)):
# buffers[i] is None if this object was not available within the
# timeout
if buffers[i]:
results.append(pyarrow.deserialize(buffers[i]))
else:
results.append(ObjectNotAvailable)
return results
if isinstance(object_ids, collections.Sequence):
results = []
buffers = client.get(object_ids, timeout_ms)
for i in range(len(object_ids)):
# buffers[i] is None if this object was not available within the
# timeout
if buffers[i]:
results.append(pyarrow.deserialize(buffers[i]))
else:
results.append(ObjectNotAvailable)
return results
else:
return get(client, [object_ids], timeout_ms)[0]
3 changes: 3 additions & 0 deletions python/pyarrow/tests/test_plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ def test_put_and_get(self):
[result] = pa.plasma.get(self.plasma_client, [object_id])
assert result == value

result = pa.plasma.get(self.plasma_client, object_id)
assert result == value

object_id = pa.plasma.ObjectID(np.bytes.random(20))
[result] = pa.plasma.get(self.plasma_client, [object_id], timeout_ms=0)
assert result == pa.plasma.ObjectNotAvailable
Expand Down

0 comments on commit 20b119e

Please sign in to comment.