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,
92 arrow::TableBatchReader reader(*fullTable);
93 std::shared_ptr<arrow::RecordBatch> batch;
95 std::vector<arrow::ArrayVector> chunks;
96 chunks.resize(nColumns);
97 std::vector<std::shared_ptr<arrow::ChunkedArray>>
arrays;
100 auto s = reader.ReadNext(&batch);
102 throw runtime_error_f(
"Cannot read batches from source table to spawn %s: %s",
name, s.ToString().c_str());
104 if (batch ==
nullptr) {
108 s = mergedProjectors->Evaluate(*batch, arrow::default_memory_pool(), &
v);
110 throw runtime_error_f(
"Cannot apply projector to source table of %s: %s",
name, s.ToString().c_str());
112 }
catch (std::exception& e) {
113 throw runtime_error_f(
"Cannot apply projector to source table of %s: exception caught: %s",
name, e.what());
116 for (
auto i = 0U;
i < nColumns; ++
i) {
117 chunks[
i].emplace_back(
v.at(
i));
122 for (
auto i = 0U;
i < nColumns; ++
i) {
123 arrays.push_back(std::make_shared<arrow::ChunkedArray>(chunks[
i]));
127 return arrow::Table::Make(newSchema,
arrays);
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, std::vector< std::shared_ptr< arrow::Field > > const &fields, const char *name)
RuntimeErrorRef runtime_error_f(const char *,...)
A struct, containing the root of the expression tree.