bkietz commented on issue #45817:
URL: https://github.com/apache/arrow/issues/45817#issuecomment-2749346599

   I've proposed it elsewhere, but a potentially much nicer way to handle type 
visitation is:
   
   ```c++
     std::vector<Chunk> GetChunks(const int16_t* def_levels, const int16_t* 
rep_levels,
                                  int64_t num_levels, const ::arrow::Array& 
values) {
       return VisitTraits(*values.type(), [&](auto t) {
         if constexpr (t.is_binary && !t.is_utf8) {
           return CalculateBinaryLike<::arrow::BinaryArray>(def_levels, 
rep_levels,
                                                            num_levels, values);
         }
         throw ParquetException("Unsupported Arrow array type " +
                                values.type()->ToString());
       });
     }
   ```
   
   Which could be implemented like:
   
   ```c++
   template <typename Visitor>
   auto VisitTraits(const DataType& type, Visitor trait_visitor) {
     return VisitType(type, [&](const auto& type) {
       using T = std::decay_t<decltype(type)>;
   
       struct Traits {
         static constexpr Type::type id = T::type_id;
   
         enum : bool {
           is_fixed_size_binary = id == Type::FIXED_SIZE_BINARY,
           is_utf8 = id == Type::STRING || id == Type::LARGE_STRING || id == 
Type::STRING_VIEW,
           /// for this visitor, we consider something binary if its array 
slots are byte spans
           is_binary = (
             id == Type::BINARY|| id == Type::LARGE_BINARY || id == 
Type::BINARY_VIEW
             || is_utf8 || is_fixed_size_binary
           ),
           // ...
         };
   
         static constexpr int bit_width = ::arrow::bit_width(id);
   
         using OffsetType = OffsetTypeOrVoid<T>;
         using CType = CTypeOrVoid<T>;
         // ...
       };
   
       return trait_visitor(Traits{});
     });
   }
   ```


-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to