felipecrv commented on code in PR #35345:
URL: https://github.com/apache/arrow/pull/35345#discussion_r1317968901


##########
cpp/src/arrow/array/builder_base.cc:
##########
@@ -319,10 +324,30 @@ struct DerefConstIterator {
   pointer operator->() const { return &(**it); }
 };
 
+/// If A and B are equivalent types, a builder of type A can receive
+/// scalar values of type B and a builder of type B can receive
+/// scalar values of type A.
+///
+/// \param a Type A.
+/// \param b Type B.
+bool AreScalarTypesEquivalent(const DataType& a, const DataType& b) {
+  if (a.Equals(b)) {
+    return true;
+  }
+  if ((a.id() == Type::LIST && b.id() == Type::LIST_VIEW) ||
+      (a.id() == Type::LIST_VIEW && b.id() == Type::LIST) ||
+      (a.id() == Type::LARGE_LIST && b.id() == Type::LARGE_LIST_VIEW) ||
+      (a.id() == Type::LARGE_LIST_VIEW && b.id() == Type::LARGE_LIST)) {
+    return checked_cast<const BaseListType&>(a).value_type()->Equals(
+        *checked_cast<const BaseListType&>(b).value_type());
+  }
+  return false;
+}
+
 }  // namespace
 
 Status ArrayBuilder::AppendScalar(const Scalar& scalar, int64_t n_repeats) {
-  if (!scalar.type->Equals(type())) {
+  if (!AreScalarTypesEquivalent(*scalar.type, *type())) {

Review Comment:
   This simplified work I was doing in compute kernels tremendously. I think 
that if since we have different physical representation for the same logical 
types we should start thinking about these conversions. Perhaps not in the 
ad-hoc way I've done here but with a more robust and general type-checking 
algorithm.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to