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 get_element for struct column #8578

Merged
merged 6 commits into from
Jun 25, 2021

Conversation

isVoid
Copy link
Contributor

@isVoid isVoid commented Jun 22, 2021

Partly addresses #8558

This PR supports retrieving a struct_scalar from STRUCT type column.

@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label Jun 22, 2021
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

❗ No coverage uploaded for pull request base (branch-21.08@bbf375b). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##             branch-21.08    #8578   +/-   ##
===============================================
  Coverage                ?   83.01%           
===============================================
  Files                   ?      109           
  Lines                   ?    18225           
  Branches                ?        0           
===============================================
  Hits                    ?    15129           
  Misses                  ?     3096           
  Partials                ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbf375b...b9fbd6e. Read the comment docs.

@isVoid isVoid added feature request New feature or request 3 - Ready for Review Ready for review by team non-breaking Non-breaking change labels Jun 23, 2021
@isVoid isVoid marked this pull request as ready for review June 23, 2021 02:04
@isVoid isVoid requested a review from a team as a code owner June 23, 2021 02:04
auto row_contents =
std::make_unique<column>(slice(input, index, index + 1), stream, mr)->release();
auto scalar_contents = std::make_unique<table>(std::move(row_contents.children));
return std::make_unique<struct_scalar>(std::move(*scalar_contents), valid, stream, mr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think std::move(*scalar_contents) is wrong as the unique_ptr hasn't been informed that it doesn't have ownership anymore. I think you want:

auto scalar_contents = table(std::move(row_contents.children));
std::make_unique<struct_scalar>(std::move(scalar_contents), valid, stream, mr);

Copy link
Contributor

@mythrocks mythrocks Jun 23, 2021

Choose a reason for hiding this comment

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

std::make_unique<struct_scalar>(std::move(scalar_contents), valid, stream, mr);

Not quite. The struct_scalar constructor needs a table&&.

I think std::move(*scalar_contents) is wrong as the unique_ptr hasn't been informed that it doesn't have ownership anymore.

The unique_ptr retains ownership of the "moved-from" object, which should be safe to destroy when the unique_ptr goes out of scope. (Please correct me if I'm wrong.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you are correct. To clarify, the object (the table) being pointed to by the std::unique_ptr<> has had it's internal buffers emptied out, but the table held by the pointer itself still exists, so when it gets deleted, it's destructor does nothing.

It is a little bit subtle though. @robertmaynard 's suggestion makes the sequence of operations a lot more clear.

As a side note, it's a little surprising the PR that added these move constructors didn't actually have any tests for them.

Copy link
Contributor

@mythrocks mythrocks Jun 23, 2021

Choose a reason for hiding this comment

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

Ah, I misread @robertmaynard's suggestion: scalar_contents is a table, in his case.

I agree. @robertmaynard's way reads better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments. Moving to @robertmaynard 's suggestion.

From a lower level perspective, previously

std::make_unique<struct_scalar>(std::move(*scalar_contents), valid, stream, mr);

creates a table object with the contents that was pointed to by the unique_ptr and was later moved to the struct_scalar. After this step, the unique_ptr still points to a table object, but as a result of default move constructor, that object now contains 0 columns, effectively empty. It's safe for unique_ptr to deallocate this object because the table object is still live, its internal _columns field is also live, only it's empty.

Agreed it's subtle compared to the new writings.

Copy link
Contributor

@nvdbaranec nvdbaranec left a comment

Choose a reason for hiding this comment

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

See comment on the thread about the move constructor.

cpp/src/copying/get_element.cu Outdated Show resolved Hide resolved
@isVoid isVoid requested a review from nvdbaranec June 24, 2021 23:42
@isVoid
Copy link
Contributor Author

isVoid commented Jun 25, 2021

rerun tests

@isVoid isVoid added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Jun 25, 2021
@isVoid
Copy link
Contributor Author

isVoid commented Jun 25, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 4a0bea5 into rapidsai:branch-21.08 Jun 25, 2021
rapids-bot bot pushed a commit that referenced this pull request Jun 29, 2021
Implements necessary `__getitem__` changes for python side. Partly addresses #8558, merge after #8578

Authors:
  - https://github.com/shaneding

Approvers:
  - https://github.com/brandon-b-miller
  - Ashwin Srinath (https://github.com/shwina)

URL: #8577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge feature request New feature or request libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants