You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "chrisjordansquire (via GitHub)" <gi...@apache.org> on 2023/09/16 17:17:22 UTC

[GitHub] [arrow] chrisjordansquire opened a new pull request, #37754: GH-37244: [C++] Refactor dict_internal.h to use Result

chrisjordansquire opened a new pull request, #37754:
URL: https://github.com/apache/arrow/pull/37754

   <!--
   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
   
   This change addresses #36111 , updating the method GetDictionaryArrayData in dict_internal.h to return a Result instead of a Status type. 
   
   <!--
    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.  
   -->
   
   ### What changes are included in this PR?
   
   This is a narrow interpretation of the above issue, only changing the return type with minimal updates to the call sites or their return types. 
   
   <!--
   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. The C++ test suite was run on the `ninja-debug` build target using the command `ctest -j16 --output-on-failure`. All tests not requiring parquet data passed. (I was unsure how to setup those tests based on the Arrow development guidelines.) 
   
   <!--
   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?
   
   No. The only changes should be library-internal. 
   
   <!--
   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


[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #37754:
URL: https://github.com/apache/arrow/pull/37754#issuecomment-1727186003

   After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 868b9bde7b7eefe487995dca279149a46eb99c34.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/16954924499) has more details. It also includes information about 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


[GitHub] [arrow] bkietz commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1329271253


##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -299,10 +300,11 @@ class DictionaryUnifierImpl : public DictionaryUnifier {
     }
 
     // Build unified dictionary array
-    std::shared_ptr<ArrayData> data;
-    RETURN_NOT_OK(DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
-                                                     0 /* start_offset */, &data));
-    *out_dict = MakeArray(data);
+    Result<std::shared_ptr<ArrayData>> data;
+    data = DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
+                                              0 /* start_offset */);
+    RETURN_NOT_OK(data.status());
+    *out_dict = MakeArray(data.ValueOrDie());

Review Comment:
   Likewise:
   ```suggestion
       ARROW_ASSIGN_OR_RAISE(auto data, DictTraits::GetDictionaryArrayData(
           pool_, value_type_, memo_table_, /*start_offset=*/0));
       *out_dict = MakeArray(data);
   ```



##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -282,10 +282,11 @@ class DictionaryUnifierImpl : public DictionaryUnifier {
     *out_type = arrow::dictionary(index_type, value_type_);
 
     // Build unified dictionary array
-    std::shared_ptr<ArrayData> data;
-    RETURN_NOT_OK(DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
-                                                     0 /* start_offset */, &data));
-    *out_dict = MakeArray(data);
+    Result<std::shared_ptr<ArrayData>> data;
+    data = DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
+                                              0 /* start_offset */);
+    RETURN_NOT_OK(data.status());
+    *out_dict = MakeArray(data.ValueOrDie());

Review Comment:
   For `Result`s we have a convenience macro which should save you some boilerplate:
   ```suggestion
       ARROW_ASSIGN_OR_RAISE(auto data, DictTraits::GetDictionaryArrayData(
           pool_, value_type_, memo_table_, /*start_offset=*/0));
       *out_dict = MakeArray(data);
   ```



##########
cpp/src/arrow/array/builder_dict.cc:
##########
@@ -106,8 +106,11 @@ class DictionaryMemoTable::DictionaryMemoTableImpl {
     enable_if_memoize<T, Status> Visit(const T&) {
       using ConcreteMemoTable = typename DictionaryTraits<T>::MemoTableType;
       auto memo_table = checked_cast<ConcreteMemoTable*>(memo_table_);
-      return DictionaryTraits<T>::GetDictionaryArrayData(pool_, value_type_, *memo_table,
-                                                         start_offset_, out_);
+      Result<std::shared_ptr<ArrayData>> data;
+      data = DictionaryTraits<T>::GetDictionaryArrayData(pool_, value_type_, *memo_table,
+                                                         start_offset_);
+      *out_ = data.ok() ? data.ValueOrDie() : nullptr;
+      return data.status();

Review Comment:
   ```suggestion
         ARROW_ASSIGN_OR_RAISE(*out_, DictionaryTraits<T>::GetDictionaryArrayData(
             pool_, value_type_, *memo_table, start_offset_));
         return Status::OK();
   ```



##########
cpp/src/arrow/compute/kernels/vector_hash.cc:
##########
@@ -285,8 +285,11 @@ class RegularHashKernel : public HashKernel {
   Status FlushFinal(ExecResult* out) override { return action_.FlushFinal(out); }
 
   Status GetDictionary(std::shared_ptr<ArrayData>* out) override {
-    return DictionaryTraits<Type>::GetDictionaryArrayData(pool_, type_, *memo_table_,
-                                                          0 /* start_offset */, out);
+    Result<std::shared_ptr<ArrayData>> data;

Review Comment:
   also here



-- 
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


[GitHub] [arrow] chrisjordansquire commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "chrisjordansquire (via GitHub)" <gi...@apache.org>.
chrisjordansquire commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1330492327


##########
cpp/src/arrow/compute/kernels/vector_hash.cc:
##########
@@ -285,8 +285,11 @@ class RegularHashKernel : public HashKernel {
   Status FlushFinal(ExecResult* out) override { return action_.FlushFinal(out); }
 
   Status GetDictionary(std::shared_ptr<ArrayData>* out) override {
-    return DictionaryTraits<Type>::GetDictionaryArrayData(pool_, type_, *memo_table_,
-                                                          0 /* start_offset */, out);
+    Result<std::shared_ptr<ArrayData>> data;

Review Comment:
   Change made. 



##########
cpp/src/arrow/array/builder_dict.cc:
##########
@@ -106,8 +106,11 @@ class DictionaryMemoTable::DictionaryMemoTableImpl {
     enable_if_memoize<T, Status> Visit(const T&) {
       using ConcreteMemoTable = typename DictionaryTraits<T>::MemoTableType;
       auto memo_table = checked_cast<ConcreteMemoTable*>(memo_table_);
-      return DictionaryTraits<T>::GetDictionaryArrayData(pool_, value_type_, *memo_table,
-                                                         start_offset_, out_);
+      Result<std::shared_ptr<ArrayData>> data;
+      data = DictionaryTraits<T>::GetDictionaryArrayData(pool_, value_type_, *memo_table,
+                                                         start_offset_);
+      *out_ = data.ok() ? data.ValueOrDie() : nullptr;
+      return data.status();

Review Comment:
   Done. 



-- 
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


[GitHub] [arrow] chrisjordansquire commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "chrisjordansquire (via GitHub)" <gi...@apache.org>.
chrisjordansquire commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1328133344


##########
cpp/src/arrow/array/dict_internal.h:
##########
@@ -63,11 +64,10 @@ struct DictionaryTraits<BooleanType> {
   using T = BooleanType;
   using MemoTableType = typename HashTraits<T>::MemoTableType;
 
-  static Status GetDictionaryArrayData(MemoryPool* pool,
-                                       const std::shared_ptr<DataType>& type,
-                                       const MemoTableType& memo_table,
-                                       int64_t start_offset,
-                                       std::shared_ptr<ArrayData>* out) {
+  static Result<std::shared_ptr<ArrayData>> GetDictionaryArrayData(
+      MemoryPool* pool, const std::shared_ptr<DataType>& type,
+      const MemoTableType& memo_table, int64_t start_offset,
+      std::shared_ptr<ArrayData>* out) {

Review Comment:
   Yep. Update incoming. 



##########
cpp/src/arrow/array/dict_internal.h:
##########
@@ -91,11 +92,10 @@ struct DictionaryTraits<T, enable_if_has_c_type<T>> {
   using c_type = typename T::c_type;
   using MemoTableType = typename HashTraits<T>::MemoTableType;
 
-  static Status GetDictionaryArrayData(MemoryPool* pool,
-                                       const std::shared_ptr<DataType>& type,
-                                       const MemoTableType& memo_table,
-                                       int64_t start_offset,
-                                       std::shared_ptr<ArrayData>* out) {
+  static Result<std::shared_ptr<ArrayData>> GetDictionaryArrayData(
+      MemoryPool* pool, const std::shared_ptr<DataType>& type,
+      const MemoTableType& memo_table, int64_t start_offset,
+      std::shared_ptr<ArrayData>* out) {

Review Comment:
   Also ditto. Update incoming. 



-- 
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


[GitHub] [arrow] github-actions[bot] commented on pull request #37754: GH-37244: [C++] Refactor dict_internal.h to use Result

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #37754:
URL: https://github.com/apache/arrow/pull/37754#issuecomment-1722274663

   :warning: GitHub issue #37244 **has been automatically assigned in GitHub** to PR creator.


-- 
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


[GitHub] [arrow] bkietz merged pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz merged PR #37754:
URL: https://github.com/apache/arrow/pull/37754


-- 
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


[GitHub] [arrow] chrisjordansquire commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "chrisjordansquire (via GitHub)" <gi...@apache.org>.
chrisjordansquire commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1330283087


##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -282,10 +282,11 @@ class DictionaryUnifierImpl : public DictionaryUnifier {
     *out_type = arrow::dictionary(index_type, value_type_);
 
     // Build unified dictionary array
-    std::shared_ptr<ArrayData> data;
-    RETURN_NOT_OK(DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
-                                                     0 /* start_offset */, &data));
-    *out_dict = MakeArray(data);
+    Result<std::shared_ptr<ArrayData>> data;
+    data = DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
+                                              0 /* start_offset */);
+    RETURN_NOT_OK(data.status());
+    *out_dict = MakeArray(data.ValueOrDie());

Review Comment:
   Awesome! I was trying to find such a macro and didn't succeed. Thanks for the pointer!



-- 
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


[GitHub] [arrow] github-actions[bot] commented on pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #37754:
URL: https://github.com/apache/arrow/pull/37754#issuecomment-1722279543

   :warning: GitHub issue #36111 **has been automatically assigned in GitHub** to PR creator.


-- 
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


[GitHub] [arrow] mapleFU commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1328042525


##########
cpp/src/arrow/array/dict_internal.h:
##########
@@ -91,11 +92,10 @@ struct DictionaryTraits<T, enable_if_has_c_type<T>> {
   using c_type = typename T::c_type;
   using MemoTableType = typename HashTraits<T>::MemoTableType;
 
-  static Status GetDictionaryArrayData(MemoryPool* pool,
-                                       const std::shared_ptr<DataType>& type,
-                                       const MemoTableType& memo_table,
-                                       int64_t start_offset,
-                                       std::shared_ptr<ArrayData>* out) {
+  static Result<std::shared_ptr<ArrayData>> GetDictionaryArrayData(
+      MemoryPool* pool, const std::shared_ptr<DataType>& type,
+      const MemoTableType& memo_table, int64_t start_offset,
+      std::shared_ptr<ArrayData>* out) {

Review Comment:
   ditto



##########
cpp/src/arrow/array/dict_internal.h:
##########
@@ -63,11 +64,10 @@ struct DictionaryTraits<BooleanType> {
   using T = BooleanType;
   using MemoTableType = typename HashTraits<T>::MemoTableType;
 
-  static Status GetDictionaryArrayData(MemoryPool* pool,
-                                       const std::shared_ptr<DataType>& type,
-                                       const MemoTableType& memo_table,
-                                       int64_t start_offset,
-                                       std::shared_ptr<ArrayData>* out) {
+  static Result<std::shared_ptr<ArrayData>> GetDictionaryArrayData(
+      MemoryPool* pool, const std::shared_ptr<DataType>& type,
+      const MemoTableType& memo_table, int64_t start_offset,
+      std::shared_ptr<ArrayData>* out) {

Review Comment:
   can we remove this `out` ( because it's an output argument?) ?



-- 
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


[GitHub] [arrow] chrisjordansquire commented on a diff in pull request #37754: GH-36111: [C++] Refactor dict_internal.h to use Result

Posted by "chrisjordansquire (via GitHub)" <gi...@apache.org>.
chrisjordansquire commented on code in PR #37754:
URL: https://github.com/apache/arrow/pull/37754#discussion_r1330492659


##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -299,10 +300,11 @@ class DictionaryUnifierImpl : public DictionaryUnifier {
     }
 
     // Build unified dictionary array
-    std::shared_ptr<ArrayData> data;
-    RETURN_NOT_OK(DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
-                                                     0 /* start_offset */, &data));
-    *out_dict = MakeArray(data);
+    Result<std::shared_ptr<ArrayData>> data;
+    data = DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
+                                              0 /* start_offset */);
+    RETURN_NOT_OK(data.status());
+    *out_dict = MakeArray(data.ValueOrDie());

Review Comment:
   Done. 



##########
cpp/src/arrow/array/array_dict.cc:
##########
@@ -282,10 +282,11 @@ class DictionaryUnifierImpl : public DictionaryUnifier {
     *out_type = arrow::dictionary(index_type, value_type_);
 
     // Build unified dictionary array
-    std::shared_ptr<ArrayData> data;
-    RETURN_NOT_OK(DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
-                                                     0 /* start_offset */, &data));
-    *out_dict = MakeArray(data);
+    Result<std::shared_ptr<ArrayData>> data;
+    data = DictTraits::GetDictionaryArrayData(pool_, value_type_, memo_table_,
+                                              0 /* start_offset */);
+    RETURN_NOT_OK(data.status());
+    *out_dict = MakeArray(data.ValueOrDie());

Review Comment:
   Done. 



-- 
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