Skip to content

Commit 7ccf6fd

Browse files
authored
GH-35560: [C++] Use Cast() instead of CastTo() for Scalar in test (#39044)
### Rationale for this change Remove legacy code ### What changes are included in this PR? * Replace the legacy scalar `CastTo` implementation with the new cast compute kernel for supported types, without requiring additional casting logic for unsupported types. ### Are these changes tested? Yes. It is passed by existing test cases. ### Are there any user-facing changes? No. * Closes: #35560 Authored-by: Hyunseok Seo <hsseo0501@gmail.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 50e54b8 commit 7ccf6fd

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

cpp/src/arrow/dataset/partition_test.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "arrow/compute/api_scalar.h"
3030
#include "arrow/compute/api_vector.h"
31+
#include "arrow/compute/cast.h"
3132
#include "arrow/dataset/dataset.h"
3233
#include "arrow/dataset/file_ipc.h"
3334
#include "arrow/dataset/test_util_internal.h"
@@ -40,6 +41,8 @@
4041

4142
namespace arrow {
4243

44+
using compute::Cast;
45+
4346
using internal::checked_pointer_cast;
4447

4548
namespace dataset {
@@ -335,7 +338,7 @@ TEST_F(TestPartitioning, DirectoryPartitioningWithTemporal) {
335338
partitioning_ = std::make_shared<DirectoryPartitioning>(
336339
schema({field("year", int32()), field("month", int8()), field("day", temporal)}));
337340

338-
ASSERT_OK_AND_ASSIGN(auto day, StringScalar("2020-06-08").CastTo(temporal));
341+
ASSERT_OK_AND_ASSIGN(auto day, Cast(StringScalar("2020-06-08"), temporal));
339342
AssertParse("/2020/06/2020-06-08/",
340343
and_({equal(field_ref("year"), literal(2020)),
341344
equal(field_ref("month"), literal<int8_t>(6)),

cpp/src/arrow/scalar_test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,22 +1043,22 @@ TYPED_TEST(TestNumericScalar, Cast) {
10431043
std::shared_ptr<Scalar> other_scalar;
10441044
ASSERT_OK_AND_ASSIGN(other_scalar, Scalar::Parse(other_type, repr));
10451045

1046-
ASSERT_OK_AND_ASSIGN(auto cast_to_other, scalar->CastTo(other_type))
1047-
ASSERT_EQ(*cast_to_other, *other_scalar);
1046+
ASSERT_OK_AND_ASSIGN(auto cast_to_other, Cast(scalar, other_type))
1047+
ASSERT_EQ(*cast_to_other.scalar(), *other_scalar);
10481048

1049-
ASSERT_OK_AND_ASSIGN(auto cast_from_other, other_scalar->CastTo(type))
1050-
ASSERT_EQ(*cast_from_other, *scalar);
1049+
ASSERT_OK_AND_ASSIGN(auto cast_from_other, Cast(other_scalar, type))
1050+
ASSERT_EQ(*cast_from_other.scalar(), *scalar);
10511051
}
10521052

10531053
ASSERT_OK_AND_ASSIGN(auto cast_from_string,
1054-
StringScalar(std::string(repr)).CastTo(type));
1055-
ASSERT_EQ(*cast_from_string, *scalar);
1054+
Cast(StringScalar(std::string(repr)), type));
1055+
ASSERT_EQ(*cast_from_string.scalar(), *scalar);
10561056

10571057
if (is_integer_type<TypeParam>::value) {
1058-
ASSERT_OK_AND_ASSIGN(auto cast_to_string, scalar->CastTo(utf8()));
1059-
ASSERT_EQ(
1060-
std::string_view(*checked_cast<const StringScalar&>(*cast_to_string).value),
1061-
repr);
1058+
ASSERT_OK_AND_ASSIGN(auto cast_to_string, Cast(scalar, utf8()));
1059+
ASSERT_EQ(std::string_view(
1060+
*checked_cast<const StringScalar&>(*cast_to_string.scalar()).value),
1061+
repr);
10621062
}
10631063
}
10641064
}

0 commit comments

Comments
 (0)