MCPcopy Create free account
hub / github.com/apache/arrow / MetadataFlightServer

Class MetadataFlightServer

python/pyarrow/tests/test_flight.py:174–212  ·  view source on GitHub ↗

A Flight server that numbers incoming/outgoing data.

Source from the content-addressed store, hash-verified

172
173
174class MetadataFlightServer(FlightServerBase):
175 """A Flight server that numbers incoming/outgoing data."""
176
177 def __init__(self, options=None, **kwargs):
178 super().__init__(**kwargs)
179 self.options = options
180
181 def do_get(self, context, ticket):
182 data = [
183 pa.array([-10, -5, 0, 5, 10])
184 ]
185 table = pa.Table.from_arrays(data, names=['a'])
186 return flight.GeneratorStream(
187 table.schema,
188 self.number_batches(table),
189 options=self.options)
190
191 def do_put(self, context, descriptor, reader, writer):
192 counter = 0
193 expected_data = [-10, -5, 0, 5, 10]
194 assert reader.stats.num_messages == 1
195 for batch, buf in reader:
196 assert batch.equals(pa.RecordBatch.from_arrays(
197 [pa.array([expected_data[counter]])],
198 ['a']
199 ))
200 assert buf is not None
201 client_counter, = struct.unpack('<i', buf.to_pybytes())
202 assert counter == client_counter
203 writer.write(struct.pack('<i', counter))
204 counter += 1
205 assert reader.stats.num_messages == 6
206 assert reader.stats.num_record_batches == 5
207
208 @staticmethod
209 def number_batches(table):
210 for idx, batch in enumerate(table.to_batches()):
211 buf = struct.pack('<i', idx)
212 yield batch, buf
213
214
215class EchoFlightServer(FlightServerBase):

Calls

no outgoing calls