From 476a75a5bd49fa501a9540e57b6da05cb721ae1c Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:18:36 +0200 Subject: [PATCH] Simplify builder holders (#13384) --- .../Core/include/Framework/TableBuilder.h | 75 ++++--------------- 1 file changed, 16 insertions(+), 59 deletions(-) diff --git a/Framework/Core/include/Framework/TableBuilder.h b/Framework/Core/include/Framework/TableBuilder.h index 7de45f58d2e62..0df83bdfb0f53 100644 --- a/Framework/Core/include/Framework/TableBuilder.h +++ b/Framework/Core/include/Framework/TableBuilder.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace arrow { @@ -462,10 +463,10 @@ struct CachedInsertion { int pos = 0; }; -template typename InsertionPolicy> -struct BuilderHolder : InsertionPolicy { +template +struct BuilderHolder : P { static constexpr size_t index = I; - using Policy = InsertionPolicy; + using Policy = P; using ArrowType = typename detail::ConversionTraits::ArrowType; using BuilderType = typename arrow::TypeTraits::BuilderType; @@ -562,60 +563,16 @@ template struct is_bounded_array> : std::true_type { }; -template -struct HolderTrait { - - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; - -template -struct HolderTrait { - using Holder = BuilderHolder; -}; +template +concept BulkInsertable = (std::integral> && !std::same_as>); -template -struct HolderTrait { - using Holder = BuilderHolder; +template +struct InsertionTrait { + static consteval DirectInsertion policy() + requires(!BulkInsertable); + static consteval CachedInsertion policy() + requires(BulkInsertable); + using Policy = decltype(policy()); }; /// Helper function to convert a brace-initialisable struct to @@ -645,7 +602,7 @@ template constexpr auto makeHolderTypes() { return [](std::index_sequence) { - return std::tuple(typename HolderTrait::Holder(arrow::default_memory_pool())...); + return std::tuple(BuilderHolder::Policy>(arrow::default_memory_pool())...); }(std::make_index_sequence{}); } @@ -653,7 +610,7 @@ template auto makeHolders(arrow::MemoryPool* pool, size_t nRows) { return [pool, nRows](std::index_sequence) { - return new std::tuple(typename HolderTrait::Holder(pool, nRows)...); + return new std::tuple(BuilderHolder::Policy>(pool, nRows)...); }(std::make_index_sequence{}); } @@ -668,7 +625,7 @@ class TableBuilder static void throwError(RuntimeErrorRef const& ref); template - using HoldersTuple = typename std::tuple::Holder...>; + using HoldersTuple = typename std::tuple::Policy>...>; template using HoldersTupleIndexed = decltype(makeHolderTypes());