kou commented on code in PR #39353:
URL: https://github.com/apache/arrow/pull/39353#discussion_r1439006759
##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -1087,11 +1088,28 @@ void CheckListCast(const ScalarType& scalar, const
std::shared_ptr<DataType>& to
*checked_cast<const
BaseListScalar&>(*cast_scalar).value);
}
-void CheckInvalidListCast(const Scalar& scalar, const
std::shared_ptr<DataType>& to_type,
- const std::string& expected_message) {
- EXPECT_RAISES_WITH_CODE_AND_MESSAGE_THAT(StatusCode::Invalid,
-
::testing::HasSubstr(expected_message),
- scalar.CastTo(to_type));
+std::tuple<StatusCode, std::string> GetExpectedError(
+ const std::shared_ptr<DataType>& type,
+ const std::shared_ptr<DataType>& invalidCastType) {
+ if (type->id() == Type::FIXED_SIZE_LIST) {
+ return std::make_tuple(
+ StatusCode::TypeError,
+ "Size of FixedSizeList is not the same. input list: " +
type->ToString() +
+ " output list: " + invalidCastType->ToString());
+ } else {
+ return std::make_tuple(
+ StatusCode::Invalid,
+ "ListType can only be casted to FixedSizeListType if the lists are all
the "
+ "expected size.");
+ }
+}
Review Comment:
Ah, sorry. Can we use `Scalar::type` instead of passing `from_type`?
```diff
diff --git a/cpp/src/arrow/scalar_test.cc b/cpp/src/arrow/scalar_test.cc
index 654e0510c6..8592765adc 100644
--- a/cpp/src/arrow/scalar_test.cc
+++ b/cpp/src/arrow/scalar_test.cc
@@ -1090,14 +1090,13 @@ void CheckListCast(const ScalarType& scalar, const
std::shared_ptr<DataType>& to
template <typename ScalarType>
void CheckListCastError(const ScalarType& scalar,
- const std::shared_ptr<DataType>& from_type,
const std::shared_ptr<DataType>& to_type) {
StatusCode code;
std::string expected_message;
- if (from_type->id() == Type::FIXED_SIZE_LIST) {
+ if (scalar.type->id() == Type::FIXED_SIZE_LIST) {
code = StatusCode::TypeError;
expected_message =
- "Size of FixedSizeList is not the same. input list: " +
from_type->ToString() +
+ "Size of FixedSizeList is not the same. input list: " +
scalar.type->ToString() +
" output list: " + to_type->ToString();
} else {
code = StatusCode::Invalid;
@@ -1195,7 +1194,7 @@ class TestListLikeScalar : public ::testing::Test {
scalar, fixed_size_list(value_->type(),
static_cast<int32_t>(value_->length())));
auto invalid_cast_type = fixed_size_list(value_->type(), 5);
- CheckListCastError(scalar, type_, invalid_cast_type);
+ CheckListCastError(scalar, invalid_cast_type);
}
protected:
@@ -1253,7 +1252,7 @@ TEST(TestMapScalar, Cast) {
CheckListCast(scalar, fixed_size_list(key_value_type, 2));
auto invalid_cast_type = fixed_size_list(key_value_type, 5);
- CheckListCastError(scalar, scalar.type, invalid_cast_type);
+ CheckListCastError(scalar, invalid_cast_type);
}
TEST(TestStructScalar, FieldAccess) {
```
--
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]