- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.9k
ARROW-11932: [C++] Implement ArrayBuilder::AppendScalar #10579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
        
          
                cpp/src/arrow/array/builder_base.h
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also suggest the overload AppendScalar(const Scalar& scalat, int64_t nrepeats) to append the same scalar a number of times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've added the overload.
| Hmm, it looks like the implementation could be more optimized. When appending multiple scalars (or multiple times the same scalars), the required space could be reserved. Also, at least for primitive types, I would expect appending multiple scalars to be much more streamlined than this. (it looks like such optimizations could be crafted more easily if  Perhaps create a TODO JIRA for those optimizations, unless you would like to work on them on this PR. | 
| I changed it to at least call Reserve() since that's simple. I filed ARROW-13197 and also noted the dictionary scalar support there. | 
| (Note: Ben left feedback on this in #10511 so I'll address that here.) | 
| Now fixed to not require allocations/not use a vector as Ben suggested. | 
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
        
          
                cpp/src/arrow/array/builder_base.cc
              
                Outdated
          
        
      | namespace { | ||
| struct AppendScalarImpl { | ||
| template <typename T> | ||
| enable_if_t<has_c_type<T>::value || is_decimal_type<T>::value, Status> Visit(const T&) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't include FixedSizeBinaryType, which doesn't require a ReserveData call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FixedSizeBinaryType didn't work with this specialization anyways, I'll go add the required Builder::Append(Buffer) call that's needed.
| This got included in #10511. | 
This repurposes the code from ScalarVectorToArray. This doesn't support dictionary scalars.