15#include <arrow/compute/api_aggregate.h>
16#include <arrow/compute/kernel.h>
17#include <arrow/table.h>
24 auto locate = std::find_if(
list.begin(),
list.end(), [&binding, &
key](
auto const&
entry) { return (entry.binding == binding) && (entry.key == key); });
25 if (locate ==
list.end()) {
27 }
else if (!locate->enabled &&
enabled) {
28 locate->enabled =
true;
38 int64_t p =
static_cast<int64_t
>(
values.size()) - 1;
50 for (
auto i = 0U;
i <
values.size(); ++
i) {
68 return {(*groups)[
value].data(), (*groups)[
value].size()};
83 bindingsKeysUnsorted{bsksUnsorted}
108 if (table->num_rows() == 0) {
111 return arrow::Status::OK();
115 throw runtime_error_f(
"Disabled cache %s/%s update requested",
b.c_str(), k.c_str());
118 arrow::Datum value_counts;
119 auto options = arrow::compute::ScalarAggregateOptions::Defaults();
120 ARROW_ASSIGN_OR_RAISE(value_counts,
121 arrow::compute::CallFunction(
"value_counts", {table->GetColumnByName(
bindingsKeys[
pos].
key)},
123 auto pair =
static_cast<arrow::StructArray
>(value_counts.array());
126 values[
pos] = std::make_shared<arrow::NumericArray<arrow::Int32Type>>(pair.field(0)->data());
127 counts[
pos] = std::make_shared<arrow::NumericArray<arrow::Int64Type>>(pair.field(1)->data());
128 return arrow::Status::OK();
135 if (table->num_rows() == 0) {
136 return arrow::Status::OK();
140 throw runtime_error_f(
"Disabled unsorted cache %s/%s update requested",
b.c_str(), k.c_str());
142 auto column = table->GetColumnByName(k);
144 for (
auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
145 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
146 for (
auto iElement = 0; iElement < chunk.length(); ++iElement) {
147 auto v = chunk.Value(iElement);
161 return arrow::Status::OK();
174 throw runtime_error_f(
"%s/%s not found neither in sorted or unsorted cache", bindingKey.
binding.c_str(), bindingKey.
key.c_str());
179 auto locate = std::find_if(
bindingsKeys.begin(),
bindingsKeys.end(), [&](
Entry const& bk) { return (bindingKey.binding == bk.binding) && (bindingKey.key == bk.key); });
246 auto column = input->GetColumnByName(
key);
247 auto array0 =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(0)->data());
249 int32_t cur = array0.Value(0);
250 int32_t lastNeg = cur < 0 ? cur : 0;
251 int32_t lastPos = cur < 0 ? -1 : cur;
252 for (
auto i = 0;
i < column->num_chunks(); ++
i) {
253 auto array =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(
i)->data());
254 for (
auto e = 0; e <
array.length(); ++e) {
261 cur =
array.Value(e);
264 throw runtime_error_f(
"Table %s index %s is not sorted: next value %d < previous value %d!",
target.c_str(),
key.c_str(), cur, lastPos);
266 if (lastPos == cur && prev < 0) {
267 throw runtime_error_f(
"Table %s index %s has a group with index %d that is split by %d",
target.c_str(),
key.c_str(), cur, prev);
271 throw runtime_error_f(
"Table %s index %s is not sorted: next negative value %d > previous negative value %d!",
target.c_str(),
key.c_str(), cur, lastNeg);
273 if (lastNeg == cur && prev >= 0) {
274 throw runtime_error_f(
"Table %s index %s has a group with index %d that is split by %d",
target.c_str(),
key.c_str(), cur, prev);
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
GLenum GLsizei GLsizei GLint * values
GLuint GLsizei GLsizei * length
Defining PrimaryVertex explicitly as messageable.
std::vector< Entry > Cache
void updatePairList(Cache &list, std::string const &binding, std::string const &key, bool enabled)
RuntimeErrorRef runtime_error_f(const char *,...)
void setCachesUnsorted(Cache &&bsks)
void setCaches(Cache &&bsks)
Cache bindingsKeysUnsorted
SliceInfoPtr getCacheForPos(int pos) const
SliceInfoUnsortedPtr getCacheUnsortedFor(Entry const &bindingKey) const
arrow::Status updateCacheEntryUnsorted(int pos, std::shared_ptr< arrow::Table > const &table)
int getCachePosSortedFor(Entry const &bindingKey) const
arrow::Status updateCacheEntry(int pos, std::shared_ptr< arrow::Table > const &table)
std::pair< int, bool > getCachePos(Entry const &bindingKey) const
SliceInfoPtr getCacheFor(Entry const &bindingKey) const
void setCaches(Cache &&bsks, Cache &&bsksUnsorted={})
ArrowTableSlicingCache(Cache &&bsks, Cache &&bsksUnsorted={})
Cache bindingsKeysUnsorted
SliceInfoUnsortedPtr getCacheUnsortedForPos(int pos) const
int getCachePosUnsortedFor(Entry const &bindingKey) const
std::vector< std::vector< int > > valuesUnsorted
static void validateOrder(Entry const &bindingKey, std::shared_ptr< arrow::Table > const &input)
std::vector< std::shared_ptr< arrow::NumericArray< arrow::Int64Type > > > counts
gsl::span< int64_t const > counts
std::pair< int64_t, int64_t > getSliceFor(int value) const
gsl::span< int64_t const > getSliceFor(int value) const