You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sunby (via GitHub)" <gi...@apache.org> on 2024/07/30 13:20:22 UTC
[PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
sunby opened a new pull request, #43485:
URL: https://github.com/apache/arrow/pull/43485
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
We should give a cast suggestion if an overflow happens when concatenating struct type. eg. when concatenating a type like `struct<a: int8, b: list>` an overflow on the recursive concatenation of field b should lead to a cast suggestion to `struct<a: int8, b: large_list>`.
### What changes are included in this PR?
Suggest casts when concatenation of struct type fails due to overflow.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### Are these changes tested?
Yes.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697905167
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
Review Comment:
>
Thanks for this correction. So we only need to return fields that fail to do the concatenation right? I originally thought that returning all fields would be more user-friendly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697905167
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
Review Comment:
>
Thanks for this correction. So we only need to return fields that fail to do the concatenation right? I originally thought that returning normal fields would be more user-friendly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697915159
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
+ auto status = ConcatenateImpl(child_data, pool_)
+ .Concatenate(&out_->child_data[i], &child_hints);
+ if (!status.ok() && child_hints.suggested_cast) {
+ ARROW_ASSIGN_OR_RAISE(
+ suggested,
+ suggested
+ ? suggested->SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast)))
+ : s.SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast))));
+ }
+ }
Review Comment:
line 580 should be `suggested_field_casts[i]->WithType(std::move(field_error_hints.suggested_cast));` because `field_error_hints.suggested_cast`'s type is `std::shared_ptr<DataType>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1698897510
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -686,6 +703,7 @@ class ConcatenateImpl {
RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
.Concatenate(&out_->child_data[i], /*hints=*/nullptr));
}
+
Review Comment:
```suggestion
```
##########
cpp/src/arrow/array/concatenate_test.cc:
##########
@@ -760,6 +760,24 @@ TEST_F(ConcatenateTest, OffsetOverflow) {
pool, &suggested_cast)
.status());
ASSERT_TRUE(suggested_cast->Equals(LargeVersionOfType(list_view_ty)));
+
+ auto struct_ty = struct_({field("a", int32()), field("b", list(utf8()))});
+ auto fake_long_struct = ArrayFromJSON(struct_ty, "[[0, [\"Hello\"]]]");
+ std::dynamic_pointer_cast<StructArray>(fake_long_struct)
Review Comment:
Use `internal::checked_pointer_cast<>(..)` from `arrow/util/checked_cast.h`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on PR #43485:
URL: https://github.com/apache/arrow/pull/43485#issuecomment-2258337728
issue: https://github.com/apache/arrow/issues/43316
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697256378
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
+ auto status = ConcatenateImpl(child_data, pool_)
+ .Concatenate(&out_->child_data[i], &child_hints);
+ if (!status.ok() && child_hints.suggested_cast) {
Review Comment:
what if `!status.ok()` but no `suggested_cast`? Should this return directly?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on PR #43485:
URL: https://github.com/apache/arrow/pull/43485#issuecomment-3551630226
@felipecrv I think this pr is ready to review, PTAL if you have time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697915159
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
+ auto status = ConcatenateImpl(child_data, pool_)
+ .Concatenate(&out_->child_data[i], &child_hints);
+ if (!status.ok() && child_hints.suggested_cast) {
+ ARROW_ASSIGN_OR_RAISE(
+ suggested,
+ suggested
+ ? suggested->SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast)))
+ : s.SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast))));
+ }
+ }
Review Comment:
line 580 should be `suggested_field_casts[i] = suggested_field_casts[i]->WithType(std::move(field_error_hints.suggested_cast));` because `field_error_hints.suggested_cast`'s type is `std::shared_ptr<DataType>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "sunby (via GitHub)" <gi...@apache.org>.
sunby commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697905167
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
Review Comment:
>
Thanks for this correction. So we only need to return fields that fail to do the concatenation right? I originally thought that returning all fields would be more user-friendly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-43316: [C++] Implement cast suggestions for struct type [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on code in PR #43485:
URL: https://github.com/apache/arrow/pull/43485#discussion_r1697495817
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
Review Comment:
rename to `field_error_hints` or just `error_hints` because these are "hints about error" states.
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
+ auto status = ConcatenateImpl(child_data, pool_)
+ .Concatenate(&out_->child_data[i], &child_hints);
+ if (!status.ok() && child_hints.suggested_cast) {
+ ARROW_ASSIGN_OR_RAISE(
+ suggested,
+ suggested
+ ? suggested->SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast)))
+ : s.SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast))));
+ }
+ }
+ if (suggested) {
+ suggested_cast_ = std::move(suggested);
+ return OffsetOverflowStatus();
Review Comment:
```suggestion
if (!suggested_field_casts.empty()) {
suggested_cast_ = struct_(suggested_field_casts);
return OffsetOverflowStatus();
}
```
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
for (int i = 0; i < s.num_fields(); ++i) {
ARROW_ASSIGN_OR_RAISE(auto child_data, ChildData(i));
- RETURN_NOT_OK(ConcatenateImpl(child_data, pool_)
- .Concatenate(&out_->child_data[i], /*hints=*/nullptr));
+ ErrorHints child_hints;
+ auto status = ConcatenateImpl(child_data, pool_)
+ .Concatenate(&out_->child_data[i], &child_hints);
+ if (!status.ok() && child_hints.suggested_cast) {
+ ARROW_ASSIGN_OR_RAISE(
+ suggested,
+ suggested
+ ? suggested->SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast)))
+ : s.SetField(
+ i, s.field(i)->WithType(std::move(child_hints.suggested_cast))));
+ }
+ }
Review Comment:
```suggestion
if (!status.ok()) {
if (child_hints.suggested_cast) {
// There is a hint that the error can be fixed by casting the field.
if (suggested_field_casts.empty()) {
suggested_field_casts = s.fields();
}
suggested_field_casts[i] = std::move(child_hints.suggested_cast);
} else {
// No hint, we should abort by returning the bad status.
return status;
}
}
```
##########
cpp/src/arrow/array/concatenate.cc:
##########
@@ -565,10 +565,25 @@ class ConcatenateImpl {
}
Status Visit(const StructType& s) {
+ std::shared_ptr<StructType> suggested = nullptr;
Review Comment:
```suggestion
// Populated if the concatenation of some field fails due to overflow.
// Then it's used in the end to produce the StructType suggestion.
std::vector<std::shared_ptr<Field>> suggested_field_casts;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org