You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "bkietz (via GitHub)" <gi...@apache.org> on 2023/10/24 20:30:20 UTC
[PR] GH-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
bkietz opened a new pull request, #38443:
URL: https://github.com/apache/arrow/pull/38443
<!--
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
Utf8View and BinaryView should be added to the c ABI spec and to the c++ library's importer/exporter.
<!--
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.
-->
<!--
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, minimally
<!--
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)?
-->
### Are there any user-facing changes?
View arrays will be importable/exportable through the c ABI in c++
<!--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1778124576
LGTM. But of course we need to wait for the separate review and merge of the string view PR before merging this.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409412464
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -1418,9 +1454,7 @@ class ImportedBuffer : public Buffer {
struct ArrayImporter {
explicit ArrayImporter(const std::shared_ptr<DataType>& type)
- : type_(type),
- zero_size_buffer_(std::make_shared<Buffer>(kZeroSizeArea, 0)),
- device_type_(DeviceAllocationType::kCPU) {}
Review Comment:
That's an aggressive linter...
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409425143
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -887,6 +905,32 @@ TEST_F(TestArrayExport, PrimitiveSliced) {
TestPrimitive(factory);
}
+constexpr std::string_view binary_view_buffer_content0 = "12345foo bar baz quux",
+ binary_view_buffer_content1 = "BinaryViewMultipleBuffers";
+
+static const BinaryViewType::c_type binary_view_buffer1[] = {
+ util::ToBinaryView(binary_view_buffer_content0, 0, 0),
+ util::ToInlineBinaryView("foo"),
+ util::ToBinaryView(binary_view_buffer_content1, 1, 0),
+ util::ToInlineBinaryView("bar"),
+ util::ToBinaryView(binary_view_buffer_content0.substr(5), 0, 5),
+ util::ToInlineBinaryView("baz"),
+ util::ToBinaryView(binary_view_buffer_content1.substr(6, 13), 1, 6),
+ util::ToInlineBinaryView("quux"),
+};
+
+TEST_F(TestArrayExport, BinaryViewMultipleBuffers) {
+ auto length = static_cast<int64_t>(std::size(binary_view_buffer1));
+ auto arr = std::make_shared<BinaryViewArray>(
+ binary_view(), length, Buffer::Wrap(binary_view_buffer1, length),
+ BufferVector{
+ std::make_shared<Buffer>(binary_view_buffer_content0),
+ std::make_shared<Buffer>(binary_view_buffer_content1),
+ });
+ TestNested([&] { return arr; });
Review Comment:
I'll use TestPrimitive and copy those buffers onto the heap
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1408446590
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -260,7 +264,7 @@ struct SchemaExporter {
// Dictionary type: parent struct describes index type,
// child dictionary struct describes value type.
RETURN_NOT_OK(VisitTypeInline(*dict_type.index_type(), this));
- dict_exporter_.reset(new SchemaExporter());
+ dict_exporter_ = std::make_unique<SchemaExporter>();
Review Comment:
i've actually wondered.... is there any particular difference (performance or otherwise) doing `.reset(new T)` vs `= std::make_unique<T>()`?
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -566,15 +575,31 @@ struct ArrayExporter {
--n_buffers;
++buffers_begin;
}
+
+ bool need_variadic_buffer_sizes =
+ data->type->id() == Type::BINARY_VIEW || data->type->id() == Type::STRING_VIEW;
+ if (need_variadic_buffer_sizes) {
+ ++n_buffers;
+ }
+
export_.buffers_.resize(n_buffers);
std::transform(buffers_begin, data->buffers.end(), export_.buffers_.begin(),
[](const std::shared_ptr<Buffer>& buffer) -> const void* {
return buffer ? buffer->data() : nullptr;
});
+ if (need_variadic_buffer_sizes) {
+ auto variadic_buffers = util::span(data->buffers).subspan(2);
+ export_.variadic_buffer_sizes_.resize(variadic_buffers.size());
+ for (auto [size, buf] : Zip(export_.variadic_buffer_sizes_, variadic_buffers)) {
+ size = buf->size();
+ }
Review Comment:
the `size` here is a reference? is there any way for it to be more explicit that this is a reference in the syntax here?
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -122,7 +125,7 @@ class ReleaseCallback {
private:
ARROW_DISALLOW_COPY_AND_ASSIGN(ReleaseCallback);
- bool called_;
+ bool called_{};
Review Comment:
should this be `{ false };` ? (unless I'm forgetting how the default initialization works)
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -1418,9 +1454,7 @@ class ImportedBuffer : public Buffer {
struct ArrayImporter {
explicit ArrayImporter(const std::shared_ptr<DataType>& type)
- : type_(type),
- zero_size_buffer_(std::make_shared<Buffer>(kZeroSizeArea, 0)),
- device_type_(DeviceAllocationType::kCPU) {}
Review Comment:
we lost the default to `DeviceAllocationType::kCPU`, should it be added to the initialization below?
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz merged PR #38443:
URL: https://github.com/apache/arrow/pull/38443
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409279626
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -122,7 +125,7 @@ class ReleaseCallback {
private:
ARROW_DISALLOW_COPY_AND_ASSIGN(ReleaseCallback);
- bool called_;
+ bool called_{};
Review Comment:
It would be more readable like that, yes.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1835069026
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 94fc124288a0b925c26ea3800ec380020abe9e42.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/19201948192) has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409479176
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -1418,9 +1454,7 @@ class ImportedBuffer : public Buffer {
struct ArrayImporter {
explicit ArrayImporter(const std::shared_ptr<DataType>& type)
- : type_(type),
- zero_size_buffer_(std::make_shared<Buffer>(kZeroSizeArea, 0)),
- device_type_(DeviceAllocationType::kCPU) {}
Review Comment:
i agree, that really is an aggressive linter.... lol
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409393131
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -1418,9 +1454,7 @@ class ImportedBuffer : public Buffer {
struct ArrayImporter {
explicit ArrayImporter(const std::shared_ptr<DataType>& type)
- : type_(type),
- zero_size_buffer_(std::make_shared<Buffer>(kZeroSizeArea, 0)),
- device_type_(DeviceAllocationType::kCPU) {}
Review Comment:
This was a linter action, which replaced DeviceAllocationType::kCPU with `{}` below since that's equivalent in this case. I'll replace `{}` with the more explicit form.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1370781289
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -353,6 +353,8 @@ TEST_F(TestSchemaExport, Primitive) {
TestPrimitive(large_binary(), "Z");
TestPrimitive(utf8(), "u");
TestPrimitive(large_utf8(), "U");
+ TestPrimitive(binary_view(), "vz");
+ TestPrimitive(utf8_view(), "vu");
Review Comment:
Should I add a test exercising many/no buffers?
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1778733535
You also need to remove the corresponding skips in datagen.py.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409477233
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -260,7 +264,7 @@ struct SchemaExporter {
// Dictionary type: parent struct describes index type,
// child dictionary struct describes value type.
RETURN_NOT_OK(VisitTypeInline(*dict_type.index_type(), this));
- dict_exporter_.reset(new SchemaExporter());
+ dict_exporter_ = std::make_unique<SchemaExporter>();
Review Comment:
In that case, wouldn't it be better to keep this as calling `.reset` rather than switch to `make_unique`?
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409280009
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -287,7 +289,7 @@ struct SchemaExportChecker {
const std::vector<std::string> flattened_names_;
std::vector<int64_t> flattened_flags_;
const std::vector<std::string> flattened_metadata_;
- size_t flattened_index_;
+ size_t flattened_index_{};
Review Comment:
Readability
```suggestion
size_t flattened_index_{0};
```
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "urvishdesai (via GitHub)" <gi...@apache.org>.
urvishdesai commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1835245922
Hi @bkietz, is there a plan to add Utf8View support to the rust library soon?
If someone is not already working on it, I would like to take up the PR to add support for Utf8View to the arrow2 library (https://github.com/jorgecarleitao/arrow2/issues/1596)
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1836017930
@urvishdesai thanks for offering! I don't think anyone else has that queued, please do (and I'd be happy to review)
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1830368073
ping @pitrou
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1832197446
@pitrou rebased, added round trip tests
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1832535285
Yay! 🚀
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1371326845
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -353,6 +353,8 @@ TEST_F(TestSchemaExport, Primitive) {
TestPrimitive(large_binary(), "Z");
TestPrimitive(utf8(), "u");
TestPrimitive(large_utf8(), "U");
+ TestPrimitive(binary_view(), "vz");
+ TestPrimitive(utf8_view(), "vu");
Review Comment:
That would be nicer IMHO.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1388229361
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -3986,8 +4072,6 @@ TEST_F(TestDeviceArrayRoundtrip, Primitive) {
TestWithJSON(mm, int32(), "[4, 5, null]");
}
-// TODO C -> C++ -> C roundtripping tests?
Review Comment:
I think this can be removed now since the C abi integration tests should cover this
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #38443:
URL: https://github.com/apache/arrow/pull/38443#issuecomment-1779472598
The largest issue I had forgotten: C-ABI doesn't store buffer sizes explicitly. (For string data we derive the data buffer's length by reading the offsets buffer.) I guess we'll need an extra buffer to store those, since reconstructing the sizes by examining every view is untenable
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409566238
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -260,7 +264,7 @@ struct SchemaExporter {
// Dictionary type: parent struct describes index type,
// child dictionary struct describes value type.
RETURN_NOT_OK(VisitTypeInline(*dict_type.index_type(), this));
- dict_exporter_.reset(new SchemaExporter());
+ dict_exporter_ = std::make_unique<SchemaExporter>();
Review Comment:
In this case there is no difference since the assigned pointer is a `unique_ptr<SchemaExporter>` and not a pointer to a base/parent class.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409275278
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -566,15 +575,31 @@ struct ArrayExporter {
--n_buffers;
++buffers_begin;
}
+
+ bool need_variadic_buffer_sizes =
+ data->type->id() == Type::BINARY_VIEW || data->type->id() == Type::STRING_VIEW;
+ if (need_variadic_buffer_sizes) {
+ ++n_buffers;
+ }
+
export_.buffers_.resize(n_buffers);
std::transform(buffers_begin, data->buffers.end(), export_.buffers_.begin(),
[](const std::shared_ptr<Buffer>& buffer) -> const void* {
return buffer ? buffer->data() : nullptr;
});
+ if (need_variadic_buffer_sizes) {
+ auto variadic_buffers = util::span(data->buffers).subspan(2);
+ export_.variadic_buffer_sizes_.resize(variadic_buffers.size());
+ for (auto [size, buf] : Zip(export_.variadic_buffer_sizes_, variadic_buffers)) {
+ size = buf->size();
+ }
Review Comment:
Yes, or perhaps simply avoid `Zip` here and use the more usual and more readable push-back approach:
```c++
export_.variadic_buffer_sizes_.reserve(variadic_buffers.size());
for (const auto& buf : variadic_buffers) {
export_.variadic_buffer_sizes_.push_back(buf->size());
}
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1408551084
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -260,7 +264,7 @@ struct SchemaExporter {
// Dictionary type: parent struct describes index type,
// child dictionary struct describes value type.
RETURN_NOT_OK(VisitTypeInline(*dict_type.index_type(), this));
- dict_exporter_.reset(new SchemaExporter());
+ dict_exporter_ = std::make_unique<SchemaExporter>();
Review Comment:
In scenarios where you have an `std::unique_ptr<ParentClass>` being populated by many sub-classes of `ParentClass`:
`std::make_unique<T, Deleter>(...)` can lead to more binary bloat because `class Deleter = std::default_delete<T>` is type-specialized whereas `reset()` takes a super-class pointer and only needs the deleter that invokes the destructor via dynamic dispatching through the parent class vtable.
Being type-specialized often leads to the derived-classes destructors' being inlined into the `std::default_deleter<T>`. All this extra inlining and removal of one indirection could lead to less overhead of destructor dispatching.
--
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-36099: [C++] Add Utf8View and BinaryView to the c ABI [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38443:
URL: https://github.com/apache/arrow/pull/38443#discussion_r1409284678
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -887,6 +905,32 @@ TEST_F(TestArrayExport, PrimitiveSliced) {
TestPrimitive(factory);
}
+constexpr std::string_view binary_view_buffer_content0 = "12345foo bar baz quux",
+ binary_view_buffer_content1 = "BinaryViewMultipleBuffers";
+
+static const BinaryViewType::c_type binary_view_buffer1[] = {
+ util::ToBinaryView(binary_view_buffer_content0, 0, 0),
+ util::ToInlineBinaryView("foo"),
+ util::ToBinaryView(binary_view_buffer_content1, 1, 0),
+ util::ToInlineBinaryView("bar"),
+ util::ToBinaryView(binary_view_buffer_content0.substr(5), 0, 5),
+ util::ToInlineBinaryView("baz"),
+ util::ToBinaryView(binary_view_buffer_content1.substr(6, 13), 1, 6),
+ util::ToInlineBinaryView("quux"),
+};
+
+TEST_F(TestArrayExport, BinaryViewMultipleBuffers) {
+ auto length = static_cast<int64_t>(std::size(binary_view_buffer1));
+ auto arr = std::make_shared<BinaryViewArray>(
+ binary_view(), length, Buffer::Wrap(binary_view_buffer1, length),
+ BufferVector{
+ std::make_shared<Buffer>(binary_view_buffer_content0),
+ std::make_shared<Buffer>(binary_view_buffer_content1),
+ });
+ TestNested([&] { return arr; });
Review Comment:
Why not use `TestPrimitive`? Also, ideally the factory creates the array on the fly, to make sure that lifetimes are handled properly.
--
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