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

ARROW-16911: [C++] Add Equals method to Partitioning #13567

Merged
merged 14 commits into from
Jul 19, 2022

Conversation

vibhatha
Copy link
Collaborator

Adding Equals method to Partitioning class and extended classes. Also include a few test cases.

@github-actions
Copy link

@github-actions
Copy link

⚠️ Ticket has no components in JIRA, make sure you assign one.

if (this == &other) {
return true;
}
return checked_cast<const DefaultPartitioning&>(other).type_name() == type_name() &&
Copy link
Member

Choose a reason for hiding this comment

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

Don't do the checked cast here, it'll be wrong if the other partitioning isn't the same type. You don't use any methods from the derived type anyways.

Copy link
Member

@westonpace westonpace Jul 11, 2022

Choose a reason for hiding this comment

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

I agree with @lidavidm that a checked_cast should be avoided. If you received a pointer type Partitioning* you could do a dynamic_cast instead of the type_name comparison. However, a failed dynamic_cast is an exception when you have a reference type and it's probably better to just compare type_name.

The comparison to type_name is basically doing the same thing as a cast check anyways.

The reason a checked_cast is a bad idea is that it should be ok for a user to do:

DefaultPartitioning one;
KeyValuePartitioning two(schema);
if (one.Equals(two)) {
  std::cout << "equal" << std::endl;
}

This Equals method should always return false so this toy example is somewhat meaningless. However, it could be useful if the actual partitions were based on file metadata or something dynamically calculated. If there is a checked_cast then, instead of false, we will get an abort in debug mode and potentially a segmentation fault in release mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes your absolutely right, sorry I missed this. Thanks for pointing this out.

Comment on lines 408 to 413
if (this == &other) {
return true;
}
const auto& direct_part =
::arrow::internal::checked_cast<const DirectoryPartitioning&>(other);
return type_name() == direct_part.type_name() && KeyValuePartitioning::Equals(other);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (this == &other) {
return true;
}
const auto& direct_part =
::arrow::internal::checked_cast<const DirectoryPartitioning&>(other);
return type_name() == direct_part.type_name() && KeyValuePartitioning::Equals(other);
return type_name() == direct_part.type_name() && KeyValuePartitioning::Equals(other);

Copy link
Member

Choose a reason for hiding this comment

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

and ditto below (since KeyValuePartitioning::Equals does the this == &other check already

if (this == &other) {
return true;
}
return checked_cast<const DefaultPartitioning&>(other).type_name() == type_name() &&
Copy link
Member

@westonpace westonpace Jul 11, 2022

Choose a reason for hiding this comment

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

I agree with @lidavidm that a checked_cast should be avoided. If you received a pointer type Partitioning* you could do a dynamic_cast instead of the type_name comparison. However, a failed dynamic_cast is an exception when you have a reference type and it's probably better to just compare type_name.

The comparison to type_name is basically doing the same thing as a cast check anyways.

The reason a checked_cast is a bad idea is that it should be ok for a user to do:

DefaultPartitioning one;
KeyValuePartitioning two(schema);
if (one.Equals(two)) {
  std::cout << "equal" << std::endl;
}

This Equals method should always return false so this toy example is somewhat meaningless. However, it could be useful if the actual partitions were based on file metadata or something dynamically calculated. If there is a checked_cast then, instead of false, we will get an abort in debug mode and potentially a segmentation fault in release mode.

@vibhatha vibhatha marked this pull request as ready for review July 12, 2022 04:02
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Thanks for the update @vibhatha, here are a couple more comments.

@lidavidm
Copy link
Member

LGTM after Antoine's comments are addressed.

@vibhatha
Copy link
Collaborator Author

cc @lidavidm @pitrou addressed the reviews

@pitrou
Copy link
Member

pitrou commented Jul 18, 2022

@vibhatha This CI failure looks unrelated, can you take a look? https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2042

@vibhatha
Copy link
Collaborator Author

@vibhatha This CI failure looks unrelated, can you take a look? https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2042

@pitrou seems like related

/arrow/cpp/src/arrow/dataset/partition_test.cc
[2024](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2025)
In file included from /usr/include/x86_64-linux-gnu/c++/6/bits/c++allocator.h:33:0,
[2025](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2026)
                 from /usr/include/c++/6/bits/allocator.h:46,
[2026](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2027)
                 from /usr/include/c++/6/string:41,
[2027](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2028)
                 from /usr/include/c++/6/stdexcept:39,
[2028](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2029)
                 from /usr/include/c++/6/array:39,
[2029](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2030)
                 from /usr/include/c++/6/tuple:39,
[2030](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2031)
                 from /usr/include/c++/6/functional:55,
[2031](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2032)
                 from /arrow/cpp/src/arrow/dataset/partition.h:22,
[2032](https://github.com/apache/arrow/runs/7351561711?check_suite_focus=true#step:6:2033)
                 from /arrow/cpp/src/arrow/dataset/partition_test.cc:18:

@vibhatha
Copy link
Collaborator Author

I will look into this.

@pitrou
Copy link
Member

pitrou commented Jul 18, 2022

Yes, I meant related, sorry :-)

@vibhatha
Copy link
Collaborator Author

@pitrou I think now it is fixed, but some CIs are failing because of a protobuf issue.

cc @lidavidm It is visible here too.

@vibhatha vibhatha requested review from pitrou and lidavidm July 18, 2022 14:54
@lidavidm
Copy link
Member

Antoine is fixing the Protobuf issue in #13634

@vibhatha
Copy link
Collaborator Author

@pitrou Thanks for catching the wrong push_back.

@pitrou pitrou merged commit d07dc75 into apache:master Jul 19, 2022
@ursabot
Copy link

ursabot commented Jul 20, 2022

Benchmark runs are scheduled for baseline = 0fda96c and contender = d07dc75. d07dc75 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Failed ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Failed ⬇️0.97% ⬆️0.0%] test-mac-arm
[Failed ⬇️0.32% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.04% ⬆️0.04%] ursa-thinkcentre-m75q
Buildkite builds:
[Failed] d07dc75e ec2-t3-xlarge-us-east-2
[Failed] d07dc75e test-mac-arm
[Failed] d07dc75e ursa-i9-9960x
[Finished] d07dc75e ursa-thinkcentre-m75q
[Failed] 0fda96c4 ec2-t3-xlarge-us-east-2
[Failed] 0fda96c4 test-mac-arm
[Failed] 0fda96c4 ursa-i9-9960x
[Finished] 0fda96c4 ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@vibhatha
Copy link
Collaborator Author

@pitrou Is this something to worry about? I cannot trace the failure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants