A Flight server that always returns the same data. See ARROW-4796: this server implementation will segfault if Flight does not properly hold a reference to the Table object.
| 136 | |
| 137 | |
| 138 | class ConstantFlightServer(FlightServerBase): |
| 139 | """A Flight server that always returns the same data. |
| 140 | |
| 141 | See ARROW-4796: this server implementation will segfault if Flight |
| 142 | does not properly hold a reference to the Table object. |
| 143 | """ |
| 144 | |
| 145 | CRITERIA = b"the expected criteria" |
| 146 | |
| 147 | def __init__(self, location=None, options=None, **kwargs): |
| 148 | super().__init__(location, **kwargs) |
| 149 | # Ticket -> Table |
| 150 | self.table_factories = { |
| 151 | b'ints': simple_ints_table, |
| 152 | b'dicts': simple_dicts_table, |
| 153 | b'multi': multiple_column_table, |
| 154 | } |
| 155 | self.options = options |
| 156 | |
| 157 | def list_flights(self, context, criteria): |
| 158 | if criteria == self.CRITERIA: |
| 159 | yield flight.FlightInfo( |
| 160 | pa.schema([]), |
| 161 | flight.FlightDescriptor.for_path('/foo'), |
| 162 | [] |
| 163 | ) |
| 164 | |
| 165 | def do_get(self, context, ticket): |
| 166 | # Return a fresh table, so that Flight is the only one keeping a |
| 167 | # reference. |
| 168 | table = self.table_factories[ticket.ticket]() |
| 169 | return flight.RecordBatchStream(table, options=self.options) |
| 170 | |
| 171 | |
| 172 | class MetadataFlightServer(FlightServerBase): |
no outgoing calls