You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2023/12/06 00:32:39 UTC
(arrow) branch main updated: GH-35560: [C++] Use Cast() instead of CastTo() for Scalar in test (#39044)
This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 7ccf6fd5e1 GH-35560: [C++] Use Cast() instead of CastTo() for Scalar in test (#39044)
7ccf6fd5e1 is described below
commit 7ccf6fd5e192526c90722478e462e9dff8f198bb
Author: Hyunseok Seo <hs...@gmail.com>
AuthorDate: Wed Dec 6 09:32:30 2023 +0900
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 <hs...@gmail.com>
Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
cpp/src/arrow/dataset/partition_test.cc | 5 ++++-
cpp/src/arrow/scalar_test.cc | 20 ++++++++++----------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/cpp/src/arrow/dataset/partition_test.cc b/cpp/src/arrow/dataset/partition_test.cc
index 1e93294867..7ec96929a9 100644
--- a/cpp/src/arrow/dataset/partition_test.cc
+++ b/cpp/src/arrow/dataset/partition_test.cc
@@ -28,6 +28,7 @@
#include "arrow/compute/api_scalar.h"
#include "arrow/compute/api_vector.h"
+#include "arrow/compute/cast.h"
#include "arrow/dataset/dataset.h"
#include "arrow/dataset/file_ipc.h"
#include "arrow/dataset/test_util_internal.h"
@@ -40,6 +41,8 @@
namespace arrow {
+using compute::Cast;
+
using internal::checked_pointer_cast;
namespace dataset {
@@ -335,7 +338,7 @@ TEST_F(TestPartitioning, DirectoryPartitioningWithTemporal) {
partitioning_ = std::make_shared<DirectoryPartitioning>(
schema({field("year", int32()), field("month", int8()), field("day", temporal)}));
- ASSERT_OK_AND_ASSIGN(auto day, StringScalar("2020-06-08").CastTo(temporal));
+ ASSERT_OK_AND_ASSIGN(auto day, Cast(StringScalar("2020-06-08"), temporal));
AssertParse("/2020/06/2020-06-08/",
and_({equal(field_ref("year"), literal(2020)),
equal(field_ref("month"), literal<int8_t>(6)),
diff --git a/cpp/src/arrow/scalar_test.cc b/cpp/src/arrow/scalar_test.cc
index a7ba5980fe..9d40e688f1 100644
--- a/cpp/src/arrow/scalar_test.cc
+++ b/cpp/src/arrow/scalar_test.cc
@@ -1043,22 +1043,22 @@ TYPED_TEST(TestNumericScalar, Cast) {
std::shared_ptr<Scalar> other_scalar;
ASSERT_OK_AND_ASSIGN(other_scalar, Scalar::Parse(other_type, repr));
- ASSERT_OK_AND_ASSIGN(auto cast_to_other, scalar->CastTo(other_type))
- ASSERT_EQ(*cast_to_other, *other_scalar);
+ ASSERT_OK_AND_ASSIGN(auto cast_to_other, Cast(scalar, other_type))
+ ASSERT_EQ(*cast_to_other.scalar(), *other_scalar);
- ASSERT_OK_AND_ASSIGN(auto cast_from_other, other_scalar->CastTo(type))
- ASSERT_EQ(*cast_from_other, *scalar);
+ ASSERT_OK_AND_ASSIGN(auto cast_from_other, Cast(other_scalar, type))
+ ASSERT_EQ(*cast_from_other.scalar(), *scalar);
}
ASSERT_OK_AND_ASSIGN(auto cast_from_string,
- StringScalar(std::string(repr)).CastTo(type));
- ASSERT_EQ(*cast_from_string, *scalar);
+ Cast(StringScalar(std::string(repr)), type));
+ ASSERT_EQ(*cast_from_string.scalar(), *scalar);
if (is_integer_type<TypeParam>::value) {
- ASSERT_OK_AND_ASSIGN(auto cast_to_string, scalar->CastTo(utf8()));
- ASSERT_EQ(
- std::string_view(*checked_cast<const StringScalar&>(*cast_to_string).value),
- repr);
+ ASSERT_OK_AND_ASSIGN(auto cast_to_string, Cast(scalar, utf8()));
+ ASSERT_EQ(std::string_view(
+ *checked_cast<const StringScalar&>(*cast_to_string.scalar()).value),
+ repr);
}
}
}