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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to