Skip to content

fix(cubesql): Handle array-typed columns in streaming SQL mode - #11149

Merged
MazterQyou merged 1 commit into
masterfrom
cubesql/streaming-mode-array-fix
Jun 24, 2026
Merged

MazterQyou merged 1 commit into
masterfrom
cubesql/streaming-mode-array-fix

Conversation

@MazterQyou

Copy link
Copy Markdown
Member

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made

This PR fixes handling array-typed columns in streaming mode. Related test is included.

This behavior is not documented and unsupported, so it should not be relied upon. The fix is being landed to bring streaming and non-streaming modes in line.

Signed-off-by: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com>
@MazterQyou
MazterQyou requested review from a team as code owners June 23, 2026 18:16
@github-actions github-actions Bot added driver:postgres Issues relating to the Postgres driver rust Pull requests that update Rust code javascript Pull requests that update Javascript code data source driver labels Jun 23, 2026
@claude

claude Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MazterQyou's task in 1m 34s —— View job


Claude PR Review

Reviewed the four-file change. Overall this is a focused, well-scoped fix that brings streaming-mode behavior in line with the non-streaming path (both now JSON-stringify non-scalar values) and is backed by a unit test in scan.rs plus an integration test in the Postgres driver.

Verdict: LGTM — 0 high, 1 medium, 2 low.

Details

Findings

Medium — PostgresDriver.ts may have silently fixed a latent enum-mapping bug

In packages/cubejs-postgres-driver/src/PostgresDriver.ts:304-316, adding AS typname aliases the CASE expression so current.typname is now populated. Before this change the result column for the CASE branch had no explicit name, so depending on driver behavior current.typname was likely undefined for every row — meaning the existing enum (typcategory = 'E') mapping to varchar may not have been working at all, and userDefinedTypes was being populated with { [oid]: undefined }. Worth confirming and calling out in the PR description, since this silently fixes more than just arrays.

Low — stream.rs: JsObject branch is a broad catch-all

packages/cubejs-backend-native/src/stream.rs:322-326 will JSON.stringify any JsObject not already matched. The branch ordering (after JsDate) is correct so dates still error rather than serializing, but Buffers / typed arrays / Maps will silently produce {"type":"Buffer",...} / {} / {} rather than a clear error. For the documented streaming-mode use case this is fine, but a brief comment noting the intent ("treat any unknown object as JSON for parity with the non-streaming path") would help the next reader.

Low — stream.rs: js_value_to_json_string re-resolves JSON.stringify on every call

packages/cubejs-backend-native/src/stream.rs:264-283 looks up JSON and JSON.stringify on the global for every array/object cell. For chunks with many array columns this is a non-trivial overhead. Caching the JsFunction handle (e.g. on JsValueObject or a per-chunk scope) would avoid the repeated global lookups. Not a blocker; mention in case throughput matters here.

Notes / Praise

  • Replacing the .unwrap() at the old transform_response call site with a proper throw_error (stream.rs:349-353) is a nice correctness improvement on its own — previously a malformed chunk would crash the Node process.
  • The scan.rs unit test (convert_transport_response_serializes_non_scalar_values_to_json_strings) is well-targeted: covers both array and object shapes, plus the null case.
  • Postgres integration test exercises both text[] and int[] — good coverage of the array category.
  • Conventional commit message and CHANGELOG-friendly description.
• [branch](https://github.com/cube-js/cube/tree/cubesql/streaming-mode-array-fix)

@codecov

codecov Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.20%. Comparing base (e317395) to head (a04208e).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
rust/cubesql/cubesql/src/compile/engine/df/scan.rs 95.45% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11149      +/-   ##
==========================================
- Coverage   83.68%   79.20%   -4.49%     
==========================================
  Files         257      474     +217     
  Lines       79384    96934   +17550     
  Branches        0     3563    +3563     
==========================================
+ Hits        66434    76774   +10340     
- Misses      12950    19642    +6692     
- Partials        0      518     +518     
Flag Coverage Δ
cube-backend 58.80% <ø> (?)
cubesql 83.69% <95.45%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MazterQyou
MazterQyou merged commit 56ba7c6 into master Jun 24, 2026
166 of 169 checks passed
@MazterQyou
MazterQyou deleted the cubesql/streaming-mode-array-fix branch June 24, 2026 13:59
ovr added a commit that referenced this pull request Aug 18, 2026
…11586)

`loadUserDefinedTypes` built its oid -> typname map with a reduce that
spread the accumulator on every row, copying the whole map n times. That
is quadratic and fully synchronous, so it blocks the event loop.

This went unnoticed while the query only selected `typcategory in ('U', 'E')`
(~20 rows on a stock Postgres). #11149 added `'A'` so that array-typed
columns get mapped, and Postgres auto-creates an array type for every
relation — the row count now scales with the number of tables in the
database, not with the number of actual user defined types.

Measured on postgres:16, `SELECT count(*) FROM pg_type WHERE typcategory
in ('U', 'E', 'A')`:

| tables in database | rows | spread reduce | in-place loop |
| ------------------ | ---- | ------------- | ------------- |
| 0                  |  313 |        6.3 ms |       0.12 ms |
| 5000               | 5313 |       2355 ms |       0.45 ms |
| ~20000             |   -  |      35116 ms |       1.10 ms |
ovr added a commit that referenced this pull request Aug 18, 2026
…fined types

