Skip to content

fix: json output keeps NULL keys and tells NaN from NULL; show() survives a closed stdout (#124, #125) - #150

Merged
vyncint merged 4 commits into
mainfrom
pr/030-compute2
Nov 18, 2026
Merged

vyncint merged 4 commits into
mainfrom
pr/030-compute2

Conversation

@vyncint

@vyncint vyncint commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Two user-facing fixes from the 0.3.0 review, one commit each, with the evidence in each commit body.

  • oxide sql --output json drops the key of every NULL value and writes NaN as null #124 oxide sql --output json dropped the key of every NULL value and wrote NaN as null, so a script could not tell a NULL from a missing column, or NaN from NULL.
    • Every object now carries every column, with a NULL as null.
    • NaN, +inf and -inf are the strings "NaN", "Infinity" and "-Infinity" in Float16/32/64, including inside lists, structs and dictionaries. Finite values still go through arrow-json's own encoder.
    • This changes the output a script reads, so the CHANGELOG lists it under Changed, with a migration line.
  • OxideFrame::show() panics when stdout closes #125 OxideFrame::show() panicked when stdout closed ("failed printing to stdout: Broken pipe"). It now prints the same table through a stdout lock, taken after the last await, and returns Ok on a broken pipe, as oxide sql already exits 0 there (oxide sql: handle EPIPE instead of panicking when stdout closes #34). Any other write error is EngineError::Io. The closed-pipe test has its own test binary, so no sibling fork can hold the pipe open.

A third commit moves #124's CHANGELOG bullet under Changed. It also separates the bullet from the #92 bullet it had been joined to.

Locally on this branch, cargo test -p oxidelake-api -p oxidelake-runtime --lib --test cli --test show_closed_pipe --test dataframe gave 53 passed and 0 failed. The fix agent's full gate (38 test binaries, 173 passed) ran on its own branch.

Closes #124
Closes #125

Signed-off-by: Vyncint Ng 115854244+vyncint@users.noreply.github.com

`oxide sql --output json` wrote through arrow-json's default
ArrayWriter, which leaves the key of a NULL value out of its object and
writes NaN, infinity and negative infinity as `null`. The issue's own
command, on the base:

  $ oxide sql -q "SELECT 1 AS k, CAST(NULL AS DOUBLE) AS v,
                  CAST('NaN' AS DOUBLE) AS n" --output json
  [{"k":1,"n":null}]

so a script could tell neither a NULL from a missing column nor a NaN
from a NULL.

The writer is now built with explicit nulls, so every object carries
every column and a NULL is `null` (a NULL field of a struct keeps its
key too), and with an EncoderFactory, NonFiniteFloats, that writes the
three non-finite values as the strings "NaN", "Infinity" and
"-Infinity", the encoding the issue proposes. Python's float() and
JavaScript's Number() read the three back (checked with python3 and
node). Every finite value goes to arrow-json's own encoder, built from
a factory-less copy of the options, so its formatting does not change.
arrow-json asks the factory for every array it encodes, so Float16, 32
and 64 are covered, and so are the values of lists, structs and
dictionaries.

The WIP this finishes defined the factory but never passed it to the
WriterBuilder, so NaN still came out `null`; it is wired in here.

The `--output` help text, OutputFormat::Json's rustdoc, the README flag
table and the CHANGELOG say what is written.

Tests:
- output.rs: json_is_an_array_of_objects_with_every_column (replaces
  json_is_an_array_of_objects_and_drops_nulls, which pinned `{}` for an
  all-NULL row), json_writes_nan_and_the_infinities_as_strings (Float64,
  Float32, Float16 and FixedSizeList<Float32> columns, NULLs among the
  values) and json_reaches_floats_inside_structs_and_dictionaries.
- cli.rs: json_output_keeps_null_keys_and_tells_nan_from_null runs the
  issue's command against the binary; the_flags_appear_in_help requires
  --help to name null, "NaN", "Infinity" and "-Infinity"; parse_json
  now requires the `k` key in every object, so the cross-format test,
  whose demo table groups NULL keys into a row, fails on a dropped key
  instead of reading it as a NULL.

Before (base ArrayWriter, new tests): the three output.rs tests red,
e.g. `[{"k":1,"name":"a,b"},{}]` and every non-finite value `null`; the
CLI test red with `[{"k":1,"n":null}]`, the issue's output exactly.
After: output.rs 8/8, and the four json, help and format CLI tests,
green.

