bkietz commented on a change in pull request #9490:
URL: https://github.com/apache/arrow/pull/9490#discussion_r576971785



##########
File path: cpp/src/arrow/compute/kernels/scalar_cast_test.cc
##########
@@ -475,1049 +207,821 @@ TEST_F(TestCast, CanCast) {
   ExpectCannotCast(null(), {smallint()});  // FIXME missing common cast from 
null
 }
 
-TEST_F(TestCast, SameTypeZeroCopy) {
+TEST(Cast, SameTypeZeroCopy) {
   std::shared_ptr<Array> arr = ArrayFromJSON(int32(), "[0, null, 2, 3, 4]");
   ASSERT_OK_AND_ASSIGN(std::shared_ptr<Array> result, Cast(*arr, int32()));
 
   AssertBufferSame(*arr, *result, 0);
   AssertBufferSame(*arr, *result, 1);
 }
 
-TEST_F(TestCast, ZeroChunks) {
+TEST(Cast, ZeroChunks) {
   auto chunked_i32 = std::make_shared<ChunkedArray>(ArrayVector{}, int32());
   ASSERT_OK_AND_ASSIGN(Datum result, Cast(chunked_i32, utf8()));
 
   ASSERT_EQ(result.kind(), Datum::CHUNKED_ARRAY);
   AssertChunkedEqual(*result.chunked_array(), ChunkedArray({}, utf8()));
 }
 
-TEST_F(TestCast, CastDoesNotProvideDefaultOptions) {
+TEST(Cast, CastDoesNotProvideDefaultOptions) {
   std::shared_ptr<Array> arr = ArrayFromJSON(int32(), "[0, null, 2, 3, 4]");
   ASSERT_RAISES(Invalid, CallFunction("cast", {arr}));
 }
 
-TEST_F(TestCast, FromBoolean) {
-  CastOptions options;
-
-  std::vector<bool> is_valid(20, true);
-  is_valid[3] = false;
-
-  std::vector<bool> v1(is_valid.size(), true);
-  std::vector<int32_t> e1(is_valid.size(), 1);
-  for (size_t i = 0; i < v1.size(); ++i) {
-    if (i % 3 == 1) {
-      v1[i] = false;
-      e1[i] = 0;
-    }
-  }
-
-  CheckCase<BooleanType, Int32Type>(v1, is_valid, e1, options);
+TEST(Cast, FromBoolean) {
+  std::string vals = "[1, 0, null, 1, 0, 1, 1, null, 0, 0, 1]";
+  CheckCast(ArrayFromJSON(boolean(), vals), ArrayFromJSON(int32(), vals));
 }
 
-TEST_F(TestCast, ToBoolean) {
-  CastOptions options;
+TEST(Cast, ToBoolean) {
   for (auto type : kNumericTypes) {
-    CheckCaseJSON(type, boolean(), "[0, null, 127, 1, 0]",
-                  "[false, null, true, true, false]");
+    CheckCast(ArrayFromJSON(type, "[0, null, 127, 1, 0]"),
+              ArrayFromJSON(boolean(), "[false, null, true, true, false]"));
   }
 
   // Check negative numbers
-  CheckCaseJSON(int8(), boolean(), "[0, null, 127, -1, 0]",
-                "[false, null, true, true, false]");
-  CheckCaseJSON(float64(), boolean(), "[0, null, 127, -1, 0]",
-                "[false, null, true, true, false]");
+  for (auto type : {int8(), float64()}) {
+    CheckCast(ArrayFromJSON(type, "[0, null, 127, -1, 0]"),
+              ArrayFromJSON(boolean(), "[false, null, true, true, false]"));
+  }
 }
 
-TEST_F(TestCast, ToIntUpcast) {
-  CastOptions options;
-  options.allow_int_overflow = false;
-
+TEST(Cast, ToIntUpcast) {
   std::vector<bool> is_valid = {true, false, true, true, true};
 
   // int8 to int32
-  std::vector<int8_t> v1 = {0, 1, 127, -1, 0};
-  std::vector<int32_t> e1 = {0, 1, 127, -1, 0};
-  CheckCase<Int8Type, Int32Type>(v1, is_valid, e1, options);
-
-  // bool to int8
-  std::vector<bool> v2 = {false, true, false, true, true};
-  std::vector<int8_t> e2 = {0, 1, 0, 1, 1};
-  CheckCase<BooleanType, Int8Type>(v2, is_valid, e2, options);
+  CheckCast(ArrayFromJSON(int8(), "[0, null, 127, -1, 0]"),
+            ArrayFromJSON(int32(), "[0, null, 127, -1, 0]"));
 
   // uint8 to int16, no overflow/underrun
-  std::vector<uint8_t> v3 = {0, 100, 200, 255, 0};
-  std::vector<int16_t> e3 = {0, 100, 200, 255, 0};
-  CheckCase<UInt8Type, Int16Type>(v3, is_valid, e3, options);
+  CheckCast(ArrayFromJSON(uint8(), "[0, 100, 200, 255, 0]"),
+            ArrayFromJSON(int16(), "[0, 100, 200, 255, 0]"));
 }
 
-TEST_F(TestCast, OverflowInNullSlot) {
-  CastOptions options;
-  options.allow_int_overflow = false;
-
-  std::vector<bool> is_valid = {true, false, true, true, true};
-
-  std::vector<int32_t> v11 = {0, 70000, 2000, 1000, 0};
-  std::vector<int16_t> e11 = {0, 0, 2000, 1000, 0};
-
-  std::shared_ptr<Array> expected;
-  ArrayFromVector<Int16Type>(int16(), is_valid, e11, &expected);
-
-  auto buf = Buffer::Wrap(v11.data(), v11.size());
-  Int32Array tmp11(5, buf, expected->null_bitmap(), -1);
-
-  CheckPass(tmp11, *expected, int16(), options);
+TEST(Cast, OverflowInNullSlot) {
+  CheckCast(ArrayFromJSON(int32(), "[0, null, 2000, 1000, 0]"),
+            ArrayFromJSON(int16(), "[0, null, 2000, 1000, 0]"));

Review comment:
       Will do

##########
File path: cpp/src/arrow/compute/kernels/scalar_cast_test.cc
##########
@@ -1553,221 +1057,325 @@ TEST_F(TestCast, UnsupportedTargetType) {
                                   CallFunction("cast", {arr}, &options));
 }
 
-TEST_F(TestCast, DateTimeZeroCopy) {
-  std::vector<bool> is_valid = {true, false, true, true, true};
+TEST(Cast, StringToBoolean) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    CheckCast(ArrayFromJSON(string_type, R"(["False", null, "true", "True", 
"false"])"),
+              ArrayFromJSON(boolean(), "[false, null, true, true, false]"));
 
-  std::vector<int32_t> v1 = {0, 70000, 2000, 1000, 0};
-  std::shared_ptr<Array> arr;
-  ArrayFromVector<Int32Type>(int32(), is_valid, v1, &arr);
+    CheckCast(ArrayFromJSON(string_type, R"(["0", null, "1", "1", "0"])"),
+              ArrayFromJSON(boolean(), "[false, null, true, true, false]"));
 
-  CheckZeroCopy(*arr, time32(TimeUnit::SECOND));
-  CheckZeroCopy(*arr, date32());
+    auto options = CastOptions::Safe(boolean());
+    CheckCastFails(ArrayFromJSON(string_type, R"(["false "])"), options);
+    CheckCastFails(ArrayFromJSON(string_type, R"(["T"])"), options);
+  }
+}
 
-  std::vector<int64_t> v2 = {0, 70000, 2000, 1000, 0};
-  ArrayFromVector<Int64Type>(int64(), is_valid, v2, &arr);
+TEST(Cast, StringToInt) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    for (auto signed_type : {int8(), int16(), int32(), int64()}) {
+      CheckCast(ArrayFromJSON(string_type, R"(["0", null, "127", "-1", "0"])"),
+                ArrayFromJSON(signed_type, "[0, null, 127, -1, 0]"));
+    }
 
-  CheckZeroCopy(*arr, time64(TimeUnit::MICRO));
-  CheckZeroCopy(*arr, date64());
-  CheckZeroCopy(*arr, timestamp(TimeUnit::NANO));
-  CheckZeroCopy(*arr, duration(TimeUnit::MILLI));
-}
+    CheckCast(
+        ArrayFromJSON(string_type, R"(["2147483647", null, "-2147483648", "0", 
"0"])"),
+        ArrayFromJSON(int32(), "[2147483647, null, -2147483648, 0, 0]"));
 
-TEST_F(TestCast, StringToBoolean) {
-  CastOptions options;
+    CheckCast(ArrayFromJSON(
+                  string_type,
+                  R"(["9223372036854775807", null, "-9223372036854775808", 
"0", "0"])"),
+              ArrayFromJSON(int64(),
+                            "[9223372036854775807, null, -9223372036854775808, 
0, 0]"));
 
-  std::vector<bool> is_valid = {true, false, true, true, true};
+    for (auto unsigned_type : {uint8(), uint16(), uint32(), uint64()}) {
+      CheckCast(ArrayFromJSON(string_type, R"(["0", null, "127", "255", 
"0"])"),
+                ArrayFromJSON(unsigned_type, "[0, null, 127, 255, 0]"));
+    }
 
-  std::vector<std::string> v1 = {"False", "true", "true", "True", "false"};
-  std::vector<std::string> v2 = {"0", "1", "1", "1", "0"};
-  std::vector<bool> e = {false, true, true, true, false};
-  CheckCase<StringType, BooleanType, std::string>(utf8(), v1, is_valid, 
boolean(), e,
-                                                  options);
-  CheckCase<StringType, BooleanType, std::string>(utf8(), v2, is_valid, 
boolean(), e,
-                                                  options);
+    CheckCast(
+        ArrayFromJSON(string_type, R"(["2147483647", null, "4294967295", "0", 
"0"])"),
+        ArrayFromJSON(uint32(), "[2147483647, null, 4294967295, 0, 0]"));
+
+    CheckCast(ArrayFromJSON(
+                  string_type,
+                  R"(["9223372036854775807", null, "18446744073709551615", 
"0", "0"])"),
+              ArrayFromJSON(uint64(),
+                            "[9223372036854775807, null, 18446744073709551615, 
0, 0]"));
+
+    for (std::string not_int8 : {
+             "z",
+             "12 z",
+             "128",
+             "-129",
+             "0.5",
+         }) {
+      auto options = CastOptions::Safe(int8());
+      CheckCastFails(ArrayFromJSON(string_type, "[\"" + not_int8 + "\"]"), 
options);
+    }
 
-  // Same with LargeStringType
-  CheckCase<LargeStringType, BooleanType, std::string>(v1, is_valid, e, 
options);
+    for (std::string not_uint8 : {
+             "256",
+             "-1",
+             "0.5",
+         }) {
+      auto options = CastOptions::Safe(uint8());
+      CheckCastFails(ArrayFromJSON(string_type, "[\"" + not_uint8 + "\"]"), 
options);
+    }
+  }
 }
 
