Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slice method to array #287

Merged
merged 6 commits into from
Nov 22, 2024

Conversation

Alex-PLACET
Copy link
Collaborator

No description provided.

@Alex-PLACET Alex-PLACET force-pushed the add_slice_method_to_array branch from 5458b81 to e283b91 Compare November 14, 2024 14:00
@Alex-PLACET Alex-PLACET marked this pull request as draft November 14, 2024 14:15
src/array.cpp Outdated
@@ -48,6 +49,13 @@ namespace sparrow
return array_element(*p_array, index);
}

void array::slice(size_type start, size_type end)
Copy link
Collaborator

@DerThorsten DerThorsten Nov 14, 2024

Choose a reason for hiding this comment

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

I would prefer slice to return a array which is a view to the original array.
ie auto sliced_arr = arr.slice(start, end);
With the view function of the arrow_proxy it should be possible to create a cheap "view-copy" of the array and than change the offset and size there

Or maybe we should be explicit
auto sliced_arr = arr.slice(start, end); #deep copy
auto sliced_arr = arr.slice_view(start, end); #view
arr.slice_inplace(start, end) #modify
(not sure if the last one is needed or a good idea as mutating an array should be avoided if possible,imho)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now we have arr.slice and arr.slice_view

ar.slice(2, 8);

REQUIRE_EQ(ar.size(), 6);
CHECK_EQ(std::get<const_reference>(ar[0]), make_nullable<scalar_value_type>(2));
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add this to the consistency test instead of implementing this by hand

@DerThorsten DerThorsten mentioned this pull request Nov 18, 2024
18 tasks
@Alex-PLACET Alex-PLACET force-pushed the add_slice_method_to_array branch 2 times, most recently from 69e5ac8 to c6174cf Compare November 19, 2024 10:42
@Alex-PLACET Alex-PLACET marked this pull request as ready for review November 19, 2024 12:20
src/array.cpp Outdated
ArrowArray* ar = new ArrowArray;
*ar = arrow_proxy_copy.array();
ar->offset = static_cast<int64_t>(start);
ar->length = static_cast<int64_t>(end - start);
Copy link
Collaborator

@JohanMabille JohanMabille Nov 20, 2024

Choose a reason for hiding this comment

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

This method creates a memory leak, since as and ar will not be deleted. A way to fix this would be to allocate these structures on the stack and move them in the returned array. The release methods should be set to empty methods to avoid destruciton of the data when the view is destroyed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. But we can't set the release to null as it means that the array is invalid.
I have to create another release callback which don't delete the buffers

@Alex-PLACET Alex-PLACET self-assigned this Nov 20, 2024
@Alex-PLACET Alex-PLACET force-pushed the add_slice_method_to_array branch from 18e747d to 2dc35be Compare November 21, 2024 10:35
@Alex-PLACET Alex-PLACET merged commit 8fb711a into man-group:main Nov 22, 2024
71 checks passed
@Alex-PLACET Alex-PLACET deleted the add_slice_method_to_array branch November 22, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants