Skip to content

Commit b3c66e8

Browse files
authored
DPL: Drop obsolete API (#14279)
The new plugin based mechanism does not need the bulk insertion anymore.
1 parent a850e9e commit b3c66e8

File tree

3 files changed

+4
-169
lines changed

3 files changed

+4
-169
lines changed

Framework/Core/include/Framework/TableBuilder.h

Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ class Table;
4242
class Array;
4343
} // namespace arrow
4444

45-
template <typename T>
46-
struct BulkInfo {
47-
const T ptr;
48-
size_t size;
49-
};
50-
5145
extern template class arrow::NumericBuilder<arrow::UInt8Type>;
5246
extern template class arrow::NumericBuilder<arrow::UInt32Type>;
5347
extern template class arrow::NumericBuilder<arrow::FloatType>;
@@ -200,34 +194,6 @@ struct BuilderUtils {
200194
}
201195
}
202196

203-
template <typename HolderType, typename PTR>
204-
static arrow::Status bulkAppend(HolderType& holder, size_t bulkSize, const PTR ptr)
205-
{
206-
return holder.builder->AppendValues(ptr, bulkSize, nullptr);
207-
}
208-
209-
template <typename HolderType, typename PTR>
210-
static arrow::Status bulkAppendChunked(HolderType& holder, BulkInfo<PTR> info)
211-
{
212-
// Appending nullptr is a no-op.
213-
if (info.ptr == nullptr) {
214-
return arrow::Status::OK();
215-
}
216-
if constexpr (std::is_same_v<decltype(holder.builder), std::unique_ptr<arrow::FixedSizeListBuilder>>) {
217-
if (appendToList<std::remove_pointer_t<decltype(info.ptr)>>(holder.builder, info.ptr, info.size).ok() == false) {
218-
throw runtime_error("Unable to append to column");
219-
} else {
220-
return arrow::Status::OK();
221-
}
222-
} else {
223-
if (holder.builder->AppendValues(info.ptr, info.size, nullptr).ok() == false) {
224-
throw runtime_error("Unable to append to column");
225-
} else {
226-
return arrow::Status::OK();
227-
}
228-
}
229-
}
230-
231197
template <typename HolderType, typename ITERATOR>
232198
static arrow::Status append(HolderType& holder, std::pair<ITERATOR, ITERATOR> ip)
233199
{
@@ -518,14 +484,6 @@ struct TableBuilderHelpers {
518484
return {BuilderTraits<ARGS>::make_datatype()...};
519485
}
520486

521-
template <typename... ARGS, size_t NCOLUMNS = sizeof...(ARGS)>
522-
static std::vector<std::shared_ptr<arrow::Field>> makeFields(std::array<char const*, NCOLUMNS> const& names)
523-
{
524-
char const* const* names_ptr = names.data();
525-
return {
526-
std::make_shared<arrow::Field>(*names_ptr++, BuilderMaker<ARGS>::make_datatype(), true, nullptr)...};
527-
}
528-
529487
/// Invokes the append method for each entry in the tuple
530488
template <typename... Ts, typename VALUES>
531489
static bool append(std::tuple<Ts...>& holders, VALUES&& values)
@@ -542,19 +500,6 @@ struct TableBuilderHelpers {
542500
(BuilderUtils::unsafeAppend(std::get<Ts::index>(holders), std::get<Ts::index>(values)), ...);
543501
}
544502

545-
template <typename... Ts, typename PTRS>
546-
static bool bulkAppend(std::tuple<Ts...>& holders, size_t bulkSize, PTRS ptrs)
547-
{
548-
return (BuilderUtils::bulkAppend(std::get<Ts::index>(holders), bulkSize, std::get<Ts::index>(ptrs)).ok() && ...);
549-
}
550-
551-
/// Return true if all columns are done.
552-
template <typename... Ts, typename INFOS>
553-
static bool bulkAppendChunked(std::tuple<Ts...>& holders, INFOS infos)
554-
{
555-
return (BuilderUtils::bulkAppendChunked(std::get<Ts::index>(holders), std::get<Ts::index>(infos)).ok() && ...);
556-
}
557-
558503
/// Invokes the append method for each entry in the tuple
559504
template <typename... Ts>
560505
static bool finalize(std::vector<std::shared_ptr<arrow::Array>>& arrays, std::tuple<Ts...>& holders)
@@ -575,15 +520,9 @@ constexpr auto tuple_to_pack(std::tuple<ARGS...>&&)
575520
return framework::pack<ARGS...>{};
576521
}
577522

578-
template <typename T>
579-
concept BulkInsertable = (std::integral<std::decay<T>> && !std::same_as<bool, std::decay_t<T>>);
580-
581523
template <typename T>
582524
struct InsertionTrait {
583-
static consteval DirectInsertion<T> policy()
584-
requires(!BulkInsertable<T>);
585-
static consteval CachedInsertion<T> policy()
586-
requires(BulkInsertable<T>);
525+
static consteval DirectInsertion<T> policy();
587526
using Policy = decltype(policy());
588527
};
589528

@@ -658,7 +597,9 @@ class TableBuilder
658597
template <typename... ARGS, size_t I = sizeof...(ARGS)>
659598
auto makeBuilders(std::array<char const*, I> const& columnNames, size_t nRows)
660599
{
661-
mSchema = std::make_shared<arrow::Schema>(TableBuilderHelpers::makeFields<ARGS...>(columnNames));
600+
char const* const* names_ptr = columnNames.data();
601+
mSchema = std::make_shared<arrow::Schema>(
602+
std::vector<std::shared_ptr<arrow::Field>>({std::make_shared<arrow::Field>(*names_ptr++, BuilderMaker<ARGS>::make_datatype(), true, nullptr)...}));
662603

663604
mHolders = makeHolders<ARGS...>(mMemoryPool, nRows);
664605
mFinalizer = [](std::vector<std::shared_ptr<arrow::Array>>& arrays, void* holders) -> bool {
@@ -768,45 +709,6 @@ class TableBuilder
768709
}(typename T::table_t::persistent_columns_t{});
769710
}
770711

771-
template <typename... ARGS, size_t NCOLUMNS = sizeof...(ARGS)>
772-
auto preallocatedPersist(std::array<char const*, NCOLUMNS> const& columnNames, int nRows)
773-
{
774-
constexpr size_t nColumns = NCOLUMNS;
775-
validate();
776-
mArrays.resize(nColumns);
777-
makeBuilders<ARGS...>(columnNames, nRows);
778-
779-
// Callback used to fill the builders
780-
return [holders = mHolders](unsigned int /*slot*/, typename BuilderMaker<ARGS>::FillType... args) -> void {
781-
TableBuilderHelpers::unsafeAppend(*(HoldersTupleIndexed<ARGS...>*)holders, std::forward_as_tuple(args...));
782-
};
783-
}
784-
785-
template <typename... ARGS, size_t NCOLUMNS = sizeof...(ARGS)>
786-
auto bulkPersist(std::array<char const*, NCOLUMNS> const& columnNames, size_t nRows)
787-
{
788-
validate();
789-
// Should not be called more than once
790-
mArrays.resize(NCOLUMNS);
791-
makeBuilders<ARGS...>(columnNames, nRows);
792-
793-
return [holders = mHolders](unsigned int /*slot*/, size_t batchSize, typename BuilderMaker<ARGS>::FillType const*... args) -> void {
794-
TableBuilderHelpers::bulkAppend(*(HoldersTupleIndexed<ARGS...>*)holders, batchSize, std::forward_as_tuple(args...));
795-
};
796-
}
797-
798-
template <typename... ARGS, size_t NCOLUMNS = sizeof...(ARGS)>
799-
auto bulkPersistChunked(std::array<char const*, NCOLUMNS> const& columnNames, size_t nRows)
800-
{
801-
validate();
802-
mArrays.resize(NCOLUMNS);
803-
makeBuilders<ARGS...>(columnNames, nRows);
804-
805-
return [holders = mHolders](unsigned int /*slot*/, BulkInfo<typename BuilderMaker<ARGS>::STLValueType const*>... args) -> bool {
806-
return TableBuilderHelpers::bulkAppendChunked(*(HoldersTupleIndexed<ARGS...>*)holders, std::forward_as_tuple(args...));
807-
};
808-
}
809-
810712
/// Reserve method to expand the columns as needed.
811713
template <typename... Ts>
812714
auto reserveArrays(std::tuple<Ts...>& holders, int s)

Framework/Core/test/benchmark_TableBuilder.cxx

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,6 @@ static void BM_TableBuilderScalarReserved(benchmark::State& state)
6262
BENCHMARK(BM_TableBuilderScalarReserved)->Arg(1 << 21);
6363
BENCHMARK(BM_TableBuilderScalarReserved)->Range(8, 8 << 16);
6464

65-
static void BM_TableBuilderScalarPresized(benchmark::State& state)
66-
{
67-
using namespace o2::framework;
68-
for (auto _ : state) {
69-
TableBuilder builder;
70-
auto rowWriter = builder.preallocatedPersist<float>({"x"}, state.range(0));
71-
for (auto i = 0; i < state.range(0); ++i) {
72-
rowWriter(0, 0.f);
73-
}
74-
auto table = builder.finalize();
75-
}
76-
}
77-
78-
BENCHMARK(BM_TableBuilderScalarPresized)->Arg(1 << 20);
79-
BENCHMARK(BM_TableBuilderScalarPresized)->Range(8, 8 << 16);
80-
81-
static void BM_TableBuilderScalarBulk(benchmark::State& state)
82-
{
83-
using namespace o2::framework;
84-
auto chunkSize = state.range(0) / 256;
85-
std::vector<float> buffer(chunkSize, 0.); // We assume data is chunked in blocks 256th of the total size
86-
for (auto _ : state) {
87-
TableBuilder builder;
88-
auto bulkWriter = builder.bulkPersist<float>({"x"}, state.range(0));
89-
for (auto i = 0; i < state.range(0) / chunkSize; ++i) {
90-
bulkWriter(0, chunkSize, buffer.data());
91-
}
92-
auto table = builder.finalize();
93-
}
94-
}
95-
96-
BENCHMARK(BM_TableBuilderScalarBulk)->Range(256, 1 << 20);
97-
9865
static void BM_TableBuilderSimple(benchmark::State& state)
9966
{
10067
using namespace o2::framework;

Framework/Core/test/test_TableBuilder.cxx

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,6 @@ TEST_CASE("TestTableBuilderStruct")
162162
}
163163
}
164164

165-
TEST_CASE("TestTableBuilderBulk")
166-
{
167-
using namespace o2::framework;
168-
TableBuilder builder;
169-
auto bulkWriter = builder.bulkPersist<int, int>({"x", "y"}, 10);
170-
int x[] = {0, 1, 2, 3, 4, 5, 6, 7};
171-
int y[] = {0, 1, 2, 3, 4, 5, 6, 7};
172-
173-
bulkWriter(0, 8, x, y);
174-
175-
auto table = builder.finalize();
176-
REQUIRE(table->num_columns() == 2);
177-
REQUIRE(table->num_rows() == 8);
178-
REQUIRE(table->schema()->field(0)->name() == "x");
179-
REQUIRE(table->schema()->field(1)->name() == "y");
180-
REQUIRE(table->schema()->field(0)->type()->id() == arrow::int32()->id());
181-
REQUIRE(table->schema()->field(1)->type()->id() == arrow::int32()->id());
182-
183-
for (int64_t i = 0; i < 8; ++i) {
184-
auto p = std::dynamic_pointer_cast<arrow::NumericArray<arrow::Int32Type>>(table->column(0)->chunk(0));
185-
REQUIRE(p->Value(i) == i);
186-
}
187-
}
188-
189165
TEST_CASE("TestTableBuilderMore")
190166
{
191167
using namespace o2::framework;
@@ -288,13 +264,3 @@ TEST_CASE("TestColumnCount")
288264
int count2 = TableBuilder::countColumns<float, int, char[3]>();
289265
REQUIRE(count2 == 3);
290266
}
291-
292-
TEST_CASE("TestMakeFields")
293-
{
294-
auto fields = TableBuilderHelpers::makeFields<int, float>({"i", "f"});
295-
REQUIRE(fields.size() == 2);
296-
REQUIRE(fields[0]->name() == "i");
297-
REQUIRE(fields[1]->name() == "f");
298-
REQUIRE(fields[0]->type()->name() == "int32");
299-
REQUIRE(fields[1]->type()->name() == "float");
300-
}

0 commit comments

Comments
 (0)