16#include <arrow/compute/api_aggregate.h>
17#include <arrow/compute/kernel.h>
18#include <arrow/table.h>
25std::shared_ptr<arrow::ChunkedArray> GetColumnByNameCI(std::shared_ptr<arrow::Table>
const& table, std::string
const&
key)
27 auto const&
fields = table->schema()->fields();
28 auto target = std::find_if(
fields.begin(),
fields.end(), [&
key](std::shared_ptr<arrow::Field>
const& field) {
29 return [](std::string_view const& s1, std::string_view const& s2) {
30 return std::ranges::equal(
32 [](char c1, char c2) {
33 return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2));
35 }(field->name(),
key);
37 return table->column(std::distance(
fields.begin(),
target));
43 auto locate = std::find(list.begin(), list.end(),
entry);
44 if (locate == list.end()) {
45 list.emplace_back(
entry);
46 }
else if (!locate->enabled &&
entry.enabled) {
47 locate->enabled =
true;
51std::pair<int64_t, int64_t> SliceInfoPtr::getSliceFor(
int value)
const
60std::span<const int64_t> SliceInfoUnsortedPtr::getSliceFor(
int value)
const
69 return {(*groups)[
value].data(), (*groups)[
value].size()};
72void ArrowTableSlicingCacheDef::setCaches(
Cache&& bsks)
77void ArrowTableSlicingCacheDef::setCachesUnsorted(
Cache&& bsks)
79 bindingsKeysUnsorted = bsks;
84 bindingsKeysUnsorted{bsksUnsorted},
112 if (table->num_rows() == 0) {
113 return arrow::Status::OK();
122 auto column = GetColumnByNameCI(table, k);
125 for (
auto iChunk = column->num_chunks() - 1; iChunk >= 0; --iChunk) {
126 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
127 for (
auto iElement = chunk.length() - 1; iElement >= 0; --iElement) {
128 auto value = chunk.Value(iElement);
145 int lastValue = std::numeric_limits<int>::max();
147 for (
auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
148 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
149 for (
auto iElement = 0; iElement < chunk.length(); ++iElement) {
150 auto v = chunk.Value(iElement);
152 if (
v == lastValue) {
164 return arrow::Status::OK();
171 if (table->num_rows() == 0) {
172 return arrow::Status::OK();
176 throw runtime_error_f(
"Disabled unsorted cache %s/%s update requested",
b.c_str(), k.c_str());
178 auto column = GetColumnByNameCI(table, k);
180 for (
auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
181 auto chunk =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(iChunk)->data());
182 for (
auto iElement = 0; iElement < chunk.length(); ++iElement) {
183 auto v = chunk.Value(iElement);
197 return arrow::Status::OK();
215 auto locate = std::ranges::find(
bindingsKeys, bindingKey);
278 auto column = o2::framework::GetColumnByNameCI(input,
key);
279 auto array0 =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(0)->data());
281 int32_t cur = array0.Value(0);
282 int32_t lastNeg = cur < 0 ? cur : 0;
283 int32_t lastPos = cur < 0 ? -1 : cur;
284 for (
auto i = 0;
i < column->num_chunks(); ++
i) {
285 auto array =
static_cast<arrow::NumericArray<arrow::Int32Type>
>(column->chunk(
i)->data());
286 for (
auto e = 0; e <
array.length(); ++e) {
293 cur =
array.Value(e);
296 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);
298 if (lastPos == cur && prev < 0) {
299 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);
303 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);
305 if (lastNeg == cur && prev >= 0) {
306 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);
std::vector< std::shared_ptr< arrow::Field > > fields
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
Defining ITS Vertex explicitly as messageable.
void updatePairList(Cache &list, Entry &entry)
std::vector< Entry > Cache
RuntimeErrorRef runtime_error_f(const char *,...)
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={})
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)
static std::string describe(InputSpec const &spec)
ConcreteDataMatcher matcher