feat: add %%sql --limit and --no-display support - #1883
Conversation
|
@coderfender @martin-g - ptal |
Design note: why not use
|
Why python release build fails ?python/ is a separate Cargo workspace (excluded from the main one) with its own Cargo.lock, and it path-depends on the main ballista crates. But:
So the lock goes stale on main itself every time deps move, and the next contributor inherits a red build. Kindly let me know your thoughts edit: Raised #1887 |
1be2889 to
bf30f29
Compare
| # Default number of rows rendered for a ``%%sql`` cell when ``--limit`` is not | ||
| # given. This caps only the display (via datafusion's HTML formatter); the | ||
| # underlying result keeps all of its rows. | ||
| DEFAULT_DISPLAY_LIMIT = 50 |
There was a problem hiding this comment.
Could we probably push this as a limit option to datafusion ? That might help with probing high volume data
There was a problem hiding this comment.
The --limit is a display cap atm. It only changes how many rows render. It does not reduce compute or collection i.e the full result is still materialized. On datafusion side it seems we already have df.limit(n, offset), df.head(n) which pushes the limit into the plan. I think you mean that setting %%sql --limit x should push it to the execution layer rather than just display side. right ? I can look into that side lmk
There was a problem hiding this comment.
Yeah. I personally think that without that wiring in place , this feature might still OOM and users might not have an idea re the root cause
| limit = None | ||
|
|
||
| i = 0 | ||
| while i < len(tokens): |
There was a problem hiding this comment.
Could be a good practice to store constant ipython flags separately?
There was a problem hiding this comment.
sure makes sense. addressed



Which issue does this PR close?
Closes #.
Rationale for this change
The
%%sqlJupyter cell magic advertises two options in its help text that were never actually implemented:--no-display - Don't display results
--limit N - Limit displayed rows (default: 50)
The argument-parsing loop only extracted a variable name, it scanned all tokens and kept the last non-flag, never breaking, silently dropping any
--flag. So the documented options were ignored. This PR makes the behavior matchthe documented contract, including the
(default: 50)already promised in the help text.What changes are included in this PR?
In
python/python/ballista/jupyter.py:_parse_cell_magic_args(), which parses--limit Nand--no-displayplus the optional variable name, using the same hand-rolledline.split()convention as the other magics in this module (%ballista,%register). Invalid--limitvalues (missing / non-integer / non-positive) return a clear message instead of raising.--limit Ncaps the display to N rows via datafusion'sconfigure_formatter(max_rows=N, min_rows=N). This is display-only — it never truncates the underlying data, so an in-queryLIMITalways takes effect. When--limitis omitted, the display falls back to a default of 50.--no-displayruns the query, stores the result in the variable if one is given, and renders nothing.sql()docstring and the%ballista helptext.Docs: added a short
--limit/--no-displayexample to the "SQL Magic Commands" section ofpython/README.md.Tests in
python/python/tests/test_jupyter.py:--limitrejection).--limit(display cap set, data not truncated), the default cap,--no-display, and the invalid---limiterror path.Are there any user-facing changes?
Yes, the previously documented
--limitand--no-displayoptions on the%%sqlcell magic now work. The README is updated accordingly.The only behavioral change to existing usage: a
%%sqlcell now renders up to 50 rows by default (the value the help text already documented here) instead of datafusion's built-in default of 10. This affects rendered rows only. Query results are never truncated, and in-queryLIMITis unaffected.Note:
--limitis implemented via datafusion's global HTML formatter, so each%%sqlcell re-sets the display cap. The cap also applies to subsequent non-%%sqlDataFrame displays in the same kernel until changed