llama90 commented on code in PR #39353:
URL: https://github.com/apache/arrow/pull/39353#discussion_r1436210085
##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -1077,21 +1077,38 @@ std::shared_ptr<DataType>
MakeListType<FixedSizeListType>(
template <typename ScalarType>
void CheckListCast(const ScalarType& scalar, const std::shared_ptr<DataType>&
to_type) {
- EXPECT_OK_AND_ASSIGN(auto cast_scalar, scalar.CastTo(to_type));
- ASSERT_OK(cast_scalar->ValidateFull());
- ASSERT_EQ(*cast_scalar->type, *to_type);
+ EXPECT_OK_AND_ASSIGN(auto cast_scalar, Cast(scalar, to_type));
+ ASSERT_OK(cast_scalar.scalar()->ValidateFull());
+ ASSERT_EQ(*cast_scalar.scalar()->type, *to_type);
- ASSERT_EQ(scalar.is_valid, cast_scalar->is_valid);
+ ASSERT_EQ(scalar.is_valid, cast_scalar.scalar()->is_valid);
ASSERT_TRUE(scalar.is_valid);
ASSERT_ARRAYS_EQUAL(*scalar.value,
- *checked_cast<const
BaseListScalar&>(*cast_scalar).value);
+ *checked_cast<const
BaseListScalar&>(*cast_scalar.scalar()).value);
}
-void CheckInvalidListCast(const Scalar& scalar, const
std::shared_ptr<DataType>& 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.");
+ }
+}
+
+template <typename ScalarType>
+void CheckInvalidListCast(const ScalarType& scalar,
+ const std::shared_ptr<DataType>& to_type, const
StatusCode code,
const std::string& expected_message) {
- EXPECT_RAISES_WITH_CODE_AND_MESSAGE_THAT(StatusCode::Invalid,
-
::testing::HasSubstr(expected_message),
- scalar.CastTo(to_type));
+ EXPECT_RAISES_WITH_CODE_AND_MESSAGE_THAT(code,
::testing::HasSubstr(expected_message),
Review Comment:
Yes. You are correct. In the current situation, as you mentioned, both
`Invalid` and `TypeError` can occur. I think `CheckListCastError` or
`VerifyListCastFailure` would be more appropriate. What do you think?
--
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]