Skip to content
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

[C++] is_binary_like_type<T> template condition fails to compile because missing T::is_utf8 member #45817

Open
kszucs opened this issue Mar 17, 2025 · 2 comments

Comments

@kszucs
Copy link
Member

kszucs commented Mar 17, 2025

Describe the bug, including details regarding any error messages, version, and platform.

Tried to use template condition in the following code snippet:

  std::vector<Chunk> GetChunks(const int16_t* def_levels, const int16_t* rep_levels,
                               int64_t num_levels, const ::arrow::Array& values) {
    auto handle_type = [&](auto&& type) -> std::vector<Chunk> {
      using ArrowType = std::decay_t<decltype(type)>;

      if constexpr (::arrow::is_binary_like_type<ArrowType>::value) {
        return CalculateBinaryLike<::arrow::BinaryArray>(def_levels, rep_levels,
                                                         num_levels, values);
      } else {
        throw ParquetException("Unsupported Arrow array type " +
                               values.type()->ToString());
      }
    };
    return ::arrow::VisitType(*values.type(), handle_type);
  }

but getting compiler error:

/Users/kszucs/Workspace/arrow/cpp/src/arrow/type_traits.h:719:70: error: no member named 'is_utf8' in 'arrow::Time64Type'
  719 |     std::integral_constant<bool, is_base_binary_type<T>::value && T::is_utf8>;
      |                                                                   ~~~^
/Users/kszucs/Workspace/arrow/cpp/src/arrow/type_traits.h:744:36: note: in instantiation of template type alias 'is_string_like_type' requested here
  744 |                                   !is_string_like_type<T>::value) ||
      |                                    ^
/Users/kszucs/Workspace/arrow/cpp/src/parquet/chunker_internal.cc:291:30: note: in instantiation of template type alias 'is_binary_like_type' requested here
  291 |       if constexpr (::arrow::is_binary_like_type<ArrowType>::value) {
      |                              ^
/Users/kszucs/Workspace/arrow/cpp/src/arrow/visit_type_inline.h:84:34: note: in instantiation of function template specialization 'parquet::internal::ContentDefinedChunker::Impl::GetChunks(const int16_t *, const int16_t *, int64_t, const ::arrow::Array &)::(anonymous class)::operator()<const arrow::Time64Type &>' requested here
   84 |     ARROW_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
      |                                  ^
/Users/kszucs/Workspace/arrow/cpp/src/parquet/chunker_internal.cc:299:21: note: in instantiation of function template specialization 'arrow::VisitType<(lambda at /Users/kszucs/Workspace/arrow/cpp/src/parquet/chunker_internal.cc:285:24) &>' requested here
  299 |     return ::arrow::VisitType(*values.type(), handle_type);

Seems like this condition cannot be used on its own without further specifying the type.

Component(s)

C++

@pitrou
Copy link
Member

pitrou commented Mar 17, 2025

Hmm, that is certainly annoying. @bkietz Could you think of an alternative way of spelling this?

@kszucs
Copy link
Member Author

kszucs commented Mar 17, 2025

Also the type_id functions are not always consistently named with the template conditions, see:

/// \brief Check for a binary-like type (i.e. with 32-bit offsets)
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a binary-like type one
constexpr bool is_binary_like(Type::type type_id) {
  switch (type_id) {
    case Type::BINARY:
    case Type::STRING:
      return true;
    default:
      break;
  }
  return false;
}

and the identically named:

template <typename T>
using is_binary_like_type =
    std::integral_constant<bool, (is_base_binary_type<T>::value &&
                                  !is_string_like_type<T>::value) ||
                                     is_fixed_size_binary_type<T>::value>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants