Skip to content

Commit

Permalink
apacheGH-39050: [C++] Use Cast() instead of CastTo() for Timestamp Sc…
Browse files Browse the repository at this point in the history
…alar in test (apache#39060)

### Rationale for this change

Remove legacy code

### What changes are included in this PR?

* Replace the legacy scalar CastTo implementation for Timestamp Scalar in test. The cast function already supports casting between different timestamp types. We just need to allow for the possibility of data loss by using `CastOptions::Unsafe()`. 

### Are these changes tested?

Yes. It is passed by existing test cases.

### Are there any user-facing changes?

No.

* Closes: apache#39050

Authored-by: Hyunseok Seo <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
llama90 authored Dec 5, 2023
1 parent 6958f21 commit c39a223
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cpp/src/arrow/scalar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "arrow/array.h"
#include "arrow/array/util.h"
#include "arrow/buffer.h"
#include "arrow/compute/cast.h"
#include "arrow/memory_pool.h"
#include "arrow/scalar.h"
#include "arrow/status.h"
Expand All @@ -40,6 +41,9 @@

namespace arrow {

using compute::Cast;
using compute::CastOptions;

using internal::checked_cast;
using internal::checked_pointer_cast;

Expand Down Expand Up @@ -862,9 +866,9 @@ TEST(TestTimestampScalars, MakeScalar) {

TEST(TestTimestampScalars, Cast) {
auto convert = [](TimeUnit::type in, TimeUnit::type out, int64_t value) -> int64_t {
auto scalar =
TimestampScalar(value, timestamp(in)).CastTo(timestamp(out)).ValueOrDie();
return internal::checked_pointer_cast<TimestampScalar>(scalar)->value;
EXPECT_OK_AND_ASSIGN(auto casted, Cast(TimestampScalar(value, timestamp(in)),
timestamp(out), CastOptions::Unsafe()));
return internal::checked_pointer_cast<TimestampScalar>(casted.scalar())->value;
};

EXPECT_EQ(convert(TimeUnit::SECOND, TimeUnit::MILLI, 1), 1000);
Expand Down

0 comments on commit c39a223

Please sign in to comment.