Skip to content

Commit 20b119e

Browse files
committed
make it possible to get single objects
1 parent 36f67d6 commit 20b119e

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

python/pyarrow/plasma.pyx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from libcpp.vector cimport vector as c_vector
2626
from libc.stdint cimport int64_t, uint8_t, uintptr_t
2727
from cpython.pycapsule cimport *
2828

29+
import collections
2930
import pyarrow
3031

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

47+
@staticmethod
48+
CUniqueID from_random()
49+
4650
c_bool operator==(const CUniqueID& rhs) const
4751

4852
c_string hex() const
@@ -161,9 +165,8 @@ cdef class ObjectID:
161165

162166
@staticmethod
163167
def from_random():
164-
cdef ObjectID result
165-
result.data = CUniqueID.from_random()
166-
return result
168+
cdef CUniqueID data = CUniqueID.from_random()
169+
return ObjectID(data.binary())
167170

168171

169172
cdef class ObjectNotAvailable:
@@ -652,13 +655,16 @@ def get(PlasmaClient client, object_ids, timeout_ms=-1):
652655
List of Python values for the data associated with the object_ids
653656
and ObjectNotAvailable if the object was not available.
654657
"""
655-
results = []
656-
buffers = client.get(object_ids, timeout_ms)
657-
for i in range(len(object_ids)):
658-
# buffers[i] is None if this object was not available within the
659-
# timeout
660-
if buffers[i]:
661-
results.append(pyarrow.deserialize(buffers[i]))
662-
else:
663-
results.append(ObjectNotAvailable)
664-
return results
658+
if isinstance(object_ids, collections.Sequence):
659+
results = []
660+
buffers = client.get(object_ids, timeout_ms)
661+
for i in range(len(object_ids)):
662+
# buffers[i] is None if this object was not available within the
663+
# timeout
664+
if buffers[i]:
665+
results.append(pyarrow.deserialize(buffers[i]))
666+
else:
667+
results.append(ObjectNotAvailable)
668+
return results
669+
else:
670+
return get(client, [object_ids], timeout_ms)[0]

python/pyarrow/tests/test_plasma.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ def test_put_and_get(self):
279279
[result] = pa.plasma.get(self.plasma_client, [object_id])
280280
assert result == value
281281

282+
result = pa.plasma.get(self.plasma_client, object_id)
283+
assert result == value
284+
282285
object_id = pa.plasma.ObjectID(np.bytes.random(20))
283286
[result] = pa.plasma.get(self.plasma_client, [object_id], timeout_ms=0)
284287
assert result == pa.plasma.ObjectNotAvailable

0 commit comments

Comments
 (0)