Skip to content

Commit 07d272b

Browse files
felipecrvpitrou
andauthored
GH-36414: [C++] Add missing type_traits.h predicate: is_var_length_list() (#36415)
### Rationale for this change `is_var_length_list_type<T>` is missing its `is_var_length_list(type_id)` counterpart. ### What changes are included in this PR? - New function - Use of `is_var_length_list_type<T>` directly (instead of using deprecated `is_base_list_type<T>` ### Are these changes tested? Yes. * Closes: #36414 Lead-authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com> Co-authored-by: Antoine Pitrou <pitrou@free.fr> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 1bfa241 commit 07d272b

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

cpp/src/arrow/ipc/writer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class RecordBatchSerializer {
404404
}
405405

406406
template <typename T>
407-
enable_if_base_list<typename T::TypeClass, Status> Visit(const T& array) {
407+
enable_if_var_size_list<typename T::TypeClass, Status> Visit(const T& array) {
408408
using offset_type = typename T::offset_type;
409409

410410
std::shared_ptr<Buffer> value_offsets;

cpp/src/arrow/testing/json_internal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class SchemaWriter {
227227

228228
template <typename T>
229229
enable_if_t<is_null_type<T>::value || is_primitive_ctype<T>::value ||
230-
is_base_binary_type<T>::value || is_base_list_type<T>::value ||
230+
is_base_binary_type<T>::value || is_var_length_list_type<T>::value ||
231231
is_struct_type<T>::value || is_run_end_encoded_type<T>::value>
232232
WriteTypeMetadata(const T& type) {}
233233

cpp/src/arrow/testing/random_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RandomArrayTest : public ::testing::TestWithParam<RandomTestParam> {
7070
}
7171

7272
bool HasList(const DataType& type) {
73-
if (is_list_like(type.id()) && type.id() != Type::FIXED_SIZE_LIST) {
73+
if (is_var_length_list(type.id())) {
7474
return true;
7575
}
7676
for (const auto& child : type.fields()) {

cpp/src/arrow/type_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,7 @@ TEST(TypesTest, TestMembership) {
18521852
TEST_PREDICATE(all_types, is_dictionary);
18531853
TEST_PREDICATE(all_types, is_fixed_size_binary);
18541854
TEST_PREDICATE(all_types, is_fixed_width);
1855+
TEST_PREDICATE(all_types, is_var_length_list);
18551856
TEST_PREDICATE(all_types, is_list_like);
18561857
TEST_PREDICATE(all_types, is_nested);
18571858
TEST_PREDICATE(all_types, is_union);

cpp/src/arrow/type_traits.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ using enable_if_list_type = enable_if_t<is_list_type<T>::value, R>;
709709

710710
template <typename T>
711711
using is_list_like_type =
712-
std::integral_constant<bool, is_base_list_type<T>::value ||
712+
std::integral_constant<bool, is_var_length_list_type<T>::value ||
713713
is_fixed_size_list_type<T>::value>;
714714

715715
template <typename T, typename R = void>
@@ -1179,6 +1179,22 @@ constexpr bool is_fixed_width(Type::type type_id) {
11791179
return is_primitive(type_id) || is_dictionary(type_id) || is_fixed_size_binary(type_id);
11801180
}
11811181

1182+
/// \brief Check for a variable-length list type
1183+
///
1184+
/// \param[in] type_id the type-id to check
1185+
/// \return whether type-id is a variable-length list type one
1186+
constexpr bool is_var_length_list(Type::type type_id) {
1187+
switch (type_id) {
1188+
case Type::LIST:
1189+
case Type::LARGE_LIST:
1190+
case Type::MAP:
1191+
return true;
1192+
default:
1193+
break;
1194+
}
1195+
return false;
1196+
}
1197+
11821198
/// \brief Check for a list-like type
11831199
///
11841200
/// \param[in] type_id the type-id to check
@@ -1484,6 +1500,16 @@ static inline bool is_fixed_width(const DataType& type) {
14841500
return is_fixed_width(type.id());
14851501
}
14861502

1503+
/// \brief Check for a variable-length list type
1504+
///
1505+
/// \param[in] type the type to check
1506+
/// \return whether type is a variable-length list type
1507+
///
1508+
/// Convenience for checking using the type's id
1509+
static inline bool is_var_length_list(const DataType& type) {
1510+
return is_var_length_list(type.id());
1511+
}
1512+
14871513
/// \brief Check for a list-like type
14881514
///
14891515
/// \param[in] type the type to check

0 commit comments

Comments
 (0)