Practice problem · Datadog · Medium

Warehouse Query Client

A cloud data warehouse runs SQL statements asynchronously: a client submits one, polls until it is done, then reads the result in pages. 3 stages in Python with an AI assistant. Pro.

Stage 1 of 3: Submit, wait, read

Background. A cloud data warehouse runs SQL statements asynchronously: a client submits one, polls until it is done, then reads the result in pages. warehouse.py is the service, read-only: Connection.submit(sql) returns a statement id, status(id) says RUNNING, SUCCEEDED, FAILED or CANCELLED (with an error code and message when it failed), fetch(id, page) returns a page of rows and whether there are more, cancel(id) stops a statement, and the module docstring lists the limits the service enforces. Time is simulated: the tests give the client a sleep that moves the warehouse's clock, so waiting costs nothing real.

Implement QueryClient.run(sql) in client.py.

  • QueryClient(connection, sleep=time.sleep, poll_interval=0.5, timeout=30.0).
  • run(sql) submits the statement and returns its rows, every page in order, once it has succeeded.
  • While the statement is running, the client checks its status, then calls sleep(poll_interval) before checking again; every sleep is a full poll_interval, the last one before the timeout included. It never fetches rows before the statement has succeeded.
  • A FAILED statement raises QueryFailed(sql, code, message); a CANCELLED one raises QueryFailed with code CANCELLED.
  • The time waited is the sum of the sleeps so far. When it has reached timeout and the statement is still running, the client cancels it and raises QueryTimeout(sql, timeout). A statement that is done when the check at the timeout happens is done.

Example

wh = Warehouse({"SELECT 1": Query(duration=1.0, rows=[{"1": 1}])})
c = QueryClient(wh.connect("secret"), sleep=wh.advance, poll_interval=0.5)
c.run("SELECT 1")      # [{"1": 1}], after about three status checks and two half-second sleeps
wh.now                 # 1.0

Done when Submit goes green.

Constraints

  • Python 3.12+ standard library only
  • Time limit: 10 seconds per test file
  • Editable: client.py
  • Read-only: warehouse.py, test_helpers.py and all tests/test_*.py files

What comes after stage 1

The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.

  1. Stage 2: Results too large to hold. Millions of rows and a caller who may stop after ten of them.
  2. Stage 3: Many statements at once. Dozens of statements, a service with a concurrency limit that sometimes fails one for no lasting reason.

The files you get

  • Yours to edit: client.py.
  • Read-only: warehouse.py, test_helpers.py, tests/__init__.py.
  • Tests you can read and run: tests/test_part1_run.py. Hidden tests run on Submit.

The round: an agent in the editor

The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.

Frequently asked, briefly answered

Is Warehouse Query Client free?

It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.

Which company asks something like this?

Datadog. It is modelled on Datadog's round: AI coding round (since spring 2026): any AI tool of your own, screen shared, a small integration task such as a client for a cloud data warehouse, then production follow-ups on large results, secrets and batching; the company publishes guidelines for the round.

Do I bring my own AI tool?

No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.

What does the interviewer ask?

2 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.

Start this problem → Sign in

More like it: every practice problem, how Datadog runs its AI round, the AI coding interview guide.