Beispiel #1
0
 def do_exchange(self, context, descriptor, reader, writer):
     if descriptor.descriptor_type != flight.DescriptorType.CMD:
         raise pa.ArrowInvalid("Must provide a command descriptor")
     elif descriptor.command == b"echo":
         return self.exchange_echo(context, reader, writer)
     elif descriptor.command == b"get":
         return self.exchange_do_get(context, reader, writer)
     elif descriptor.command == b"put":
         return self.exchange_do_put(context, reader, writer)
     elif descriptor.command == b"transform":
         return self.exchange_transform(context, reader, writer)
     else:
         raise pa.ArrowInvalid(
             "Unknown command: {}".format(descriptor.command))
Beispiel #2
0
 def exchange_do_put(self, context, reader, writer):
     """Emulate DoPut with DoExchange."""
     num_batches = 0
     for chunk in reader:
         if not chunk.data:
             raise pa.ArrowInvalid("All chunks must have data.")
         num_batches += 1
     writer.write_metadata(str(num_batches).encode("utf-8"))
Beispiel #3
0
 def exchange_transform(self, context, reader, writer):
     """Sum rows in an uploaded table."""
     for field in reader.schema:
         if not pa.types.is_integer(field.type):
             raise pa.ArrowInvalid("Invalid field: " + repr(field))
     table = reader.read_all()
     sums = [0] * table.num_rows
     for column in table:
         for row, value in enumerate(column):
             sums[row] += value.as_py()
     result = pa.Table.from_arrays([pa.array(sums)], names=["sum"])
     writer.begin(result.schema)
     writer.write_table(result)