-TEST_F(TestCast, StringToBooleanErrors) {
-  CastOptions options;
-
-  std::vector<bool> is_valid = {true};
+TEST(Cast, StringToFloating) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    for (auto float_type : {float32(), float64()}) {
+      auto strings =
+          ArrayFromJSON(string_type, R"(["0.1", null, "127.3", "1e3", "200.4", 
"0.5"])");
+      auto floats = ArrayFromJSON(float_type, "[0.1, null, 127.3, 1000, 200.4, 
0.5]");
+      CheckCast(strings, floats);
+
+      for (std::string not_float : {
+               "z",
+           }) {
+        auto options = CastOptions::Safe(float32());
+        CheckCastFails(ArrayFromJSON(string_type, "[\"" + not_float + "\"]"), 
options);
+      }
 
-  CheckFails<StringType>({"false "}, is_valid, boolean(), options);
-  CheckFails<StringType>({"T"}, is_valid, boolean(), options);
-  CheckFails<LargeStringType>({"T"}, is_valid, boolean(), options);
+#if !defined(_WIN32) || defined(NDEBUG)
+      // Test that casting is locale-independent
+      // French locale uses the comma as decimal point
+      LocaleGuard locale_guard("fr_FR.UTF-8");
+      CheckCast(strings, floats);
+#endif
+    }
+  }
 }
 
