Sharing memory works inside one machine. Between machines and processes the data has to travel, and a protocol that turns columns into rows and back for the trip throws away what Arrow bought you. Arrow Flight and ADBC are the two answers: Flight streams record batches over gRPC, and ADBC gives database access that returns Arrow instead of rows. This topic is about the decisions around them, which is where real pipelines go wrong.
The idea in plain words
Where we are. Topic 6 wrote batches to files and streams. A Flight server sends the same streams over a network. Nothing here needs a server: each function models one decision (is this config safe, how to split a dataset, how to answer a ticket, how to bind a parameter), so you can reason about them and check them without any infrastructure. The capstone then builds a pipeline from the pieces of the whole skill.
A protocol on gRPC for moving Arrow record batches between services. A client asks for a dataset and receives endpoints, each with locations and a ticket; it then fetches the tickets, in parallel if it wants, as streams of batches that never leave columnar form.
Review the config before the first call
Most Flight incidents are configuration, not code. A grpc:// location sends data, and any token, in clear text. A TLS connection with no token lets anyone in. A batch size of five million rows can exhaust memory on the client; one of ten rows spends its time on headers. No timeout means one stuck server hangs the pipeline. review_flight_config turns these rules of thumb into a checklist that returns codes you can act on or fail a deployment on.
# Two configs: an unsafe one and a sound oneunsafe = {"location": "grpc://10.0.0.5:8815", "token": "s3cret", "max_batch_rows": 5_000_000, "timeout_s": None}sound = {"location": "grpc+tls://ticks.example:8815", "token": "s3cret", "max_batch_rows": 65_536, "timeout_s": 30}print("unsafe:", review_flight_config(unsafe))print("sound :", review_flight_config(sound))
unsafe: ['huge-batches', 'insecure-transport', 'no-timeout', 'token-in-clear'] sound : []
Endpoints and tickets
Splitting a dataset across endpoints is how Flight scales: ten servers each hold a range, and the client fetches all ten at once. plan_endpoints is the server's GetFlightInfo answer, a list of (location, start, stop). do_get is DoGet for one ticket: it slices that range and streams it as record batches. Fetching every ticket of the plan returns each row exactly once, in any order the client chooses.
# Split the bars across two nodes, then serve one ticket as batches of at most 4,000 rowsplan = plan_endpoints(table.num_rows, 10000, ["node-a:8815", "node-b:8815"])for endpoint in plan: print(endpoint)batches = do_get(table, plan[1][1:], 4000)print("batches for the second ticket:", [b.num_rows for b in batches])print("all tickets together:", sum(sum(b.num_rows for b in do_get(table, (s, e), 4000)) for _, s, e in plan), "rows of", table.num_rows)
('node-a:8815', 0, 10000)
('node-b:8815', 10000, 20000)
('node-a:8815', 20000, 30000)
('node-b:8815', 30000, 33493)
batches for the second ticket: [3397, 4000, 2603]
all tickets together: 33493 rows of 33493ADBC: bind parameters, never paste them
An ADBC statement is SQL text with ? placeholders plus a separate list of values. The driver sends them apart, so a value can never be read as SQL, which is the definition of safe against injection, and the database can reuse its plan for the same text. bind_params checks the one thing a client can check before sending: the number of placeholders, ignoring question marks inside quoted text, equals the number of values. A hostile string stays a value.
# A statement with two placeholders, one with a '?' inside text, and a count mismatchprint(bind_params("SELECT * FROM bars WHERE symbol = ? AND close > ?", ["KO", 50.0]))print(bind_params("SELECT 'why?' AS q, close FROM bars WHERE symbol = ?", ["JPM"]))print(bind_params("SELECT * FROM bars WHERE symbol = ?", ["x'; DROP TABLE bars; --"]))try: bind_params("SELECT * FROM bars WHERE symbol = ? AND close > ?", ["KO"])except ValueError as error: print("ValueError:", error)
('SELECT * FROM bars WHERE symbol = ? AND close > ?', ('KO', 50.0))
("SELECT 'why?' AS q, close FROM bars WHERE symbol = ?", ('JPM',))
('SELECT * FROM bars WHERE symbol = ?', ("x'; DROP TABLE bars; --",))
ValueError: 2 placeholders but 1 parametersA real client also handles retries, server-side authentication, cancellation and back-pressure when the consumer is slower than the stream. The models here keep the decisions testable; pyarrow.flight (a desktop library, not in the browser) and the ADBC drivers carry them out over a network.
What the tasks ask
- 1`review_flight_config`Take the scheme from the location; collect the codes in a set and return it sorted.
- 2`plan_endpoints` and `do_get`
range(0, num_rows, rows_per_endpoint)withlocations[k % len(locations)];table.slice(start, ...)thento_batches(max_chunksize=batch_rows). - 3`bind_params`Walk the characters, tracking whether you are inside
'...'or"..."; count?outside quotes; raiseValueErrorif the count differs.
Lab · what's graded
4 tasks · 100 pts- Review a client config:
review_flight_config25 pts - Split into endpoints:
plan_endpoints25 pts - Serve a ticket:
do_get25 pts - Bind, do not paste:
bind_params25 pts