Skip to content

Commit 2e4eff5

Browse files
committed
DPL: Simplify persist further
1 parent 803ecbd commit 2e4eff5

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

Framework/Core/include/Framework/TableBuilder.h

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ auto makeHolders(arrow::MemoryPool* pool, size_t nRows)
623623
template <typename... ARGS>
624624
using IndexedHoldersTuple = decltype(makeHolderTypes<ARGS...>());
625625

626+
template <typename T>
627+
concept ShouldNotDeconstruct = std::is_bounded_array_v<T> || std::is_arithmetic_v<T> || framework::is_base_of_template_v<std::vector, T>;
628+
626629
/// Helper class which creates a lambda suitable for building
627630
/// an arrow table from a tuple. This can be used, for example
628631
/// to build an arrow::Table from a TDataFrame.
@@ -662,21 +665,15 @@ class TableBuilder
662665

663666
public:
664667
template <typename ARG0, typename... ARGS>
665-
requires(sizeof...(ARGS) == 0)
668+
requires(sizeof...(ARGS) == 0) && (!ShouldNotDeconstruct<ARG0>)
666669
static constexpr int countColumns()
667670
{
668-
if constexpr (std::is_bounded_array_v<ARG0> == false &&
669-
std::is_arithmetic_v<ARG0> == false &&
670-
framework::is_base_of_template_v<std::vector, ARG0> == false) {
671-
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
672-
return framework::pack_size(argsPack_t{});
673-
} else {
674-
return 1;
675-
}
671+
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
672+
return framework::pack_size(argsPack_t{});
676673
}
677674

678675
template <typename ARG0, typename... ARGS>
679-
requires(sizeof...(ARGS) > 0)
676+
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
680677
static constexpr int countColumns()
681678
{
682679
return 1 + sizeof...(ARGS);
@@ -698,7 +695,7 @@ class TableBuilder
698695
/// Creates a lambda which is suitable to persist things
699696
/// in an arrow::Table
700697
template <typename ARG0, typename... ARGS>
701-
requires(sizeof...(ARGS) > 0)
698+
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
702699
auto persist(std::array<char const*, sizeof...(ARGS) + 1> const& columnNames)
703700
{
704701
auto persister = persistTuple(framework::pack<ARG0, ARGS...>{}, columnNames);
@@ -711,31 +708,15 @@ class TableBuilder
711708
// Special case for a single parameter to handle the serialization of struct
712709
// which can be decomposed
713710
template <typename ARG0, typename... ARGS>
714-
requires(sizeof...(ARGS) == 0)
711+
requires(sizeof...(ARGS) == 0) && (!ShouldNotDeconstruct<ARG0>)
715712
auto persist(std::array<char const*, countColumns<ARG0, ARGS...>()> const& columnNames)
716713
{
717-
if constexpr (std::is_bounded_array_v<ARG0> == false &&
718-
std::is_arithmetic_v<ARG0> == false &&
719-
framework::is_base_of_template_v<std::vector, ARG0> == false) {
720-
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
721-
auto persister = persistTuple(argsPack_t{}, columnNames);
722-
return [persister = persister](unsigned int slot, ARG0 const& obj) -> void {
723-
auto t = to_tuple(obj);
724-
persister(slot, t);
725-
};
726-
} else if constexpr ((std::is_bounded_array_v<ARG0> == true ||
727-
framework::is_base_of_template_v<std::vector, ARG0> == true)) {
728-
auto persister = persistTuple(framework::pack<ARG0>{}, columnNames);
729-
// Callback used to fill the builders
730-
return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const& arg) -> void {
731-
persister(slot, std::forward_as_tuple(arg));
732-
};
733-
} else {
734-
auto persister = persistTuple(framework::pack<ARG0>{}, columnNames);
735-
return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const& arg) -> void {
736-
persister(slot, std::forward_as_tuple(arg));
737-
};
738-
}
714+
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
715+
auto persister = persistTuple(argsPack_t{}, columnNames);
716+
return [persister = persister](unsigned int slot, ARG0 const& obj) -> void {
717+
auto t = to_tuple(obj);
718+
persister(slot, t);
719+
};
739720
}
740721

741722
/// Same a the above, but use a tuple to persist stuff.

0 commit comments

Comments
 (0)