bkietz commented on code in PR #35345:
URL: https://github.com/apache/arrow/pull/35345#discussion_r1318531647
##########
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:
I'm not opposed to the conversion, just to making it a property of the
builder. I think if things do break then it'd be possible to recover
functionality by extracting the conversion to `template <typename S> Result<S>
EquivalentCast(const Scalar&);` (or maybe being more formal and adding
`Scalar::View`) and calling that before AppendScalar
--
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]