Repository navigation
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #46353 +/- ##
========================================
Coverage 86.08% 86.08%
========================================
Files 3140 3140
Lines 219083 219318 +235
Branches 51921 51976 +55
========================================
+ Hits 188600 188803 +203
- Misses 27055 27072 +17
- Partials 3428 3443 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Engine specs can set supports_arrow_result to fetch query results as a pyarrow.Table when the DB-API cursor exposes an Arrow method; any other cursor returns None and keeps fetch_data. Also adds the ARROW_NATIVE_RESULT_SET feature flag (default off) that callers check before asking for Arrow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build a result set from a pyarrow.Table with the same column names, nested-value handling, uint64 overflow rule and column metadata as the row constructor, with an engine-spec hook for engine-specific types. fetch_arrow_result fetches Arrow only when ARROW_NATIVE_RESULT_SET is on and reports truncation from one extra row. Tests compare both paths down to to_pandas_df(), and pin the two intended dtype differences (int32 width, all-NULL columns). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
duckdb-engine cursors return Arrow natively, so no ADBC driver or new dependency is needed. INTERVAL and HUGEINT/UHUGEINT are converted to what DuckDB's Python fetch returns, and limited reads cap the reader's batch size. A parity test runs the same SQL through both paths on a real DuckDB cursor. The inherited MotherDuck spec opts in too. Off unless ARROW_NATIVE_RESULT_SET is enabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With ARROW_NATIVE_RESULT_SET on and an opted-in engine, SQL Lab and the statement executor fetch Arrow and use SupersetResultSet.from_arrow. One extra row is still requested to detect truncation, as on the row path. With the flag off the existing fetch_data path runs unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chart and dataset queries that go through get_df build their DataFrame via SupersetResultSet.from_arrow when ARROW_NATIVE_RESULT_SET is on and the engine returns Arrow. The DataFrame, cache and response format are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96d47ca to
2d09484
Compare
|
I replaced the branch with a reworked version:
I updated the description to match. Local checks: unit tests, the |
| table = table_method() | ||
| if limit is not None: | ||
| return table.slice(0, limit) |
There was a problem hiding this comment.
Looks like the rework lost the fix from codeant's thread, where a limited read with only to_arrow_table/fetch_arrow_table returned None so fetchmany could apply the limit. test_fetch_arrow_limits_a_table pins the materialize-then-slice version now. Was that intentional? DuckDB doesn't hit it, but the next engine to opt in without a streaming reader would.
There was a problem hiding this comment.
Good catch, not intentional. Fixed in aoelvp94@e7fa6fa: with a limit and only a table fetch method, fetch_arrow now returns None so the caller uses fetchmany. The tests cover that case now.
Co-authored-by: Evan Rusackas <evan@preset.io>
to_arrow_table/fetch_arrow_table materialize the whole result, so a limited read returns None and the caller uses fetchmany. Restore the behavior the rework dropped.
The rework sent arrow.json, arrow.uuid and opaque NUMERIC through stringify_extension_columns, a Python loop over to_pylist(). That made from_arrow about 9x slower on Postgres and left JSON as text in to_pandas_df. Restore the previous handling: JSON text stays in the table until to_pandas_df or nested_columns, UUIDs are stringified with a vectorized conversion, and NUMERIC becomes a decimal.
Arrow's string-to-decimal cast does not reject values that overflow the target precision: an 80-digit NUMERIC came back as a different number with the wrong sign. Count the integer and fraction digits first, pick decimal128 or decimal256 only when the value fits, and keep the exact text otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SUMMARY
I designed this change and drove it end to end: the scope comes from SIP #46289 and my demo repo, and I reviewed every commit, ran the tests, and checked the parity cases myself, including a local run of SQL Lab with the flag on and off. I used an AI coding assistant (Claude Code) to draft code, tests and this description under my direction. Here's the AI summary of the changes, I reviewed this and agree with it:
This is the Phase 2 (ingest) part of SIP #46289. It adds an opt-in path that builds
SupersetResultSetfrom apyarrow.Tableinstead of Python rows. The existingfetchallrow path stays the default and the fallback. DuckDB is the only engine that opts in here.SupersetResultSet.from_arrow(table, db_engine_spec, *, truncated=False)accepts a Table from any producer. It does not fetch anything and does not require ADBC. It normalizes like the row constructor: deduplicated column names, decoded dictionary columns, nested values stringified as JSON (and kept innested_columns), JSON extension columns kept as text untilto_pandas_dfornested_columnsparses them, UUID stringified, opaque NUMERIC read asDecimal, other extension types stringified, and uint64 columns stringified when a value exceeds 2**63 - 1. Engine specs can adjust a column through a newnormalize_arrow_column(field, column)hook, and vendor<VENDOR>:typefield metadata is used for type names.ARROW_NATIVE_RESULT_SET(defaultFalse) is the global rollback. New engine-spec attributesupports_arrow_result(defaultFalse) is the per-engine opt-in.BaseEngineSpec.fetch_arrow(cursor, limit)reads fromto_arrow_reader,fetch_record_batch,to_arrow_tableorfetch_arrow_table, and stops reading a stream oncelimitrows are in. When a limit is set and the cursor can only fetch a full table, it returnsNoneso the caller usesfetchmany.fetch_arrow_result(db_engine_spec, cursor, limit)insuperset/result_set.pyis the single entry point. It checks the flag, fetcheslimit + 1rows, and reports whether the result was truncated. Without the flag, an opt-in, or an Arrow-capable cursor, it returns(None, False)without touching the cursor.Database.get_df(charts and datasets), SQL Lab execution (sql_lab._read_sqllab_payload), and the statement executor (_fetch_result_set) call it first and fall back tofetch_data.limiting_factorand truncation behave as before. The executor checks the query deadline after fetching and before building the result set, as the row path does.decimal128(38, 0), become int64, or strings when a value does not fit.Out of scope: the
/api/v1/chart/dataArrow wire format and frontend shim (Phase 1, #45363), Postgres/ADBC (a later PR), a generic Flight SQL engine spec, and any new required dependency.Known, intentional differences from the row path, pinned in tests: an all-NULL column keeps its declared Arrow type,
int32keeps its width, and DuckDBDECIMAL(38, 0)reads as an integer because it has the same Arrow type as HUGEINT.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A, backend only. With the flag off nothing changes. With it on, SQL Lab and chart results are identical to the row path.
Ingest-path benchmark from the SIP, on apache/superset master
f81191d, 1M rows, median of 3 rounds, total time through Arrow IPC: DuckDB 0.22s withfrom_arrowvs 5.83s on the row path (26.8×).Re-run on this branch at
149303a, 100k rows, median of 3 rounds, total time throughwrite_ipc_buffer(Linux VM, Intel Xeon). DuckDB is the only engine opted in on this PR; the Postgres and Flight SQL Arrow figures use ADBC +from_arrowin the same harness:from_arrowHarness and data: https://github.com/aoelvp94/superset-adbc-arrow-demo (see the reproduction comment on #46289).
TESTING INSTRUCTIONS
ARROW_NATIVE_RESULT_SEToff): charts and SQL Lab behave as today.FEATURE_FLAGS = {"ARROW_NATIVE_RESULT_SET": True}. DuckDB connections also needPREVENT_UNSAFE_DB_CONNECTIONS = False. Add a DuckDB database (duckdb:///:memory:).The results, column types and row count are the same both times.
ivshows as30 days 03:00:00, and the firstbigvalue keeps all 39 digits.4. Unit tests:
ADDITIONAL INFORMATION
ARROW_NATIVE_RESULT_SET(defaultFalse)hold:sip: This PR is the Phase 2 reference implementation for SIP #46289 and should not be merged until the SIP vote passes. Could a committer add the
hold:siplabel? It does not duplicate #45363, which stays the Phase 1 chart-data work.🤖 Generated with Claude Code