Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ versions (0.x) may contain breaking changes; they are always listed under a
come back in build order, as the CPU reference returns them. Not yet run
on a GPU (STATUS.md).

- **`oxide sql --output json` keeps the key of a NULL and tells NaN from
NULL** (#124). Every object now carries every column, a NULL as `null`;
the key used to be left out, so a script could not tell a NULL from a
column that does not exist. NaN, infinity and negative infinity, which
JSON has no number for, are the strings `"NaN"`, `"Infinity"` and
`"-Infinity"` in every float type, inside lists, structs and
dictionaries too; all three used to be written `null`, like a NULL. A
script that took a missing key for NULL reads `null` instead, and one
that reads a float column accepts the three strings, which Python's
`float()` and JavaScript's `Number()` read back. `--help` and the README
say so.

### Fixed

- **A LIMIT over a GPU-placed filter or join returns its row count again**
Expand Down Expand Up @@ -426,6 +438,15 @@ versions (0.x) may contain breaking changes; they are always listed under a
`build_description()` are public, and `make test-mixed-build` runs both
cases with real binaries.


- **`OxideFrame::show()` no longer panics when stdout closes** (#125). It
was DataFusion's `DataFrame::show`, whose `println!` panics on a closed
pipe, so a program showing a frame into `… | head -1` died with `failed
printing to stdout: Broken pipe`: the crash #34 fixed in `oxide sql` and
left in the library. `show` now writes the same table itself, and a
reader that has gone is a clean stop that returns `Ok`, as `oxide sql`
exits 0 there; any other write failure is an `EngineError::Io`.

### Fixed

- **A crates.io error can no longer switch the release's semver check off.**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ error, never a silent fallback.
| `--cluster` | `sql` | — | Runs on a Ballista scheduler (`df://host:port`) instead of in-process. |
| `--target` | `sql`, `explain`, `tui` | detected | Plans for `cpu`, `cuda` or `metal`. Placement only: execution uses the hardware that is present. Embedded mode only — on a cluster the scheduler decides. |
| `--batch-size` | `sql`, `explain`, `tui` | 8192, or 65536 on a GPU target | Rows per record batch. Batch boundaries never change results; larger batches amortise the host↔device round trip. `0` is refused. With `--cluster` the GPU default is the scheduler's call (its target), and a size given here is kept. |
| `--output` | `sql` | `table` | `table`, `json` (an array of objects) or `csv` (RFC 4180 with a header). An empty result still prints the CSV header and `[]`, so a script can tell "no rows" from "the query failed". |
| `--output` | `sql` | `table` | `table`, `json` (an array of objects, one per row, each carrying every column) or `csv` (RFC 4180 with a header). In `json` a NULL is `null`, and NaN, infinity and negative infinity, which JSON has no number for, are the strings `"NaN"`, `"Infinity"` and `"-Infinity"`, which Python's `float()` and JavaScript's `Number()` read back. An empty result still prints the CSV header and `[]`, so a script can tell "no rows" from "the query failed". |
| `--rows` | `gen-data` | `1000000` | Rows in the demo table. |
| `--out` | `gen-data` | — | Output directory; writes `<out>/t.parquet`. |
| `--seed` | `gen-data` | `42` | PRNG seed. The same seed always writes the same bytes. |
Expand Down
2 changes: 1 addition & 1 deletion STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Filled in as phases complete. Every component goes under exactly one column —
| `oxide gen-data` (deterministic SplitMix64 dataset, Bloom filters on `id`/`k`) | datagen unit tests + CLI e2e with independent `parquet`-crate verification | | |
| `oxide sql` / `oxide explain --target` / spawned-cluster `--cluster` equality | `oxidelake-runtime/tests/cli.rs` (assert_cmd, real `oxide-scheduler` + `oxide-worker` processes) | | |
| Embedded cpu/cuda/metal target equivalence (incl. the vector query) | `oxidelake-runtime/tests/embedded.rs`; **(macOS)** the metal target actually executes on the device; **(T4)** the cuda target actually executes on the device — this test is what caught the aggregation kernel bug (failed 8 of 8 runs before the fix, 8 of 8 green after); the README quickstart (`gen-data` 1M rows → `explain`/`sql --target cuda`) plans `GpuFilterExec[cuda]` + `GpuAggregateExec[cuda]` and returns the same 98 group rows as `--target cpu` | | |
| `OxideFrame` DataFrame API (filter/select/join/aggregate/vector_distance/explain/collect) | `oxidelake-api/tests/dataframe.rs` vs SQL equivalents | | |
| `OxideFrame` DataFrame API (filter/select/join/aggregate/vector_distance/explain/collect/show) | `oxidelake-api/tests/dataframe.rs` vs SQL equivalents; `show` run in a child process, whole and into a closed pipe (`tests/show_closed_pipe.rs`, #125) | | |
| `oxide tui` (query dashboard: plan DAG + live telemetry + column profiles) | dashboard unit test (plan tags, real counters, profiles); driven end to end in a sized PTY (demo + `--query --target metal`), `q` exits 0 | | |

## Resolved dependency set
Expand Down
24 changes: 22 additions & 2 deletions crates/oxidelake-api/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! `SELECT *, l2_distance(emb, …) AS d` and lowers to `GpuVectorDistanceExec`
//! on a GPU target.

use std::io::Write;
use std::sync::Arc;

use datafusion::arrow::array::RecordBatch;
Expand Down Expand Up @@ -127,9 +128,28 @@ impl OxideFrame {
Ok(self.inner.collect().await?)
}

/// Executes the frame and prints it as a table.
/// Executes the frame and prints it on stdout as a table, formatted as
/// DataFusion's `DataFrame::show` formats it.
///
/// A reader that goes away before the table is written, as `… | head -1`
/// does once it has its line, is a clean stop: `show` returns `Ok`, as
/// `oxide sql` exits 0 there (#34). Any other write failure is
/// [`EngineError::Io`].
pub async fn show(self) -> Result<(), EngineError> {
Ok(self.inner.show().await?)
// Not `DataFrame::show`: its `println!` panics on a closed pipe
// (#125). `to_string` is what it prints, so the text is the same.
let table = self.inner.to_string().await?;
// Locked after the last await: a `StdoutLock` is not `Send`, and
// holding one across an await would make this future unspawnable.
let mut stdout = std::io::stdout().lock();
match stdout
.write_all(table.as_bytes())
.and_then(|()| stdout.write_all(b"\n"))
.and_then(|()| stdout.flush())
{
Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()),
other => other.map_err(EngineError::from),
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions crates/oxidelake-api/tests/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,44 @@ async fn read_parquet_and_explain_show_placement() {
let rows = frame.collect().await.unwrap();
assert!(rows.iter().map(RecordBatch::num_rows).sum::<usize>() > 0);
}

/// `show` prints the table DataFusion's `DataFrame::show` printed, then a
/// newline, and nothing else (#125 replaced its `println!`). It writes to
/// the process's stdout, so the check runs it in a child, this test again,
/// with stdout piped. The closed-pipe case is `tests/show_closed_pipe.rs`.
#[tokio::test]
async fn show_prints_the_table_and_a_newline() {
const CHILD: &str = "OXIDELAKE_TEST_SHOW_TABLE_CHILD";
const NAME: &str = "show_prints_the_table_and_a_newline";
const QUERY: &str = "SELECT 1 AS a, CAST(NULL AS VARCHAR) AS b";
let session = OxideSession::local().unwrap();
if std::env::var_os(CHILD).is_some() {
let shown = session.sql_frame(QUERY).await.unwrap().show().await;
// Out before the harness prints its result line after the table.
std::process::exit(if shown.is_ok() { 0 } else { 3 });
}
let table = session
.sql_frame(QUERY)
.await
.unwrap()
.into_inner()
.to_string()
.await
.unwrap();
assert!(table.contains("| 1 |"), "{table}");

// `--nocapture`, so a `print!`-based `show` reaches the pipe too.
let out = std::process::Command::new(std::env::current_exe().unwrap())
.args([NAME, "--exact", "--nocapture", "--quiet"])
.env(CHILD, "1")
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&out.stderr);
assert_eq!(out.status.code(), Some(0), "{stderr}");
// The harness's "running 1 test" line, then exactly the table.
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
stdout.ends_with(&format!("\n{table}\n")),
"expected the table then a newline:\n{table}\ngot:\n{stdout}"
);
}
104 changes: 104 additions & 0 deletions crates/oxidelake-api/tests/show_closed_pipe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//! `OxideFrame::show()` into a reader that goes away (#125).
//!
//! `… | head -1` is the most ordinary thing a shell does to a program that
//! prints a table, and `show()` used to panic on it: it was DataFusion's
//! `DataFrame::show`, whose `println!` panics when stdout is a closed pipe —
//! the crash #34 fixed in the `oxide` binary and left in the library.
//!
//! This is its own test binary, with nothing beside it that forks. A process
//! that another test forks while this one holds the pipe's read end keeps a
//! copy until it execs, and no write fails with `EPIPE` while a reader is
//! left. With a table this size that only delays the result (a sibling that
//! held the read end for 2 s delayed the panic, and the fix's clean stop, by
//! 2 s), but a closed-pipe test should not depend on its neighbours' timing.

#![allow(clippy::unwrap_used, clippy::expect_used)]

use std::io::{BufRead, BufReader};
use std::process::{Command, Stdio};

use oxidelake_api::prelude::*;

/// Set in the child the test spawns: the process whose stdout is closed.
const CHILD: &str = "OXIDELAKE_TEST_SHOW_CHILD";
const NAME: &str = "show_into_a_closed_pipe_returns_instead_of_panicking";

/// Prints a table far larger than a pipe buffer, says on stderr what `show`
/// returned, and exits with that answer before the test harness can print
/// anything more into the closed pipe.
async fn child() {
let session = OxideSession::local().unwrap();
// About 1.3 MB of table: a pipe buffer holds 64 KiB, so `show` is still
// writing when the reader goes.
let frame = session
.sql_frame("SELECT value AS id, value * 3 AS k FROM generate_series(1, 50000)")
.await
.unwrap();
match frame.show().await {
Ok(()) => {
eprintln!("show returned Ok");
std::process::exit(0);
}
Err(e) => {
eprintln!("show returned Err: {e}");
std::process::exit(3);
}
}
}

/// The reader takes the table's first line and goes, as `head -1` does; the
/// writer must stop cleanly, with `Ok`, as `oxide sql` does (#34).
#[tokio::test]
async fn show_into_a_closed_pipe_returns_instead_of_panicking() {
if std::env::var_os(CHILD).is_some() {
child().await;
return;
}
// `--nocapture`, or the harness would capture the old `println!` into a
// buffer and the closed pipe would never be written to; `--quiet`, so the
// harness prints nothing between its first line and the table.
let mut child = Command::new(std::env::current_exe().unwrap())
.args([NAME, "--exact", "--nocapture", "--quiet"])
.env(CHILD, "1")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();

let mut stdout = BufReader::new(child.stdout.take().unwrap());
let mut line = String::new();
let mut saw_table = false;
while stdout.read_line(&mut line).unwrap() > 0 {
if line.starts_with("+-") {
saw_table = true;
break;
}
line.clear();
}
drop(stdout);

let out = child.wait_with_output().unwrap();
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(saw_table, "the child printed no table:\n{stderr}");
assert!(
!stderr.contains("panicked"),
"a closed pipe is not a crash:\n{stderr}"
);
assert!(
stderr.contains("show returned Ok"),
"a reader that goes away is a clean stop:\n{stderr}"
);
assert_eq!(out.status.code(), Some(0), "{stderr}");
}

/// `show` stays spawnable. The stdout lock it writes through is not `Send`,
/// so it is taken after the query's last await; held across the query, it
/// would stop every `tokio::spawn(frame.show())` from compiling. No process
/// is forked here, so this shares the binary safely.
#[test]
fn show_is_send() {
fn spawnable<F: std::future::Future + Send>(_: F) {}
let session = OxideSession::local().unwrap();
let frame = OxideFrame::new(session.ctx().read_empty().unwrap());
spawnable(frame.show());
}
5 changes: 4 additions & 1 deletion crates/oxidelake-runtime/src/bin/oxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ enum Command {
/// GPU-target default (65536). Batch boundaries never change results.
#[arg(long, value_name = "ROWS")]
batch_size: Option<usize>,
/// How to print the result: table, json or csv.
/// How to print the result: table, json or csv. In json every object
/// carries every column, a NULL as `null`, and NaN, infinity and
/// negative infinity, which JSON has no number for, as the strings
/// "NaN", "Infinity" and "-Infinity".
#[arg(long, value_name = "FORMAT", default_value = "table")]
output: OutputFormat,
},
Expand Down
Loading
Loading