You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2025/02/05 12:27:22 UTC

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

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