Commit 96a6096
authored
feat: support reading from stdin in datafusion-cli (#22839)
## Which issue does this PR close?
- Closes #9430.
## Rationale for this change
Users frequently want to pipe data into the CLI, e.g. `cat data.csv |
datafusion-cli`, but pointing `LOCATION` at `/dev/stdin` did not work:
- CSV failed with `Illegal seek` (a pipe is not seekable).
- Parquet failed with `file size of 0 is less than footer` (a pipe
reports size 0).
- JSON silently returned 0 rows.
This PR makes reading from standard input work for CSV, JSON, and
Parquet.
## What changes are included in this PR?
stdin is exposed as a `stdin://` object store, dispatched alongside the
other schemes (`s3`, `gs`, `http`, ...) in `get_object_store` —
conceptually similar to DuckDB's `PipeFileSystem`.
- `rewrite_stdin_location` maps the well-known stdin pseudo-paths
(`/dev/stdin`, `/dev/fd/0`, `/proc/self/fd/0`) to a canonical
`stdin:///stdin.<ext>` URL, so they flow through the normal
object-store/listing code path. The extension matches the declared
`STORED AS` format because the listing layer filters candidate files by
extension.
- The `stdin://` store reads all of standard input into an in-memory
object store. Buffering up front is required because a pipe is not
seekable and Parquet stores its metadata at the end of the file.
Known scope/limitations (left as potential follow-ups):
- Only `CREATE EXTERNAL TABLE` is supported (not dynamic `SELECT * FROM
'/dev/stdin'`).
- Input is fully buffered in memory, so it must fit in memory.
- stdin can only be consumed once per session.
- Unix-only (`/dev/stdin` does not exist on Windows); writing to
`/dev/stdout` is out of scope.
## Are these changes tested?
Yes:
- Unit tests in `object_storage.rs` cover `rewrite_stdin_location` and
end-to-end reads for CSV, JSON, and Parquet via the in-memory store.
- A `#[cfg(unix)]` integration test in `cli_integration.rs` drives the
real binary through an actual pipe, exercising the real stdin read.
- Manually verified all three formats via real pipes, and confirmed
normal local-file reads are unaffected.
## Are there any user-facing changes?
Yes — reading from stdin via `LOCATION '/dev/stdin'` is now supported.
Documented in `docs/source/user-guide/cli/datasources.md` (new "Reading
from standard input" section). No breaking changes.1 parent a0e6d49 commit 96a6096
6 files changed
Lines changed: 659 additions & 4 deletions
File tree
- datafusion-cli
- src
- object_storage
- tests
- docs/source/user-guide/cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
423 | 428 | | |
424 | 429 | | |
425 | 430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
161 | 179 | | |
162 | 180 | | |
163 | 181 | | |
| |||
268 | 286 | | |
269 | 287 | | |
270 | 288 | | |
| 289 | + | |
271 | 290 | | |
272 | 291 | | |
273 | 292 | | |
| |||
285 | 304 | | |
286 | 305 | | |
287 | 306 | | |
288 | | - | |
| 307 | + | |
289 | 308 | | |
290 | 309 | | |
291 | 310 | | |
| |||
330 | 349 | | |
331 | 350 | | |
332 | 351 | | |
333 | | - | |
| 352 | + | |
334 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
335 | 362 | | |
336 | 363 | | |
337 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
564 | 567 | | |
565 | 568 | | |
566 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
567 | 573 | | |
568 | 574 | | |
569 | 575 | | |
| |||
0 commit comments