You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mapleFU (via GitHub)" <gi...@apache.org> on 2025/01/28 17:23:46 UTC

[PR] GH-45362: [C++] Fix Identity cast for time scalar [arrow]

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

   <!--
   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}
   
   -->
   
   ### 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.  
   -->
   
   See https://github.com/apache/arrow/issues/45362
   
   ### What changes are included in this PR?
   
   <!--
   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.
   -->
   
   The pr https://github.com/apache/arrow/pull/40237 introduce code:
   
   ```
   // time to time
   template <typename To, typename From, typename T = typename To::TypeClass>
   ```
   
   However, the `Time64Type::TypeClass` doesn't exists, so SFINAE always failed.
   
   ### Are these changes tested?
   
   <!--
   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)?
   -->
   
   Yes
   
   ### Are there any user-facing changes?
   
   bugfix 
   
   <!--
   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-45362: [C++] Fix Identity cast for time scalar [arrow]

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

   :warning: GitHub issue #45362 **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


Re: [PR] GH-45362: [C++] Fix identity cast for time and list scalar [arrow]

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


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,45 @@ TEST(TestBooleanScalar, Cast) {
   }
 }
 
+TEST(TestScalar, IndentityCast) {
+  random::RandomArrayGenerator gen(/*seed=*/42);
+  auto test_identity_cast_for_type = [&gen](const std::shared_ptr<arrow::DataType>& data_type) {
+    auto tmp_array = gen.ArrayOf(data_type, /*size=*/1, /*null_probability=*/0.0);
+    ARROW_SCOPED_TRACE("data type = ", data_type->ToString());
+    ASSERT_OK_AND_ASSIGN(auto scalar, tmp_array->GetScalar(0));
+    ASSERT_OK_AND_ASSIGN(auto casted_scalar, scalar->CastTo(data_type));
+    ASSERT_TRUE(casted_scalar->Equals(*scalar));
+    ASSERT_TRUE(scalar->Equals(*casted_scalar));
+  };
+  for (auto& type: PrimitiveTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: DurationTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: IntervalTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: {
+    arrow::fixed_size_list(arrow::int32(), 20),
+    arrow::list(arrow::int32()),
+    // arrow::map(arrow::binary(), arrow::int32()),
+    // struct_({field("float", arrow::float32())}),
+  }) {
+    test_identity_cast_for_type(type);
+  }
+  /*
+  for (auto& type: {

Review Comment:
   Added, but seems previous issue wants to deprecate them, I think these issues may also be mark as not planned, 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-45362: [C++] Fix identity cast for time and list scalar [arrow]

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


-- 
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-45362: [C++] Fix identity cast for time and list scalar [arrow]

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

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit d9e7fa67c3a6b2c88554bf30ee1865c707e7712b.
   
   There were 8 benchmark results with an error:
   
   - Commit Run on `arm64-t4g-2xlarge-linux` at [2025-02-05 15:07:01Z](https://conbench.ursa.dev/compare/runs/1654bfae998e46d6a23da2cf12ab3df3...168bdd94bc0d4c188a45298938f1e26e/)
     - [`tpch` (R) with engine=arrow, format=native, language=R, memory_map=False, query_id=TPCH-03, scale_factor=1](https://conbench.ursa.dev/benchmark-results/067a38d6a36c7f7d8000006553ce1908)
     - [`tpch` (R) with engine=arrow, format=parquet, language=R, memory_map=False, query_id=TPCH-03, scale_factor=1](https://conbench.ursa.dev/benchmark-results/067a38d7a594738880008fc5d88ac9bb)
   - and 6 more (see the report linked below)
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/36746697008) has more details. It also includes information about 4 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-45362: [C++] Fix identity cast for time and list scalar [arrow]

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


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,45 @@ TEST(TestBooleanScalar, Cast) {
   }
 }
 
+TEST(TestScalar, IndentityCast) {
+  random::RandomArrayGenerator gen(/*seed=*/42);
+  auto test_identity_cast_for_type = [&gen](const std::shared_ptr<arrow::DataType>& data_type) {
+    auto tmp_array = gen.ArrayOf(data_type, /*size=*/1, /*null_probability=*/0.0);
+    ARROW_SCOPED_TRACE("data type = ", data_type->ToString());
+    ASSERT_OK_AND_ASSIGN(auto scalar, tmp_array->GetScalar(0));
+    ASSERT_OK_AND_ASSIGN(auto casted_scalar, scalar->CastTo(data_type));
+    ASSERT_TRUE(casted_scalar->Equals(*scalar));
+    ASSERT_TRUE(scalar->Equals(*casted_scalar));
+  };
+  for (auto& type: PrimitiveTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: DurationTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: IntervalTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: {
+    arrow::fixed_size_list(arrow::int32(), 20),
+    arrow::list(arrow::int32()),
+    // arrow::map(arrow::binary(), arrow::int32()),
+    // struct_({field("float", arrow::float32())}),
+  }) {
+    test_identity_cast_for_type(type);
+  }
+  /*
+  for (auto& type: {

Review Comment:
   Can we open issues for the missing casts?



##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,45 @@ TEST(TestBooleanScalar, Cast) {
   }
 }
 
+TEST(TestScalar, IndentityCast) {

Review Comment:
   Nit :)
   ```suggestion
   TEST(TestScalar, IdentityCast) {
   ```



-- 
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-45362: [C++] Fix Identity cast for time scalar [arrow]

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

   Windows CI failed seems to be related.


-- 
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-45362: [C++] Fix identity cast for time scalar [arrow]

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


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -866,6 +866,9 @@ TEST(TestTimeScalars, Basics) {
     ASSERT_TRUE(first->Equals(*MakeScalar(ty, 5).ValueOrDie()));
     ASSERT_TRUE(last->Equals(*MakeScalar(ty, 42).ValueOrDie()));
     ASSERT_FALSE(last->Equals(*MakeScalar("string")));
+
+    ASSERT_OK_AND_ASSIGN(auto casted, first->CastTo(ty));
+    ASSERT_TRUE(casted->Equals(*first));

Review Comment:
   Can we create a generic test for identity cast instead? Something like:
   ```c++
   TEST(TestIdentityCast, AllTypes) {
     RandomArrayGenerator rng(/*seed=*/42);
     for (auto type : {...}) {
       ASSERT_OK_AND_ASSIGN(
           auto scalar, rng.ArrayOf(type, /*size=*/1).GetScalar(0));
       ASSERT_OK_AND_ASSIGN(auto casted, scalar->CastTo(ty));
       ASSERT_TRUE(casted->Equals(*scalar));
     }
   }
   ```



-- 
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-45362: [C++] Fix Identity cast for time scalar [arrow]

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

   Also cc @pitrou since this is new year and @zanmato1984 might not have time for 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-45362: [C++] Fix identity cast for time scalar [arrow]

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


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,45 @@ TEST(TestBooleanScalar, Cast) {
   }
 }
 
+TEST(TestScalar, IndentityCast) {
+  random::RandomArrayGenerator gen(/*seed=*/42);
+  auto test_identity_cast_for_type = [&gen](const std::shared_ptr<arrow::DataType>& data_type) {
+    auto tmp_array = gen.ArrayOf(data_type, /*size=*/1, /*null_probability=*/0.0);
+    ARROW_SCOPED_TRACE("data type = ", data_type->ToString());
+    ASSERT_OK_AND_ASSIGN(auto scalar, tmp_array->GetScalar(0));
+    ASSERT_OK_AND_ASSIGN(auto casted_scalar, scalar->CastTo(data_type));
+    ASSERT_TRUE(casted_scalar->Equals(*scalar));
+    ASSERT_TRUE(scalar->Equals(*casted_scalar));
+  };
+  for (auto& type: PrimitiveTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: DurationTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: IntervalTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: {
+    arrow::fixed_size_list(arrow::int32(), 20),
+    arrow::list(arrow::int32()),
+    // arrow::map(arrow::binary(), arrow::int32()),
+    // struct_({field("float", arrow::float32())}),

Review Comment:
   struct and map seems not supports castTo non string types



##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,45 @@ TEST(TestBooleanScalar, Cast) {
   }
 }
 
+TEST(TestScalar, IndentityCast) {
+  random::RandomArrayGenerator gen(/*seed=*/42);
+  auto test_identity_cast_for_type = [&gen](const std::shared_ptr<arrow::DataType>& data_type) {
+    auto tmp_array = gen.ArrayOf(data_type, /*size=*/1, /*null_probability=*/0.0);
+    ARROW_SCOPED_TRACE("data type = ", data_type->ToString());
+    ASSERT_OK_AND_ASSIGN(auto scalar, tmp_array->GetScalar(0));
+    ASSERT_OK_AND_ASSIGN(auto casted_scalar, scalar->CastTo(data_type));
+    ASSERT_TRUE(casted_scalar->Equals(*scalar));
+    ASSERT_TRUE(scalar->Equals(*casted_scalar));
+  };
+  for (auto& type: PrimitiveTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: DurationTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: IntervalTypes()) {
+    test_identity_cast_for_type(type);
+  }
+  for (auto& type: {
+    arrow::fixed_size_list(arrow::int32(), 20),
+    arrow::list(arrow::int32()),
+    // arrow::map(arrow::binary(), arrow::int32()),
+    // struct_({field("float", arrow::float32())}),
+  }) {
+    test_identity_cast_for_type(type);
+  }
+  /*
+  for (auto& type: {

Review Comment:
   decimal seems not have castTo



-- 
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-45362: [C++] Fix identity cast for time scalar [arrow]

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


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -866,6 +866,9 @@ TEST(TestTimeScalars, Basics) {
     ASSERT_TRUE(first->Equals(*MakeScalar(ty, 5).ValueOrDie()));
     ASSERT_TRUE(last->Equals(*MakeScalar(ty, 42).ValueOrDie()));
     ASSERT_FALSE(last->Equals(*MakeScalar("string")));
+
+    ASSERT_OK_AND_ASSIGN(auto casted, first->CastTo(ty));
+    ASSERT_TRUE(casted->Equals(*first));

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