amol- commented on a change in pull request #84:
URL: https://github.com/apache/arrow-cookbook/pull/84#discussion_r726939322



##########
File path: python/source/flight.rst
##########
@@ -0,0 +1,228 @@
+============
+Arrow Flight
+============
+
+Recipes related to leveraging Arrow Flight protocol
+
+.. contents::
+
+Using an Arrow Flight RPC server
+================================
+
+Suppose you want to implement a service that can store, send and receive
+parquet files using the Arrow Flight protocol, 
+``pyarrow`` provides an implementation framework in :mod:`pyarrow.flight` 
+and particularly through the :class:`pyarrow.flight.FlightServerBase` class.
+
+.. testcode::
+
+    import pathlib
+    import threading
+
+    import pyarrow as pa
+    import pyarrow.flight
+    import pyarrow.parquet
+
+
+    class FlightServer(pa.flight.FlightServerBase):
+
+        def __init__(self, location="grpc://0.0.0.0:8815", 
+                    repo=pathlib.Path("./datasets"), **kwargs):
+            super(FlightServer, self).__init__(location, **kwargs)
+            self._location = location
+            self._repo = repo
+
+        def _make_flight_info(self, dataset):
+            dataset_path = self._repo / dataset
+            schema = pa.parquet.read_schema(dataset_path)
+            metadata = pa.parquet.read_metadata(dataset_path)
+            descriptor = pa.flight.FlightDescriptor.for_path(
+                dataset.encode('utf-8')
+            )
+            endpoints = [pa.flight.FlightEndpoint(dataset, [self._location])]
+            return pyarrow.flight.FlightInfo(schema,
+                                            descriptor, 
+                                            endpoints,
+                                            metadata.num_rows, 
+                                            metadata.serialized_size)
+
+        def list_flights(self, context, criteria):
+            for dataset in self._repo.iterdir():
+                yield self._make_flight_info(dataset.name)
+
+        def get_flight_info(self, context, descriptor):
+            return self._make_flight_info(descriptor.path[0].decode('utf-8'))
+
+        def do_put(self, context, descriptor, reader, writer):
+            dataset = descriptor.path[0].decode('utf-8')
+            dataset_path = self._repo / dataset
+            data_table = reader.read_all()
+            pa.parquet.write_table(data_table, dataset_path)

Review comment:
       Good suggestion, created 
https://github.com/apache/arrow-cookbook/issues/86




-- 
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