15#pragma GCC diagnostic push
16#pragma GCC diagnostic ignored "-Wshadow"
18#include <arrow/builder.h>
19#include <arrow/memory_pool.h>
20#include <arrow/record_batch.h>
21#include <arrow/status.h>
22#include <arrow/table.h>
23#include <arrow/type_traits.h>
24#include <arrow/util/key_value_metadata.h>
26#pragma GCC diagnostic pop
35template <
typename TYPE,
typename C_TYPE>
36void ArrayFromVector(
const std::vector<C_TYPE>&
values, std::shared_ptr<arrow::Array>* out)
38 typename arrow::TypeTraits<TYPE>::BuilderType builder;
39 for (
size_t i = 0;
i <
values.size(); ++
i) {
40 auto status = builder.Append(
values[
i]);
43 auto status = builder.Finish(out);
53 schema = schema->WithMetadata(
54 std::make_shared<arrow::KeyValueMetadata>(
55 std::vector{std::string{
"label"}},
56 std::vector{std::string{
label}}));
59std::shared_ptr<arrow::Table>
62 bool status = mFinalizer(mArrays, mHolders);
66 assert(mSchema->num_fields() > 0 &&
"Schema needs to be non-empty");
67 return arrow::Table::Make(mSchema, mArrays);
75void TableBuilder::validate()
const
77 if (mHolders !=
nullptr) {
78 throwError(
runtime_error(
"TableBuilder::persist can only be invoked once per instance"));
84 mSchema = mSchema->WithMetadata(std::make_shared<arrow::KeyValueMetadata>(std::vector{std::string{
"label"}}, std::vector{std::string{
label}}));
87std::shared_ptr<arrow::Table>
spawnerHelper(std::shared_ptr<arrow::Table>
const& fullTable, std::shared_ptr<arrow::Schema> newSchema,
size_t nColumns,
89 std::shared_ptr<gandiva::Projector>& projector)
91 if (projector ==
nullptr) {
95 arrow::TableBatchReader reader(*fullTable);
96 std::shared_ptr<arrow::RecordBatch> batch;
98 std::vector<arrow::ArrayVector> chunks;
99 chunks.resize(nColumns);
100 std::vector<std::shared_ptr<arrow::ChunkedArray>>
arrays;
103 auto s = reader.ReadNext(&batch);
105 throw runtime_error_f(
"Cannot read batches from source table to spawn %s: %s",
name, s.ToString().c_str());
107 if (batch ==
nullptr) {
111 s = projector->Evaluate(*batch, arrow::default_memory_pool(), &
v);
113 throw runtime_error_f(
"Cannot apply projector to source table of %s: %s",
name, s.ToString().c_str());
115 }
catch (std::exception& e) {
116 throw runtime_error_f(
"Cannot apply projector to source table of %s: exception caught: %s",
name, e.what());
119 for (
auto i = 0U;
i < nColumns; ++
i) {
120 chunks[
i].emplace_back(
v.at(
i));
125 for (
auto i = 0U;
i < nColumns; ++
i) {
126 arrays.push_back(std::make_shared<arrow::ChunkedArray>(chunks[
i]));
130 return arrow::Table::Make(newSchema,
arrays);
135template class arrow::NumericBuilder<arrow::UInt8Type>;
136template class arrow::NumericBuilder<arrow::UInt32Type>;
137template class arrow::NumericBuilder<arrow::FloatType>;
138template class arrow::NumericBuilder<arrow::Int32Type>;
139template class arrow::NumericBuilder<arrow::Int8Type>;
void setLabel(const char *label)
std::shared_ptr< arrow::Table > finalize()
GLuint const GLchar * name
GLenum GLsizei GLsizei GLint * values
GLuint GLsizei const GLchar * label
std::shared_ptr< gandiva::Projector > createProjectorHelper(size_t nColumns, expressions::Projector *projectors, std::shared_ptr< arrow::Schema > schema, std::vector< std::shared_ptr< arrow::Field > > const &fields)
Defining PrimaryVertex explicitly as messageable.
void addLabelToSchema(std::shared_ptr< arrow::Schema > &schema, const char *label)
RuntimeErrorRef runtime_error(const char *)
std::shared_ptr< arrow::Table > spawnerHelper(std::shared_ptr< arrow::Table > const &fullTable, std::shared_ptr< arrow::Schema > newSchema, size_t nColumns, expressions::Projector *projectors, const char *name, std::shared_ptr< gandiva::Projector > &projector)
RuntimeErrorRef runtime_error_f(const char *,...)
A struct, containing the root of the expression tree.