Skip to content

json: Add option flatten_top_level_arrays to TapeDecoder - #9496

Merged
Jefffrey merged 5 commits into
apache:mainfrom
Rafferty97:json-array
Aug 22, 2026
Merged

Jefffrey merged 5 commits into
apache:mainfrom
Rafferty97:json-array

Conversation

@Rafferty97

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

N/A

Rationale for this change

There are JSON files in the wild that are structured as a single array at the root level, i.e. [{...}, {....}, {...}]. At present, this would be read by the tape decoder as one single array-valued record, but since each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the TapeDecoder to support these kinds of JSON files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase, but it currently employs a streaming converter to transform "top-level array" JSON sources into ND-JSON. If this PR is merged, this would facilitate the refactoring of this feature to use the TapeDecoder directly, which should noticably improve performance. See apache/datafusion#19920 for context.

What changes are included in this PR?

This PR modestly refactors the TapeDecoder to facilitate this use case, by adding an option called flatten_top_level_arrays. When enabled, any top-level arrays are "flattened" such that their elements each become an individual row in the output batch, rather than the entire array becoming a single row as would otherwise happen.

Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new unit test for this feature specifically.

Are there any user-facing changes?

The primary change is the addition of a new_with_options method on TapeDecoder, that allows the user to specify a value for the new configuration option. I figured a config struct was more future-proof, and we may want to mark it as #[non_exhaustive] but that's debatable.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Mar 2, 2026

@scovich scovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The row handling logic seems really redundant between normal and flattened-array modes... trying to figure out if there's a better way to express it?

Also -- what would be the intended semantics of flattened-array parsing a json file containing multiple arrays?

[{"a": 1}, {"a": 2}]
[{"a": 3}, {"a": 4}]

(I think the current code would produce four rows of output, but is that correct if the file is "supposed" to contain only one large array?)

Comment thread arrow-json/src/reader/mod.rs Resolved
@Rafferty97

Copy link
Copy Markdown
Contributor Author

The row handling logic seems really redundant between normal and flattened-array modes... trying to figure out if there's a better way to express it?

Also -- what would be the intended semantics of flattened-array parsing a json file containing multiple arrays?

[{"a": 1}, {"a": 2}]
[{"a": 3}, {"a": 4}]

(I think the current code would produce four rows of output, but is that correct if the file is "supposed" to contain only one large array?)

There's a little bit of code duplication but I think it's quite manageable and warranted.

The intended semantics for that example would be to produce 4 rows, whereas the current code would either error out because the top-level items aren't objects, or return two arrays if it's in "is_field" mode via the ReaderBuilder::new_as_field method.

@Rafferty97

Copy link
Copy Markdown
Contributor Author

Hi @scovich, I was wondering if you would mind reviewing this one again?

@Jefffrey
Jefffrey requested a review from scovich July 29, 2026 04:05
@github-actions github-actions Bot added the arrow-json arrow-json crate label Jul 31, 2026
@Rafferty97

Copy link
Copy Markdown
Contributor Author

Hi @alamb, I was wondering if you wouldn't mind looking at this PR as well, which has been open for a while? I think the changes are pretty modest and purely additive, so hopefully this one's easier to review. :)

@Jefffrey Jefffrey added the enhancement New feature/addition label Aug 9, 2026
@Jefffrey

Jefffrey commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

run benchmark json_reader

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing json-array (21fc186) to 7eeb3eb (merge-base) diff

