Skip to content

Support ListView codec in arrow-json#9503

Merged
alamb merged 7 commits intoapache:mainfrom
liamzwbao:issue-9340-list-view-json-codec
Mar 26, 2026
Merged

Support ListView codec in arrow-json#9503
alamb merged 7 commits intoapache:mainfrom
liamzwbao:issue-9340-list-view-json-codec

Conversation

@liamzwbao
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Support ListView codec in arrow-json. Using ListLikeArray trait to simplify implementation.

Are these changes tested?

Tests added

Are there any user-facing changes?

New encoder/decoder

@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 3, 2026
@liamzwbao liamzwbao force-pushed the issue-9340-list-view-json-codec branch from 15ef1c9 to 285baaa Compare March 17, 2026 00:33
@liamzwbao liamzwbao marked this pull request as ready for review March 17, 2026 00:34
Copy link
Copy Markdown
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

Generally looks good, but I think it would be good to have some roundtrip tests too

.add_buffer(offsets.finish())
.child_data(vec![child_data]);

if IS_VIEW {
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.

I do wonder if theres a cleaner way to handle this rather than calculating size at the end, though I assume performance impact is probably minimal

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.

We could calculate the size on the fly, but I would prefer calculating here and keeping the main loop clean. This implementation follows the same thought as the variant_to_arrow list builder:

if IS_VIEW {
// NOTE: `offsets` is never empty (constructor pushes an entry)
let mut sizes = Vec::with_capacity(self.offsets.len() - 1);
for i in 1..self.offsets.len() {
sizes.push(self.offsets[i] - self.offsets[i - 1]);
}
self.offsets.pop();
let list_view_array = GenericListViewArray::<O>::new(
field,
ScalarBuffer::from(self.offsets),
ScalarBuffer::from(sizes),
ArrayRef::from(element_array),
self.nulls.finish(),
);
Ok(Arc::new(list_view_array))
} else {
let list_array = GenericListArray::<O>::new(
field,
OffsetBuffer::<O>::new(ScalarBuffer::from(self.offsets)),
ArrayRef::from(element_array),
self.nulls.finish(),
);
Ok(Arc::new(list_array))
}

@liamzwbao liamzwbao requested a review from Jefffrey March 22, 2026 19:47
@liamzwbao
Copy link
Copy Markdown
Contributor Author

Tests added. PTAL, thanks! @Jefffrey

@alamb alamb merged commit 1f1c3a4 into apache:main Mar 26, 2026
23 checks passed
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Mar 26, 2026

Thanks @liamzwbao and @Jefffrey

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ListView in arrow-json

3 participants