#11149 needed array-typed columns to map to `text`, and selected all of
`typcategory = 'A'` to get there. Postgres creates a row type and an array
over it for every relation, so that selects one row per relation in the
database: the map stopped scaling with the types in use and started scaling
with the size of the catalog. On a multi tenant deployment with a schema per
tenant this reached ~63k rows, and the map build behind it is quadratic.

Those relation array types are only ever the type of a column for queries
that aggregate whole rows, which this driver does not issue, and a plain
composite column is already unsupported since `typcategory = 'C'` has never
been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept,
they are real user defined types.

Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations:

| query                | rows |
| -------------------- | ---- |
| typcategory in UEA   | 3317 |
| this one             |  108 |

The oids #11149 relies on are unaffected: `_text` 1009 and `_int4` 1007 are
still loaded, as are enums, enum arrays and extension types such as hll.
CrateDB, which inherits this through CrateDriver, returns the same 24 rows
for both queries and supports the correlated NOT EXISTS.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ovr added a commit that referenced this pull request Aug 18, 2026
…fined types

#11149 needed array-typed columns to map to `text`, and selected all of
`typcategory = 'A'` to get there. Postgres creates a row type and an array
over it for every relation, so that selects one row per relation in the
database: the map stopped scaling with the types in use and started scaling
with the size of the catalog. On a multi tenant deployment with a schema per
tenant this reached ~63k rows, and the map build behind it is quadratic.

Those relation array types are only ever the type of a column for queries
that aggregate whole rows, which this driver does not issue, and a plain
composite column is already unsupported since `typcategory = 'C'` has never
been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept,
they are real user defined types.

Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations:

| query                | rows |
| -------------------- | ---- |
| typcategory in UEA   | 3317 |
| this one             |  108 |

The oids #11149 relies on are unaffected: `_text` 1009 and `_int4` 1007 are
still loaded, as are enums, enum arrays and extension types such as hll.
CrateDB, which inherits this through CrateDriver, returns the same 24 rows
for both queries and supports the correlated NOT EXISTS.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ovr added a commit that referenced this pull request Aug 18, 2026
…fined types

#11149 needed array-typed columns to map to `text`, and selected all of
`typcategory = 'A'` to get there. Postgres creates a row type and an array
over it for every relation, so that selects one row per relation in the
database: the map stopped scaling with the types in use and started scaling
with the size of the catalog. On a multi tenant deployment with a schema per
tenant this reached ~63k rows, and the map build behind it is quadratic.

Those relation array types are only ever the type of a column for queries
that aggregate whole rows, which this driver does not issue, and a plain
composite column is already unsupported since `typcategory = 'C'` has never
been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept,
they are real user defined types.

Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations:

| query                | rows |
| -------------------- | ---- |
| typcategory in UEA   | 3317 |
| this one             |  108 |

The oids #11149 relies on are unaffected: `_text` 1009 and `_int4` 1007 are
still loaded, as are enums, enum arrays and extension types such as hll.
CrateDB, which inherits this through CrateDriver, returns the same 24 rows
for both queries and supports the correlated NOT EXISTS.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ovr added a commit that referenced this pull request Aug 18, 2026
…fined types (#11587)

#11149 needed array-typed columns to map to `text`, and selected all of
`typcategory = 'A'` to get there. Postgres creates a row type and an array
over it for every relation, so that selects one row per relation in the
database: the map stopped scaling with the types in use and started scaling
with the size of the catalog.

Those relation array types are only ever the type of a column for queries
that aggregate whole rows, which this driver does not issue, and a plain
composite column is already unsupported since `typcategory = 'C'` has never
been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept,
they are real user defined types.

Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations:

| query                | rows |
| -------------------- | ---- |
| typcategory in UEA   | 3317 |
| this one             |  108 |
ovr added a commit that referenced this pull request Aug 18, 2026
…11586)

`loadUserDefinedTypes` built its oid -> typname map with a reduce that
spread the accumulator on every row, copying the whole map n times. That
is quadratic and fully synchronous, so it blocks the event loop.

This went unnoticed while the query only selected `typcategory in ('U', 'E')`
(~20 rows on a stock Postgres). #11149 added `'A'` so that array-typed
columns get mapped, and Postgres auto-creates an array type for every
relation — the row count now scales with the number of tables in the
database, not with the number of actual user defined types.

Measured on postgres:16, `SELECT count(*) FROM pg_type WHERE typcategory
in ('U', 'E', 'A')`:

| tables in database | rows | spread reduce | in-place loop |
| ------------------ | ---- | ------------- | ------------- |
| 0                  |  313 |        6.3 ms |       0.12 ms |
| 5000               | 5313 |       2355 ms |       0.45 ms |
| ~20000             |   -  |      35116 ms |       1.10 ms |
ovr added a commit that referenced this pull request Aug 18, 2026
…fined types (#11587)

#11149 needed array-typed columns to map to `text`, and selected all of
`typcategory = 'A'` to get there. Postgres creates a row type and an array
over it for every relation, so that selects one row per relation in the
database: the map stopped scaling with the types in use and started scaling
with the size of the catalog.

Those relation array types are only ever the type of a column for queries
that aggregate whole rows, which this driver does not issue, and a plain
composite column is already unsupported since `typcategory = 'C'` has never
been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept,
they are real user defined types.

Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations:

| query                | rows |
| -------------------- | ---- |
| typcategory in UEA   | 3317 |
| this one             |  108 |

This branch was successfully deployed

1 active deployment
Preview — a04208ed Deployed Jun 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data source driver driver:postgres Issues relating to the Postgres driver javascript Pull requests that update Javascript code rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy