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

[GitHub] [arrow] js8544 opened a new pull request, #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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

   
   <!--
   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.  
   -->
   
   Prefer TypeError over Invalid in IsIn and IndexIn kernels
   
   ### What changes are included in this PR?
   
   When casting fails, return TypeError instead of Invalid.
   
   <!--
   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)?
   -->
   
   ### Are there any user-facing changes?
   
   No.
   
   <!--
   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] js8544 commented on a diff in pull request #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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


##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -326,9 +326,13 @@ struct IndexInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
     if (!data.type->Equals(state.value_set_type)) {
       auto materialized_input = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_input,
-                            Cast(*materialized_input, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

Review Comment:
   Done.



##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -423,11 +427,15 @@ struct IsInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
 
     if (!data.type->Equals(state.value_set_type)) {
-      auto materialized_data = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_data,
-                            Cast(*materialized_data, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
-      return ProcessIsIn(state, *casted_data.array());
+      auto materialized_input = data.ToArrayData();
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

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] js8544 commented on pull request #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on PR #36358:
URL: https://github.com/apache/arrow/pull/36358#issuecomment-1611715699

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


[GitHub] [arrow] pitrou commented on pull request #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #36358:
URL: https://github.com/apache/arrow/pull/36358#issuecomment-1613334978

   Thanks @js8544 !


-- 
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 #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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

   Conbench analyzed the 6 benchmark runs on commit `2455bc07`.
   
   There were 5 benchmark results indicating a performance regression:
   
   - Commit Run on `ursa-thinkcentre-m75q` at [2023-07-02 22:10:35Z](http://conbench.ursa.dev/compare/runs/2268b4b12fe94d58bf8dbaf93e2d4b47...237b048541ce4094b083bd3b1305b68c/)
     - [params=<TimeUnit::SECOND>, source=cpp-micro, suite=arrow-value-parsing-benchmark](http://conbench.ursa.dev/compare/benchmarks/064a1cc1f1d77ff480007e210a64aaf5...064a1f623c38787a8000f44572764422)
     - [params=<MultiplyChecked, UInt16Type>/size:524288/inverse_null_proportion:0, source=cpp-micro, suite=arrow-compute-scalar-arithmetic-benchmark](http://conbench.ursa.dev/compare/benchmarks/064a1cc38c8d7ff78000d99c5f747ed8...064a1f63b8da7dd180008b2759c4944f)
   - and 3 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/14775871819) has more details.


-- 
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 #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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

   :warning: GitHub issue #36345 **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] pitrou commented on a diff in pull request #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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


##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -326,9 +326,13 @@ struct IndexInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
     if (!data.type->Equals(state.value_set_type)) {
       auto materialized_input = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_input,
-                            Cast(*materialized_input, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

Review Comment:
   Well, we want to keep the original error. This is precisely to distinguish the different kinds of errors:
   * `TypeError`: casting from type X to type Y is not supported at all
   * `Invalid`: casting from type X to type Y _is_ supported, but the actual values fail casting (e.g. because of truncation or overflow)
   



##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -326,9 +326,13 @@ struct IndexInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
     if (!data.type->Equals(state.value_set_type)) {
       auto materialized_input = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_input,
-                            Cast(*materialized_input, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

Review Comment:
   So you could perhaps refine this as:
   ```c++
         if (!cast_result.ok()) {
           if (cast_result.IsNotImplemented()) {
             return Status::TypeError("Array type didn't match type of values set: ",
                                      *data.type, " vs ", *state.value_set_type);
           }
           return cast_result;
         }
   ```



##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -423,11 +427,15 @@ struct IsInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
 
     if (!data.type->Equals(state.value_set_type)) {
-      auto materialized_data = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_data,
-                            Cast(*materialized_data, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
-      return ProcessIsIn(state, *casted_data.array());
+      auto materialized_input = data.ToArrayData();
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

Review Comment:
   Same here of course.



##########
cpp/src/arrow/compute/kernels/scalar_set_lookup.cc:
##########
@@ -326,9 +326,13 @@ struct IndexInVisitor {
     const auto& state = checked_cast<const SetLookupState<Type>&>(*ctx->state());
     if (!data.type->Equals(state.value_set_type)) {
       auto materialized_input = data.ToArrayData();
-      ARROW_ASSIGN_OR_RAISE(auto casted_input,
-                            Cast(*materialized_input, state.value_set_type,
-                                 CastOptions::Safe(), ctx->exec_context()));
+      auto cast_result = Cast(*materialized_input, state.value_set_type,
+                              CastOptions::Safe(), ctx->exec_context());
+      if (ARROW_PREDICT_FALSE(!cast_result.ok())) {

Review Comment:
   Note that `Cast` also does the distinction, with the caveat that it returns `NotImplemented` instead of `TypeError` (which IMHO is not great):
   ```python
   >>> a = pa.array([[1000,2000], [3000]])
   >>> a.type
   ListType(list<item: int64>)
   >>> pc.cast(a, pa.list_(pa.int32()))
   <pyarrow.lib.ListArray object at 0x7f1ccf65ab60>
   [
     [
       1000,
       2000
     ],
     [
       3000
     ]
   ]
   >>> pc.cast(a, pa.list_(pa.int8()))
   [...]
   ArrowInvalid: Integer value 1000 not in range: -128 to 127
   >>> pc.cast(a, pa.utf8())
   [...]
   ArrowNotImplementedError: Unsupported cast from list<item: int64> to utf8 using function cast_string
   ```
   



-- 
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] pitrou merged pull request #36358: GH-36345: [C++] Prefer TypeError over Invalid in IsIn and IndexIn kernels

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


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