You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2023/06/27 11:58:38 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #36310: GH-36309: [C++] Add ability to cast between scalars of list-like types

pitrou commented on code in PR #36310:
URL: https://github.com/apache/arrow/pull/36310#discussion_r1243605216


##########
cpp/src/arrow/scalar.cc:
##########
@@ -1127,6 +1127,28 @@ Status CastImpl(const StructScalar& from, StringScalar* to) {
   return Status::OK();
 }
 
+// casts between variable-length and fixed-length list types
+template <typename ToScalar>
+enable_if_t<is_list_like_type<typename ToScalar::TypeClass>::value &&
+                ToScalar::TypeClass::type_id != Type::MAP,
+            Status>
+CastImpl(const BaseListScalar& from, ToScalar* to) {
+  DCHECK(from.type->id() == Type::LIST || from.type->id() == Type::LARGE_LIST ||
+         from.type->id() == Type::FIXED_SIZE_LIST);

Review Comment:
   Careful: `MapScalar` inherits from `BaseListScalar`. Are you sure it can't use this overload?



##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -391,6 +390,8 @@ class TestRealScalar : public ::testing::Test {
     ASSERT_TRUE(list_nan.ApproxEquals(list_other_nan, options));
   }
 
+  void TestListOf() { TestListOf<ListScalar>(list(type_)); }

Review Comment:
   And can we add a cast test between map and non-map-list-like somewhere?



##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -1135,6 +1136,25 @@ class TestListScalar : public ::testing::Test {
     ASSERT_NE(a0->hash(), b0->hash());
   }
 
+  void TestCast(ScalarType& scalar, const std::shared_ptr<DataType>& to_type) {

Review Comment:
   Can we avoid non-const refs?
   ```suggestion
     void TestCast(const ScalarType& scalar, const std::shared_ptr<DataType>& to_type) {
   ```



##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -391,6 +390,8 @@ class TestRealScalar : public ::testing::Test {
     ASSERT_TRUE(list_nan.ApproxEquals(list_other_nan, options));
   }
 
+  void TestListOf() { TestListOf<ListScalar>(list(type_)); }

Review Comment:
   Is it me, or is `TestListOf` never called with types other than plain list?



-- 
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: github-unsubscribe@arrow.apache.org

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