16#include <arrow/compute/api_aggregate.h>
17#include <arrow/compute/kernel.h>
18#include <arrow/table.h>
30 return (
c >=
'A' &&
c <=
'Z') ?
static_cast<char>(
c + 32) :
c;
35 auto field = std::ranges::find_if(table->schema()->fields(), [
label](std::shared_ptr<arrow::Field>
const& field) {
36 std::string_view name = field->name();
37 return name == label ||
38 std::ranges::equal(label, name, [](char c1, char c2) {
39 return asciiToLower(c1) == asciiToLower(c2);
42 if (field == table->schema()->fields().end()) {
45 return table->column(std::distance(table->schema()->fields().begin(), field)).get();
51 auto locate = std::find(list.begin(), list.end(),
entry);
52 if (locate == list.end()) {
53 list.emplace_back(
entry);
54 }
else if (!locate->enabled &&
entry.enabled) {
55 locate->enabled =
true;
59std::pair<int64_t, int64_t> SliceInfoPtr::getSliceFor(
int value)
const
68std::span<const int64_t> SliceInfoUnsortedPtr::getSliceFor(
int value)
const
77 return {(*groups)[
value].data(), (*groups)[
value].size()};
80void ArrowTableSlicingCacheDef::setCaches(
Cache&& bsks)
85void ArrowTableSlicingCacheDef::setCachesUnsorted(
Cache&& bsks)
87 bindingsKeysUnsorted = bsks;
92 bindingsKeysUnsorted{bsksUnsorted},
120 if (table->num_rows() == 0) {
121 return arrow::Status::OK();
130 auto column = getIndexFromLabel(table.get(), k);
133 for (
auto iChunk = column->num_chunks() - 1; iChunk >= 0; --iChunk) {
134 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
135 for (
auto iElement = chunk.length() - 1; iElement >= 0; --iElement) {
136 auto value = chunk.Value(iElement);
153 int lastValue = std::numeric_limits<int>::max();
155 for (
auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
156 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
157 for (
auto iElement = 0; iElement < chunk.length(); ++iElement) {
158 auto v = chunk.Value(iElement);
160 if (
v == lastValue) {
172 return arrow::Status::OK();
179 if (table->num_rows() == 0) {
180 return arrow::Status::OK();
184 throw runtime_error_f(
"Disabled unsorted cache %s/%s update requested",
b.c_str(), k.c_str());
186 auto column = getIndexFromLabel(table.get(), k);
188 for (
auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
189 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
190 for (
auto iElement = 0; iElement < chunk.length(); ++iElement) {
191 auto v = chunk.Value(iElement);
205 return arrow::Status::OK();
223 auto locate = std::ranges::find(
bindingsKeys, bindingKey);
283 emptySlice = {table.get(), table->Slice(0, 0)};
294 auto column = getIndexFromLabel(input.get(),
key);
295 auto array =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(0)->data());
296 int32_t cur =
array.Value(0);
297 int32_t lastNeg = cur < 0 ? cur : 0;
298 int32_t lastPos = cur < 0 ? -1 : cur;
299 for (
auto i = 0;
i < column->num_chunks(); ++
i) {
300 array =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(
i)->data());
301 for (
auto e = 0; e <
array.length(); ++e) {
308 cur =
array.Value(e);
311 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);
313 if (lastPos == cur && prev < 0) {
314 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);
318 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);
320 if (lastNeg == cur && prev >= 0) {
321 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);
GLuint GLsizei const GLuint const GLintptr * offsets
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
GLenum GLsizei GLsizei GLint * values
GLuint GLsizei const GLchar * label
Defining ITS Vertex explicitly as messageable.
void updatePairList(Cache &list, Entry &entry)
std::vector< Entry > Cache
RuntimeErrorRef runtime_error_f(const char *,...)
constexpr char asciiToLower(char c)
arrow::ChunkedArray * getIndexFromLabel(arrow::Table *table, std::string_view label)
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={})
std::pair< arrow::Table const *, std::shared_ptr< arrow::Table > > emptySlice
Cache bindingsKeysUnsorted
SliceInfoUnsortedPtr getCacheUnsortedForPos(int pos) const
std::shared_ptr< arrow::Table > getEmptySliceFor(std::shared_ptr< arrow::Table > const &table)
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)
static std::string describe(InputSpec const &spec)
ConcreteDataMatcher matcher