-TEST_F(TestCast, StringToNumber) { TestCastStringToNumber<StringType>(); }
+TEST(Cast, StringToTimestamp) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    auto strings = ArrayFromJSON(string_type, R"(["1970-01-01", null, 
"2000-02-29"])");
 
-TEST_F(TestCast, LargeStringToNumber) { 
TestCastStringToNumber<LargeStringType>(); }
+    CheckCast(strings,
+              ArrayFromJSON(timestamp(TimeUnit::SECOND), "[0, null, 
951782400]"));
 
-TEST_F(TestCast, StringToNumberErrors) {
-  CastOptions options;
+    CheckCast(strings,
+              ArrayFromJSON(timestamp(TimeUnit::MICRO), "[0, null, 
951782400000000]"));
 
-  std::vector<bool> is_valid = {true};
+    for (auto unit :
+         {TimeUnit::SECOND, TimeUnit::MILLI, TimeUnit::MICRO, TimeUnit::NANO}) 
{
+      for (std::string not_ts : {
+               "",
+               "xxx",
+           }) {
+        auto options = CastOptions::Safe(timestamp(unit));
+        CheckCastFails(ArrayFromJSON(string_type, "[\"" + not_ts + "\"]"), 
options);
+      }
+    }
+
+    // NOTE: timestamp parsing is tested comprehensively in 
parsing-util-test.cc
+  }
+}
 
-  CheckFails<StringType>({"z"}, is_valid, int8(), options);
-  CheckFails<StringType>({"12 z"}, is_valid, int8(), options);
-  CheckFails<StringType>({"128"}, is_valid, int8(), options);
-  CheckFails<StringType>({"-129"}, is_valid, int8(), options);
-  CheckFails<StringType>({"0.5"}, is_valid, int8(), options);
+static void AssertBinaryZeroCopy(std::shared_ptr<Array> lhs, 
std::shared_ptr<Array> rhs) {
+  // null bitmap and data buffers are always zero-copied
+  AssertBufferSame(*lhs, *rhs, 0);
+  AssertBufferSame(*lhs, *rhs, 2);
 
-  CheckFails<StringType>({"256"}, is_valid, uint8(), options);
-  CheckFails<StringType>({"-1"}, is_valid, uint8(), options);
+  if (offset_bit_width(lhs->type_id()) == offset_bit_width(rhs->type_id())) {
+    // offset buffer is zero copied if possible
+    AssertBufferSame(*lhs, *rhs, 1);
+    return;
+  }
 
-  CheckFails<StringType>({"z"}, is_valid, float32(), options);
+  // offset buffers are equivalent
+  ArrayVector offsets;
+  for (auto array : {lhs, rhs}) {
+    auto length = array->length();
+    auto buffer = array->data()->buffers[1];
+    offsets.push_back(offset_bit_width(array->type_id()) == 32
+                          ? *Cast(Int32Array(length, buffer), int64())
+                          : std::make_shared<Int64Array>(length, buffer));
+  }
+  AssertArraysEqual(*offsets[0], *offsets[1]);
 }
 
-TEST_F(TestCast, StringToTimestamp) { TestCastStringToTimestamp<StringType>(); 
}
+TEST(Cast, BinaryToString) {
+  for (auto bin_type : {binary(), large_binary()}) {
+    for (auto string_type : {utf8(), large_utf8()}) {
+      // empty -> empty always works
+      CheckCast(ArrayFromJSON(bin_type, "[]"), ArrayFromJSON(string_type, 
"[]"));
 
-TEST_F(TestCast, LargeStringToTimestamp) { 
TestCastStringToTimestamp<LargeStringType>(); }
+      auto invalid_utf8 = InvalidUtf8(bin_type);
 
-TEST_F(TestCast, StringToTimestampErrors) {
-  CastOptions options;
+      // invalid utf-8 masked by a null bit is not an error
+      CheckCast(MaskArrayWithNullsAt(InvalidUtf8(bin_type), {4}),
+                MaskArrayWithNullsAt(InvalidUtf8(string_type), {4}));
 
-  std::vector<bool> is_valid = {true};
+      // error: invalid utf-8
+      auto options = CastOptions::Safe(string_type);
+      CheckCastFails(invalid_utf8, options);
 
-  for (auto unit : {TimeUnit::SECOND, TimeUnit::MILLI, TimeUnit::MICRO, 
TimeUnit::NANO}) {
-    auto type = timestamp(unit);
-    CheckFails<StringType>({""}, is_valid, type, options);
-    CheckFails<StringType>({"xxx"}, is_valid, type, options);
+      // override utf-8 check
+      options.allow_invalid_utf8 = true;
+      ASSERT_OK_AND_ASSIGN(auto strings, Cast(*invalid_utf8, string_type, 
options));
+      ASSERT_RAISES(Invalid, strings->ValidateFull());
+      AssertBinaryZeroCopy(invalid_utf8, strings);
+    }
   }
 }
 
-TEST_F(TestCast, BinaryToString) { TestCastBinaryToBinary<BinaryType, 
StringType>(); }
+TEST(Cast, BinaryOrStringToBinary) {
+  for (auto from_type : {utf8(), large_utf8(), binary(), large_binary()}) {
+    for (auto to_type : {binary(), large_binary()}) {
+      // empty -> empty always works
+      CheckCast(ArrayFromJSON(from_type, "[]"), ArrayFromJSON(to_type, "[]"));
 
-TEST_F(TestCast, BinaryToLargeBinary) {
-  TestCastBinaryToBinary<BinaryType, LargeBinaryType>();
-}
+      auto invalid_utf8 = InvalidUtf8(from_type);
 
-TEST_F(TestCast, BinaryToLargeString) {
-  TestCastBinaryToBinary<BinaryType, LargeStringType>();
-}
+      // invalid utf-8 is not an error for binary
+      ASSERT_OK_AND_ASSIGN(auto strings, Cast(*invalid_utf8, to_type));
+      ASSERT_OK(strings->ValidateFull());
+      AssertBinaryZeroCopy(invalid_utf8, strings);
 
-TEST_F(TestCast, LargeBinaryToBinary) {
-  TestCastBinaryToBinary<LargeBinaryType, BinaryType>();
+      // invalid utf-8 masked by a null bit is not an error
+      CheckCast(MaskArrayWithNullsAt(InvalidUtf8(from_type), {4}),
+                MaskArrayWithNullsAt(InvalidUtf8(to_type), {4}));
+    }
+  }
 }
 
-TEST_F(TestCast, LargeBinaryToString) {
-  TestCastBinaryToBinary<LargeBinaryType, StringType>();
-}
+TEST(Cast, StringToString) {
+  for (auto from_type : {utf8(), large_utf8()}) {
+    for (auto to_type : {utf8(), large_utf8()}) {
+      // empty -> empty always works
+      CheckCast(ArrayFromJSON(from_type, "[]"), ArrayFromJSON(to_type, "[]"));
 
-TEST_F(TestCast, LargeBinaryToLargeString) {
-  TestCastBinaryToBinary<LargeBinaryType, LargeStringType>();
-}
+      auto invalid_utf8 = InvalidUtf8(from_type);
 
-TEST_F(TestCast, StringToBinary) { TestCastBinaryToBinary<StringType, 
BinaryType>(); }
+      // invalid utf-8 masked by a null bit is not an error
+      CheckCast(MaskArrayWithNullsAt(invalid_utf8, {4}),
+                MaskArrayWithNullsAt(InvalidUtf8(to_type), {4}));
 
-TEST_F(TestCast, StringToLargeBinary) {
-  TestCastBinaryToBinary<StringType, LargeBinaryType>();
+      // override utf-8 check
+      auto options = CastOptions::Safe(to_type);
+      options.allow_invalid_utf8 = true;
+      // utf-8 is not checked by Cast when the origin guarantees utf-8
+      ASSERT_OK_AND_ASSIGN(auto strings, Cast(*invalid_utf8, to_type, 
options));
+      ASSERT_RAISES(Invalid, strings->ValidateFull());
+      AssertBinaryZeroCopy(invalid_utf8, strings);
+    }
+  }
 }
 
-TEST_F(TestCast, StringToLargeString) {
-  TestCastBinaryToBinary<StringType, LargeStringType>();
-}
+TEST(Cast, IntToString) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    CheckCast(ArrayFromJSON(int8(), "[0, 1, 127, -128, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "127", "-128", 
null])"));
+
+    CheckCast(ArrayFromJSON(uint8(), "[0, 1, 255, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "255", null])"));
+
+    CheckCast(ArrayFromJSON(int16(), "[0, 1, 32767, -32768, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "32767", "-32768", 
null])"));
+
+    CheckCast(ArrayFromJSON(uint16(), "[0, 1, 65535, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "65535", null])"));
 
-TEST_F(TestCast, LargeStringToBinary) {
-  TestCastBinaryToBinary<LargeStringType, BinaryType>();
+    CheckCast(
+        ArrayFromJSON(int32(), "[0, 1, 2147483647, -2147483648, null]"),
+        ArrayFromJSON(string_type, R"(["0", "1", "2147483647", "-2147483648", 
null])"));
+
+    CheckCast(ArrayFromJSON(uint32(), "[0, 1, 4294967295, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "4294967295", null])"));
+
+    CheckCast(
+        ArrayFromJSON(int64(), "[0, 1, 9223372036854775807, 
-9223372036854775808, null]"),
+        ArrayFromJSON(
+            string_type,
+            R"(["0", "1", "9223372036854775807", "-9223372036854775808", 
null])"));
+
+    CheckCast(ArrayFromJSON(uint64(), "[0, 1, 18446744073709551615, null]"),
+              ArrayFromJSON(string_type, R"(["0", "1", "18446744073709551615", 
null])"));
+  }
 }
 
-TEST_F(TestCast, LargeStringToString) {
-  TestCastBinaryToBinary<LargeStringType, StringType>();
+TEST(Cast, FloatingToString) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    CheckCast(
+        ArrayFromJSON(float32(), "[0.0, -0.0, 1.5, -Inf, Inf, NaN, null]"),
+        ArrayFromJSON(string_type, R"(["0", "-0", "1.5", "-inf", "inf", "nan", 
null])"));
+
+    CheckCast(
+        ArrayFromJSON(float64(), "[0.0, -0.0, 1.5, -Inf, Inf, NaN, null]"),
+        ArrayFromJSON(string_type, R"(["0", "-0", "1.5", "-inf", "inf", "nan", 
null])"));
+  }
 }
 
-TEST_F(TestCast, LargeStringToLargeBinary) {
-  TestCastBinaryToBinary<LargeStringType, LargeBinaryType>();
+TEST(Cast, BooleanToString) {
+  for (auto string_type : {utf8(), large_utf8()}) {
+    CheckCast(ArrayFromJSON(boolean(), "[true, true, false, null]"),
+              ArrayFromJSON(string_type, R"(["true", "true", "false", 
null])"));
+  }
 }
 
-TEST_F(TestCast, NumberToString) { TestCastNumberToString<StringType>(); }
+TEST(Cast, ListToPrimitive) {
+  ASSERT_RAISES(NotImplemented,
+                Cast(*ArrayFromJSON(list(int8()), "[[1, 2], [3, 4]]"), 
uint8()));
 
-TEST_F(TestCast, NumberToLargeString) { 
TestCastNumberToString<LargeStringType>(); }
+  ASSERT_RAISES(
+      NotImplemented,
+      Cast(*ArrayFromJSON(list(binary()), R"([["1", "2"], ["3", "4"]])"), 
utf8()));
+}
 
-TEST_F(TestCast, BooleanToString) { TestCastBooleanToString<StringType>(); }
+TEST(Cast, ListToList) {
+  auto list_int32 = checked_pointer_cast<ListArray>(ArrayFromJSON(
+      list(int32()), "[[0], [1], null, [2, 3, 4], [5, 6], null, [], [7], [8, 
9]]"));
 
-TEST_F(TestCast, BooleanToLargeString) { 
TestCastBooleanToString<LargeStringType>(); }
+  auto list_int64 = std::make_shared<ListArray>(
+      list(int64()), list_int32->length(), list_int32->value_offsets(),
+      *Cast(*list_int32->values(), int64()), list_int32->null_bitmap());
+  ASSERT_OK(list_int64->ValidateFull());
 
-TEST_F(TestCast, ListToPrimitive) {
-  auto from_int = ArrayFromJSON(list(int8()), "[[1, 2], [3, 4]]");
-  auto from_binary = ArrayFromJSON(list(binary()), "[[\"1\", \"2\"], [\"3\", 
\"4\"]]");
+  auto list_float32 = std::make_shared<ListArray>(
+      list(float32()), list_int32->length(), list_int32->value_offsets(),
+      *Cast(*list_int32->values(), float32()), list_int32->null_bitmap());
+  ASSERT_OK(list_float32->ValidateFull());
 
-  ASSERT_RAISES(NotImplemented, Cast(*from_int, uint8()));
-  ASSERT_RAISES(NotImplemented, Cast(*from_binary, utf8()));
-}
+  CheckCast(list_int32, list_float32);
+  CheckCast(list_float32, list_int64);
+  CheckCast(list_int64, list_float32);
 
-TEST_F(TestCast, ListToList) {
-  CastOptions options;
-  std::shared_ptr<Array> offsets;
-
-  std::vector<int32_t> offsets_values = {0, 1, 2, 5, 7, 7, 8, 10};
-  std::vector<bool> offsets_is_valid = {true, true, true, true, false, true, 
true, true};
-  ArrayFromVector<Int32Type>(offsets_is_valid, offsets_values, &offsets);
-
-  std::shared_ptr<Array> int32_plain_array =
-      TestBase::MakeRandomArray<typename TypeTraits<Int32Type>::ArrayType>(10, 
2);
-  ASSERT_OK_AND_ASSIGN(auto int32_list_array,
-                       ListArray::FromArrays(*offsets, *int32_plain_array, 
pool_));
-
-  ASSERT_OK_AND_ASSIGN(std::shared_ptr<Array> int64_plain_array,
-                       Cast(*int32_plain_array, int64(), options));
-  ASSERT_OK_AND_ASSIGN(auto int64_list_array,
-                       ListArray::FromArrays(*offsets, *int64_plain_array, 
pool_));
-
-  ASSERT_OK_AND_ASSIGN(std::shared_ptr<Array> float64_plain_array,
-                       Cast(*int32_plain_array, float64(), options));
-  ASSERT_OK_AND_ASSIGN(auto float64_list_array,
-                       ListArray::FromArrays(*offsets, *float64_plain_array, 
pool_));
-
-  CheckPass(*int32_list_array, *int64_list_array, int64_list_array->type(), 
options,
-            /*check_scalar=*/false);
-  CheckPass(*int32_list_array, *float64_list_array, 
float64_list_array->type(), options,
-            /*check_scalar=*/false);
-  CheckPass(*int64_list_array, *int32_list_array, int32_list_array->type(), 
options,
-            /*check_scalar=*/false);
-  CheckPass(*int64_list_array, *float64_list_array, 
float64_list_array->type(), options,
-            /*check_scalar=*/false);
-
-  options.allow_float_truncate = true;
-  CheckPass(*float64_list_array, *int32_list_array, int32_list_array->type(), 
options,
-            /*check_scalar=*/false);
-  CheckPass(*float64_list_array, *int64_list_array, int64_list_array->type(), 
options,
-            /*check_scalar=*/false);
+  CheckCast(list_int32, list_int64);
+  CheckCast(list_float32, list_int32);
+  CheckCast(list_int64, list_int32);
 }

Review comment:
       will do




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to