Run configuration
run benchmark json_reader
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                        json-array                             main
-----                                        ----------                             ----
decode_binary_hex_json                       1.00     13.9±0.04ms        ? ?/sec    1.00     13.9±0.04ms        ? ?/sec
decode_binary_view_hex_json                  1.02     14.4±0.04ms        ? ?/sec    1.00     14.2±0.04ms        ? ?/sec
decode_fixed_binary_hex_json                 1.02     14.1±0.03ms        ? ?/sec    1.00     13.9±0.04ms        ? ?/sec
decode_list_long_json/131072                 1.00    285.9±1.23ms   273.8 MB/sec    1.06    302.3±0.87ms   259.0 MB/sec
decode_list_long_serialize                   1.00    181.4±0.83ms        ? ?/sec    1.12    203.7±0.96ms        ? ?/sec
decode_list_short_json/131072                1.00     18.8±0.27ms   278.3 MB/sec    1.05     19.7±0.05ms   265.6 MB/sec
decode_list_short_serialize                  1.00     11.3±0.09ms        ? ?/sec    1.05     11.8±0.12ms        ? ?/sec
decode_list_view_long_json/131072            1.00    285.3±0.96ms   274.4 MB/sec    1.06    302.9±1.02ms   258.5 MB/sec
decode_list_view_long_serialize              1.00    182.3±0.87ms        ? ?/sec    1.12    204.1±1.07ms        ? ?/sec
decode_list_view_short_json/131072           1.00     19.5±0.32ms   268.3 MB/sec    1.03     20.0±0.05ms   261.5 MB/sec
decode_list_view_short_serialize             1.00     11.5±0.10ms        ? ?/sec    1.06     12.2±0.13ms        ? ?/sec
decode_map_large_json/131072                 1.00    255.3±0.64ms   297.5 MB/sec    1.00    254.5±0.69ms   298.5 MB/sec
decode_map_large_serialize                   1.02    289.0±3.06ms        ? ?/sec    1.00    283.6±1.98ms        ? ?/sec
decode_map_small_json/131072                 1.00     29.6±0.12ms   277.6 MB/sec    1.00     29.7±0.21ms   276.8 MB/sec
decode_map_small_serialize                   1.02     20.7±0.23ms        ? ?/sec    1.00     20.3±0.19ms        ? ?/sec
decode_ree_long_json/131072                  1.00      5.9±0.13ms   258.5 MB/sec    1.00      5.9±0.01ms   259.4 MB/sec
decode_ree_long_serialize                    1.00      4.3±0.05ms        ? ?/sec    1.03      4.5±0.09ms        ? ?/sec
decode_ree_short_json/131072                 1.00      6.3±0.01ms   273.8 MB/sec    1.01      6.4±0.01ms   270.0 MB/sec
decode_ree_short_serialize                   1.00      4.7±0.05ms        ? ?/sec    1.03      4.8±0.08ms        ? ?/sec
decode_wide_object_json/131072               1.01    465.2±4.99ms   206.9 MB/sec    1.00    461.6±4.97ms   208.5 MB/sec
decode_wide_object_serialize                 1.00    431.6±6.85ms        ? ?/sec    1.00    433.6±7.78ms        ? ?/sec
decode_wide_projection_full_json/131072      1.02    772.9±6.57ms   225.1 MB/sec    1.00   759.4±10.11ms   229.1 MB/sec
decode_wide_projection_narrow_json/131072    1.00    434.7±2.04ms   400.2 MB/sec    1.00    433.6±0.79ms   401.3 MB/sec
infer_json_schema/1000                       1.00   1519.6±7.85µs    83.1 MB/sec    1.01  1531.4±17.53µs    82.4 MB/sec
large_bench_primitive                        1.02   1493.7±1.62µs        ? ?/sec    1.00   1462.9±1.92µs        ? ?/sec
small_bench_list                             1.00      6.5±0.02µs        ? ?/sec    1.03      6.7±0.01µs        ? ?/sec
small_bench_primitive                        1.00      3.9±0.01µs        ? ?/sec    1.02      4.0±0.01µs        ? ?/sec
small_bench_primitive_with_utf8view          1.00      3.9±0.02µs        ? ?/sec    1.00      3.9±0.02µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 450.1s
Peak memory 1.4 GiB
Avg memory 925.9 MiB
CPU user 408.1s
CPU sys 37.2s
Peak spill 0 B

