mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
Lint Python Flight code
This commit is contained in:
1 parent
f33b51f74d
commit
9839e0f144
5 files changed
+48
-25
No files matched your search
@@ -34,7 +34,6 @@ namespace flight {
|
||||
/// \brief A table of function pointers for calling from C++ into
|
||||
/// Python.
|
||||
class ARROW_PYTHON_EXPORT PyFlightServerVtable {
|
||||
|
||||
public:
|
||||
// Must return int so Cython will propagate exceptions
|
||||
std::function<int(PyObject*, const arrow::flight::Criteria*,
|
||||
@@ -75,12 +74,14 @@ class ARROW_PYTHON_EXPORT PyFlightServer : public arrow::flight::FlightServerBas
|
||||
};
|
||||
|
||||
/// \brief A callback that obtains the next result from a Flight action.
|
||||
typedef std::function<int(PyObject*, std::unique_ptr<arrow::flight::Result>*)> PyFlightResultStreamCallback;
|
||||
typedef std::function<int(PyObject*, std::unique_ptr<arrow::flight::Result>*)>
|
||||
PyFlightResultStreamCallback;
|
||||
|
||||
/// \brief A ResultStream built around a Python callback.
|
||||
class ARROW_PYTHON_EXPORT PyFlightResultStream : public arrow::flight::ResultStream {
|
||||
public:
|
||||
explicit PyFlightResultStream(PyObject* generator, PyFlightResultStreamCallback callback);
|
||||
explicit PyFlightResultStream(PyObject* generator,
|
||||
PyFlightResultStreamCallback callback);
|
||||
Status Next(std::unique_ptr<arrow::flight::Result>* result) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -36,12 +36,14 @@ class FlightServer(pyarrow.flight.FlightServerBase):
|
||||
def list_flights(self, criteria):
|
||||
for key, table in self.flights.items():
|
||||
if key[1] is not None:
|
||||
descriptor = pyarrow.flight.FlightDescriptor.for_command(key[1])
|
||||
descriptor = \
|
||||
pyarrow.flight.FlightDescriptor.for_command(key[1])
|
||||
else:
|
||||
descriptor = pyarrow.flight.FlightDescriptor.for_path(*key[2])
|
||||
|
||||
endpoints = [
|
||||
pyarrow.flight.FlightEndpoint(repr(key), [('localhost', 5005)]),
|
||||
pyarrow.flight.FlightEndpoint(repr(key),
|
||||
[('localhost', 5005)]),
|
||||
]
|
||||
yield pyarrow.flight.FlightInfo(table.schema,
|
||||
descriptor, endpoints,
|
||||
@@ -52,7 +54,8 @@ class FlightServer(pyarrow.flight.FlightServerBase):
|
||||
if key in self.flights:
|
||||
table = self.flights[key]
|
||||
endpoints = [
|
||||
pyarrow.flight.FlightEndpoint(repr(key), [('localhost', 5005)]),
|
||||
pyarrow.flight.FlightEndpoint(repr(key),
|
||||
[('localhost', 5005)]),
|
||||
]
|
||||
return pyarrow.flight.FlightInfo(table.schema,
|
||||
descriptor, endpoints,
|
||||
@@ -80,7 +83,8 @@ class FlightServer(pyarrow.flight.FlightServerBase):
|
||||
|
||||
def do_action(self, action):
|
||||
if action.type == "clear":
|
||||
raise NotImplementedError("{} is not implemented.".format(action.type))
|
||||
raise NotImplementedError(
|
||||
"{} is not implemented.".format(action.type))
|
||||
else:
|
||||
yield pyarrow.flight.Result(pyarrow.py_buffer(b'Shutdown!'))
|
||||
|
||||
|
||||
+20
-11
@@ -47,7 +47,10 @@ cdef class Action:
|
||||
return pyarrow_wrap_buffer(self.action.body)
|
||||
|
||||
|
||||
class ActionType(collections.namedtuple('ActionType', ['type', 'description'])):
|
||||
_ActionType = collections.namedtuple('_ActionType', ['type', 'description'])
|
||||
|
||||
|
||||
class ActionType(_ActionType):
|
||||
"""A type of action executable on a Flight service."""
|
||||
|
||||
def make_action(self, buf):
|
||||
@@ -414,18 +417,21 @@ cdef class RecordBatchStream(FlightDataStream):
|
||||
"""
|
||||
cdef shared_ptr[CRecordBatchReader] reader
|
||||
if isinstance(data_source, _CRecordBatchReader):
|
||||
stream = new CRecordBatchStream((<_CRecordBatchReader> data_source).reader)
|
||||
reader = (<_CRecordBatchReader> data_source).reader
|
||||
stream = new CRecordBatchStream(reader)
|
||||
self.stream.reset(stream)
|
||||
elif isinstance(data_source, lib.Table):
|
||||
reader.reset(new TableBatchReader(deref((<Table> data_source).table)))
|
||||
table = (<Table> data_source).table
|
||||
reader.reset(new TableBatchReader(deref(table)))
|
||||
stream = new CRecordBatchStream(reader)
|
||||
self.stream.reset(stream)
|
||||
else:
|
||||
raise TypeError("Expected RecordBatchReader or Table, but got: {}".format(type(data_source)))
|
||||
raise TypeError("Expected RecordBatchReader or Table, "
|
||||
"but got: {}".format(type(data_source)))
|
||||
|
||||
|
||||
cdef int _list_flights(void* self, const CCriteria* c_criteria,
|
||||
unique_ptr[CFlightListing]* listing) except -1:
|
||||
unique_ptr[CFlightListing]* listing) except -1:
|
||||
"""Callback for implementing ListFlights in Python."""
|
||||
cdef:
|
||||
vector[CFlightInfo] flights
|
||||
@@ -433,14 +439,15 @@ cdef int _list_flights(void* self, const CCriteria* c_criteria,
|
||||
for info in result:
|
||||
if not isinstance(info, FlightInfo):
|
||||
raise TypeError("FlightServerBase.list_flights must return "
|
||||
"FlightInfo instances, but got {}".format(type(info)))
|
||||
"FlightInfo instances, but got {}".format(
|
||||
type(info)))
|
||||
flights.push_back(CFlightInfo(deref((<FlightInfo> info).info.get())))
|
||||
listing.reset(new CSimpleFlightListing(flights))
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _get_flight_info(void* self, CFlightDescriptor c_descriptor,
|
||||
unique_ptr[CFlightInfo]* info) except -1:
|
||||
unique_ptr[CFlightInfo]* info) except -1:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
FlightDescriptor py_descriptor = \
|
||||
@@ -449,12 +456,14 @@ cdef int _get_flight_info(void* self, CFlightDescriptor c_descriptor,
|
||||
result = (<object> self).get_flight_info(py_descriptor)
|
||||
if not isinstance(result, FlightInfo):
|
||||
raise TypeError("FlightServerBase.get_flight_info must return "
|
||||
"a FlightInfo instance")
|
||||
"a FlightInfo instance, but got {}".format(
|
||||
type(result)))
|
||||
info[0] = move((<FlightInfo> result).info)
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _do_put(void* self, unique_ptr[CFlightMessageReader] reader) except -1:
|
||||
cdef int _do_put(void* self,
|
||||
unique_ptr[CFlightMessageReader] reader) except -1:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
FlightRecordBatchReader py_reader = FlightRecordBatchReader()
|
||||
@@ -468,7 +477,7 @@ cdef int _do_put(void* self, unique_ptr[CFlightMessageReader] reader) except -1:
|
||||
|
||||
|
||||
cdef int _do_get(void* self, CTicket ticket,
|
||||
unique_ptr[CFlightDataStream]* stream) except -1:
|
||||
unique_ptr[CFlightDataStream]* stream) except -1:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
py_ticket = Ticket(ticket.ticket)
|
||||
result = (<object> self).do_get(py_ticket)
|
||||
@@ -480,7 +489,7 @@ cdef int _do_get(void* self, CTicket ticket,
|
||||
|
||||
|
||||
cdef int _do_action_result_next(void* self,
|
||||
unique_ptr[CResult]* result) except -1:
|
||||
unique_ptr[CResult]* result) except -1:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
try:
|
||||
action_result = next(<object> self)
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from pyarrow._flight import (FlightClient, Action, ActionType, # noqa
|
||||
FlightDescriptor, FlightEndpoint,
|
||||
FlightInfo, Ticket, Location,
|
||||
FlightServerBase, DescriptorType,
|
||||
RecordBatchStream, Result)
|
||||
from pyarrow._flight import (Action, # noqa
|
||||
ActionType,
|
||||
DescriptorType,
|
||||
FlightClient,
|
||||
FlightDescriptor,
|
||||
FlightEndpoint,
|
||||
FlightInfo,
|
||||
FlightServerBase,
|
||||
Location,
|
||||
Ticket,
|
||||
RecordBatchStream,
|
||||
Result)
|
||||
@@ -147,8 +147,10 @@ cdef extern from "arrow/python/flight.h" namespace "arrow::py::flight" nogil:
|
||||
void Run(int port)
|
||||
void Shutdown()
|
||||
|
||||
cdef cppclass CPyFlightResultStream" arrow::py::flight::PyFlightResultStream"(CResultStream):
|
||||
CPyFlightResultStream(object generator, function[cb_result_next] callback)
|
||||
cdef cppclass CPyFlightResultStream\
|
||||
" arrow::py::flight::PyFlightResultStream"(CResultStream):
|
||||
CPyFlightResultStream(object generator,
|
||||
function[cb_result_next] callback)
|
||||
|
||||
cdef CStatus CreateFlightInfo" arrow::py::flight::CreateFlightInfo"(
|
||||
shared_ptr[CSchema] schema,
|
||||
|
||||
Reference in new issue
Block a user