Guards broken once each, then restored:
- explicit nulls off: the three output.rs tests, the issue's CLI test
  (`[{"k":1,"n":"NaN"}]`) and the cross-format test ("a row without its
  `k` key: {"n":383}") red;
- the --help sentence reverted: the_flags_appear_in_help red;
- the factory not wired (the WIP as found): both float tests red;
- the Float16 arm removed: the Float16 column's non-finite values
  `null`;
- the -Infinity branch removed: the Float64 and Float32 columns and the
  dictionary red;
- the factory's null buffer dropped: NULL floats written as 0.0.

cargo fmt --check, and clippy -p oxidelake-runtime -p oxidelake-api
--all-targets -D warnings: clean.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
OxideFrame::show() was DataFusion's DataFrame::show, which is
`println!("{}", self.to_string().await?)`, and `println!` panics when
stdout is a closed pipe. A program showing a frame into `… | head -1`
died the way `oxide sql` did before #34:

  panicked at library/std/src/io/stdio.rs:1166:9:
  failed printing to stdout: Broken pipe (os error 32)

`show` now calls DataFrame::to_string, the text DataFusion's show
printed (session format options and extension types included), and
writes it and a newline through a locked stdout. BrokenPipe is a clean
stop that returns Ok, as `oxide sql` exits 0 there (write_out in
oxide.rs makes the same match); any other write error is
EngineError::Io. The lock is taken after the last await: a StdoutLock
is not Send, and held across the query it would make the future
unspawnable. The rustdoc says all three, and STATUS.md's matrix row for
OxideFrame and docs/verification.md's test layers list show and the
new test binary.

Tests:
- tests/show_closed_pipe.rs (from the WIP),
  show_into_a_closed_pipe_returns_instead_of_panicking: re-runs itself
  as a child that shows a ~1.3 MB table (generate_series(1, 50000)),
  far more than a 64 KiB pipe buffer, into a pipe whose reader takes
  the first table line and goes; the child must report Ok and exit 0
  with no panic. It has a binary of its own with nothing beside it that
  forks: the other test there, show_is_send, forks nothing.
- tests/dataframe.rs, show_prints_the_table_and_a_newline (new):
  nothing tested what show() prints. The child's stdout must end with
  exactly DataFusion's to_string of the frame and a newline.
  dataframe.rs forked nothing before and has no closed-pipe test, so
  the child this spawns endangers none.

Before (base show, new tests): the closed-pipe test red, the child
panicking with the message above, then libtest failing with "io error
when listing tests: ... BrokenPipe". After: api tests 5 + 2 and the
doctest green.

Guards broken once each, then restored:
- the BrokenPipe arm removed: red, "show returned Err: I/O error:
  Broken pipe (os error 32)", which also shows another write error
  surfaces as EngineError::Io;
- the newline not written: show_prints_the_table_and_a_newline red;
- the lock taken before the await: show_is_send fails to compile
  (E0277, the ReentrantLockGuard is not Send). The library alone still
  compiles, so only the test catches it.
The happy-path test passes on the base too, as it should: it pins the
success path the rewrite had to keep.

Isolation, measured with a throwaway probe (not committed): the same
test beside a sibling that forks while the test holds the read end and
sleeps 2 s before it execs. Fixed: show returned Ok after 2.0 s instead
of 0.06 s. Base: the same panic, 1.8 s after the reader went. A forking
neighbour delays this test and changes neither outcome, because the
table cannot fit the pipe buffer; the module comment said the writer
could "fill the buffer and succeed" and now says what was measured.
Stress: each new test 200 times, 20 at a time, both at once (40
processes): 200/200 green each.

cargo fmt --check, clippy -p oxidelake-api -p oxidelake-runtime
--all-targets -D warnings, and rustdoc -D warnings for both: clean.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
oxide sql --output json now writes NULL keys and NaN/±inf as strings;
a script reading that output sees a different document, so the entry
belongs with the other visible changes. It also separates it from the #92
bullet it had been joined to without a blank line.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
@vyncint vyncint added this to the v0.3.0 milestone Nov 18, 2026
Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@vyncint
vyncint merged commit 726fe6d into main Nov 18, 2026
19 checks passed
@vyncint
vyncint deleted the pr/030-compute2 branch November 18, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OxideFrame::show() panics when stdout closes oxide sql --output json drops the key of every NULL value and writes NaN as null

1 participant