branch

Metric Value
Wall time 455.1s
Peak memory 1.4 GiB
Avg memory 919.8 MiB
CPU user 411.6s
CPU sys 35.9s
Peak spill 0 B

File an issue against this benchmark runner

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark json_reader

@Jefffrey Jefffrey changed the title Add option flatten_top_level_arrays to TapeDecoder json: Add option flatten_top_level_arrays to TapeDecoder Aug 19, 2026
@adriangbot

This comment was marked as duplicate.

@Jefffrey Jefffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for taking so long to review, the PR makes sense to me. just some minor comments and CI to fix up

Are there any user-facing changes?

The primary change is the addition of a new_with_options method on TapeDecoder, that allows the user to specify a value for the new configuration option. I figured a config struct was more future-proof, and we may want to mark it as #[non_exhaustive] but that's debatable.

this is probably unnecessary since its currently private

Comment thread arrow-json/src/reader/tape.rs Outdated
impl DecoderState {
fn as_str(&self) -> &'static str {
match self {
DecoderState::TopLevelList => "list",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to give this a distinct name from list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a judgement call. The method's only used to format error messages, so it could be useful to change this to "top-level list".

Comment thread arrow-json/src/reader/mod.rs Resolved
Comment thread arrow-json/src/reader/mod.rs Resolved
@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing json-array (21fc186) to 7eeb3eb (merge-base) diff

Run configuration
run benchmark json_reader
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                        json-array                             main
-----                                        ----------                             ----
decode_binary_hex_json                       1.01     13.8±0.03ms        ? ?/sec    1.00     13.8±0.07ms        ? ?/sec
decode_binary_view_hex_json                  1.01     14.2±0.04ms        ? ?/sec    1.00     14.1±0.05ms        ? ?/sec
decode_fixed_binary_hex_json                 1.02     14.0±0.03ms        ? ?/sec    1.00     13.7±0.06ms        ? ?/sec
decode_list_long_json/131072                 1.00    284.2±0.96ms   275.5 MB/sec    1.06    302.6±1.71ms   258.8 MB/sec
decode_list_long_serialize                   1.00    182.7±0.94ms        ? ?/sec    1.12    204.4±0.91ms        ? ?/sec
decode_list_short_json/131072                1.00     18.7±0.07ms   279.3 MB/sec    1.07     20.1±0.10ms   260.3 MB/sec
decode_list_short_serialize                  1.00     11.1±0.05ms        ? ?/sec    1.03     11.4±0.06ms        ? ?/sec
decode_list_view_long_json/131072            1.00    285.2±1.44ms   274.5 MB/sec    1.06    302.6±1.68ms   258.8 MB/sec
decode_list_view_long_serialize              1.00    183.8±0.86ms        ? ?/sec    1.12    206.1±0.93ms        ? ?/sec
decode_list_view_short_json/131072           1.00     18.9±0.08ms   275.6 MB/sec    1.07     20.2±0.15ms   257.8 MB/sec
decode_list_view_short_serialize             1.00     11.2±0.07ms        ? ?/sec    1.05     11.7±0.07ms        ? ?/sec
decode_map_large_json/131072                 1.01    256.2±0.94ms   296.4 MB/sec    1.00    253.8±1.18ms   299.3 MB/sec
decode_map_large_serialize                   1.00    291.4±1.66ms        ? ?/sec    1.01    293.1±1.53ms        ? ?/sec
decode_map_small_json/131072                 1.01     29.7±0.13ms   276.8 MB/sec    1.00     29.5±0.14ms   278.6 MB/sec
decode_map_small_serialize                   1.00     19.9±0.14ms        ? ?/sec    1.01     20.0±0.11ms        ? ?/sec
decode_ree_long_json/131072                  1.00      5.8±0.12ms   261.2 MB/sec    1.07      6.2±0.01ms   244.5 MB/sec
decode_ree_long_serialize                    1.01      4.3±0.01ms        ? ?/sec    1.00      4.2±0.02ms        ? ?/sec
decode_ree_short_json/131072                 1.00      6.3±0.01ms   275.0 MB/sec    1.02      6.4±0.01ms   269.8 MB/sec
decode_ree_short_serialize                   1.00      4.5±0.02ms        ? ?/sec    1.01      4.6±0.04ms        ? ?/sec
decode_wide_object_json/131072               1.01    459.3±3.58ms   209.5 MB/sec    1.00    455.2±6.62ms   211.4 MB/sec
decode_wide_object_serialize                 1.06   460.1±56.19ms        ? ?/sec    1.00    433.4±6.64ms        ? ?/sec
decode_wide_projection_full_json/131072      1.00    742.1±7.59ms   234.5 MB/sec    1.00    741.9±8.60ms   234.5 MB/sec
decode_wide_projection_narrow_json/131072    1.00    429.7±1.00ms   404.9 MB/sec    1.01    431.9±1.39ms   402.8 MB/sec
infer_json_schema/1000                       1.01  1532.8±10.70µs    82.4 MB/sec    1.00   1521.4±7.79µs    83.0 MB/sec
large_bench_primitive                        1.02   1491.8±1.99µs        ? ?/sec    1.00   1465.2±2.67µs        ? ?/sec
small_bench_list                             1.00      6.6±0.02µs        ? ?/sec    1.02      6.7±0.02µs        ? ?/sec
small_bench_primitive                        1.00      3.9±0.01µs        ? ?/sec    1.02      4.0±0.02µs        ? ?/sec
small_bench_primitive_with_utf8view          1.00      3.9±0.01µs        ? ?/sec    1.02      4.0±0.02µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 455.1s
Peak memory 1.4 GiB
Avg memory 923.2 MiB
CPU user 410.5s
CPU sys 37.7s
Peak spill 0 B

branch

Metric Value
Wall time 455.1s
Peak memory 1.4 GiB
Avg memory 923.4 MiB
CPU user 412.3s
CPU sys 36.2s
Peak spill 0 B

File an issue against this benchmark runner

@Jefffrey
Jefffrey merged commit e5c18fa into apache:main Aug 22, 2026
31 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @Rafferty97 & @scovich

@Rafferty97
Rafferty97 deleted the json-array branch August 22, 2026 13:17
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Aug 26, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Aug 28, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 2, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 18, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 21, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 25, 2026
…9496)

# Which issue does this PR close?

N/A

# Rationale for this change

There are JSON files in the wild that are structured as a single array
at the root level, i.e. `[{...}, {....}, {...}]`. At present, this would
be read by the tape decoder as one single array-valued record, but since
each nested object is what constitutes a "row", this is not ideal.

So, this PR extends the `TapeDecoder` to support these kinds of JSON
files via an opt-in configuration option.

A PR was recently merged into Datafusion to support this exact usecase,
but it currently employs a streaming converter to transform "top-level
array" JSON sources into ND-JSON. If this PR is merged, this would
facilitate the refactoring of this feature to use the `TapeDecoder`
directly, which should noticably improve performance. See
apache/datafusion#19920 for context.

# What changes are included in this PR?

This PR modestly refactors the `TapeDecoder` to facilitate this use
case, by adding an option called `flatten_top_level_arrays`. When
enabled, any top-level arrays are "flattened" such that their elements
each become an individual row in the output batch, rather than the
entire array becoming a single row as would otherwise happen.

# Are these changes tested?

Yes, these changes pass all existing unit tests, and I've added a new
unit test for this feature specifically.

# Are there any user-facing changes?

The primary change is the addition of a `new_with_options` method on
`TapeDecoder`, that allows the user to specify a value for the new
configuration option. I figured a config struct was more future-proof,
and we may want to mark it as `#[non_exhaustive]` but that's debatable.

---------

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-json arrow-json crate enhancement New feature/addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants