Project
Loading...
Searching...
No Matches
Expressions.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_EXPRESSIONS_H_
12#define O2_FRAMEWORK_EXPRESSIONS_H_
13
14#include "Framework/BasicOps.h"
15#include "Framework/Pack.h"
17#include "Framework/Variant.h"
21#include <arrow/type_fwd.h>
22#include <gandiva/gandiva_aliases.h>
23#include <arrow/type.h>
24#include <gandiva/arrow.h>
25#if !defined(__CLING__) && !defined(__ROOTCLING__)
26#include <arrow/table.h>
27#include <gandiva/selection_vector.h>
28#include <gandiva/node.h>
29#include <gandiva/filter.h>
30#include <gandiva/projector.h>
31#else
32namespace gandiva
33{
34class SelectionVector;
35class Filter;
36class Projector;
37} // namespace gandiva
38#endif
39#include <variant>
40#include <string>
41#include <memory>
42#include <set>
43#include <stack>
44namespace gandiva
45{
46using Selection = std::shared_ptr<gandiva::SelectionVector>;
47using FilterPtr = std::shared_ptr<gandiva::Filter>;
48} // namespace gandiva
49
50using atype = arrow::Type;
52 ExpressionInfo(int ai, size_t hash, std::set<uint32_t>&& hs, gandiva::SchemaPtr sc)
53 : argumentIndex(ai),
54 processHash(hash),
55 hashes(hs),
56 schema(sc)
57 {
58 }
61 std::set<uint32_t> hashes;
62 gandiva::SchemaPtr schema;
63 gandiva::NodePtr tree = nullptr;
66 bool resetSelection = false;
67};
68
70{
71void unknownParameterUsed(const char* name);
72const char* stringType(atype::type t);
73
74template <typename... T>
76 using stored_type = std::variant<T...>;
78};
79
81
82template <typename T>
83constexpr auto selectArrowType()
84{
85 return atype::NA;
86}
87
88#define SELECT_ARROW_TYPE(_Ctype_, _Atype_) \
89 template <typename T> \
90 requires std::same_as<T, _Ctype_> \
91 constexpr auto selectArrowType() \
92 { \
93 return atype::_Atype_; \
94 }
95
97SELECT_ARROW_TYPE(float, FLOAT);
98SELECT_ARROW_TYPE(double, DOUBLE);
99SELECT_ARROW_TYPE(uint8_t, UINT8);
100SELECT_ARROW_TYPE(int8_t, INT8);
101SELECT_ARROW_TYPE(uint16_t, UINT16);
102SELECT_ARROW_TYPE(int16_t, INT16);
103SELECT_ARROW_TYPE(uint32_t, UINT32);
104SELECT_ARROW_TYPE(int32_t, INT32);
105SELECT_ARROW_TYPE(uint64_t, UINT64);
106SELECT_ARROW_TYPE(int64_t, INT64);
107
108std::shared_ptr<arrow::DataType> concreteArrowType(atype::type type);
109std::string upcastTo(atype::type f);
110
114 : value{-1},
115 type{atype::INT32}
116 {
117 }
118 template <typename T>
120 {
121 }
122
125 atype::type type = atype::NA;
126};
127
130 constexpr BindingNode()
131 : name{nullptr},
132 hash{0},
133 type{atype::FLOAT}
134 {
135 }
136 BindingNode(BindingNode const&) = default;
138 constexpr BindingNode(const char* name_, uint32_t hash_, atype::type type_) : name{name_}, hash{hash_}, type{type_} {}
139 constexpr BindingNode(uint32_t hash_, atype::type type_) : name{nullptr}, hash{hash_}, type{type_} {}
140 const char* name;
141 uint32_t hash;
142 atype::type type;
143};
144
146struct OpNode {
148 OpNode(BasicOp op_) : op{op_} {}
150};
151
154 template <typename T>
155 requires(variant_trait_v<typename std::decay<T>::type> != VariantType::Unknown)
157 {
158 retrieve = [](InitContext& context, char const* name) { return LiteralNode::var_t{context.options().get<T>(name)}; };
159 }
160
161 template <typename T, typename AT>
162 requires((std::convertible_to<T, AT>) && (variant_trait_v<typename std::decay<T>::type> != VariantType::Unknown))
163 PlaceholderNode(Configurable<T> const& v, AT*) : LiteralNode{static_cast<AT>(v.value)}, name{v.name}
164 {
165 retrieve = [](InitContext& context, char const* name) { return LiteralNode::var_t{static_cast<AT>(context.options().get<T>(name))}; };
166 }
167
168 template <typename T>
169 PlaceholderNode(T defaultValue, std::string&& path)
170 : LiteralNode{defaultValue},
173 {
174 retrieve = [](InitContext& context, char const* name) { return LiteralNode::var_t{context.options().get<T>(name)}; };
175 }
176
177 void reset(InitContext& context)
178 {
179 value = retrieve(context, stored_name.empty() ? name.data() : stored_name.data());
180 }
181
182 std::string stored_name;
183 std::string const& name;
185};
186
187template <typename AT, typename T>
189{
190 return PlaceholderNode(v, (AT*)nullptr);
191}
192
195 ParameterNode(int index_ = -1)
196 : LiteralNode((float)0),
197 index{index_}
198 {
199 }
200
201 template <typename T>
202 void reset(T value_, int index_ = -1)
203 {
204 (*static_cast<LiteralNode*>(this)) = LiteralNode(value_);
205 if (index_ > 0) {
206 index = index_;
207 }
208 }
209
210 int index;
211};
212
215};
216
218template <typename T>
219concept is_literal_like = std::same_as<T, LiteralNode> || std::same_as<T, PlaceholderNode> || std::same_as<T, ParameterNode>;
220
221template <typename T>
222concept is_binding = std::same_as<T, BindingNode>;
223
224template <typename T>
225concept is_operation = std::same_as<T, OpNode>;
226
227template <typename T>
228concept is_conditional = std::same_as<T, ConditionalNode>;
229
231struct Node {
232 Node(LiteralNode&& v) : self{std::forward<LiteralNode>(v)}, left{nullptr}, right{nullptr}, condition{nullptr}
233 {
234 }
235
236 Node(PlaceholderNode&& v) : self{std::forward<PlaceholderNode>(v)}, left{nullptr}, right{nullptr}, condition{nullptr}
237 {
238 }
239
240 Node(Node&& n) : self{std::forward<self_t>(n.self)}, left{std::forward<std::unique_ptr<Node>>(n.left)}, right{std::forward<std::unique_ptr<Node>>(n.right)}, condition{std::forward<std::unique_ptr<Node>>(n.condition)}, binding{std::forward<std::string>(n.binding)}
241 {
242 }
243
244 Node(BindingNode const& n) : self{n}, left{nullptr}, right{nullptr}, condition{nullptr}
245 {
246 }
247
248 Node(BindingNode const& n, std::string binding_) : self{n}, left{nullptr}, right{nullptr}, condition{nullptr}, binding{binding_}
249 {
250 get<BindingNode>(self).name = binding.c_str();
251 }
252
253 Node(ParameterNode&& p) : self{std::forward<ParameterNode>(p)}, left{nullptr}, right{nullptr}, condition{nullptr}
254 {
255 }
256
257 Node(ConditionalNode op, Node&& then_, Node&& else_, Node&& condition_)
258 : self{op},
259 left{std::make_unique<Node>(std::forward<Node>(then_))},
260 right{std::make_unique<Node>(std::forward<Node>(else_))},
261 condition{std::make_unique<Node>(std::forward<Node>(condition_))} {}
262
263 Node(ConditionalNode op, Node&& then_, std::unique_ptr<Node>&& else_, Node&& condition_)
264 : self{op},
265 left{std::make_unique<Node>(std::forward<Node>(then_))},
266 right{std::forward<std::unique_ptr<Node>>(else_)},
267 condition{std::make_unique<Node>(std::forward<Node>(condition_))} {}
268
270 : self{op},
271 left{std::make_unique<Node>(std::forward<Node>(l))},
272 right{std::make_unique<Node>(std::forward<Node>(r))},
273 condition{nullptr} {}
274
275 Node(OpNode op, std::unique_ptr<Node>&& l, Node&& r)
276 : self{op},
277 left{std::forward<std::unique_ptr<Node>>(l)},
278 right{std::make_unique<Node>(std::forward<Node>(r))},
279 condition{nullptr} {}
280
282 : self{op},
283 left{std::make_unique<Node>(std::forward<Node>(l))},
284 right{nullptr},
285 condition{nullptr} {}
286
288 : self{other.self},
290 {
291 if (other.left != nullptr) {
292 left = std::make_unique<Node>(*other.left);
293 }
294 if (other.right != nullptr) {
295 right = std::make_unique<Node>(*other.right);
296 }
297 if (other.condition != nullptr) {
298 condition = std::make_unique<Node>(*other.condition);
299 }
300 binding = other.binding;
301 if (!binding.empty()) {
302 get<BindingNode>(self).name = binding.c_str();
303 }
304 }
305
307 using self_t = std::variant<LiteralNode, BindingNode, OpNode, PlaceholderNode, ConditionalNode, ParameterNode>;
309 size_t index = 0;
311 std::unique_ptr<Node> left = nullptr;
312 std::unique_ptr<Node> right = nullptr;
313 std::unique_ptr<Node> condition = nullptr;
314
316 std::string binding;
317};
318
322 Node* node_ptr = nullptr;
323 size_t index = 0;
324 explicit NodeRecord(Node* node_, size_t index_) : node_ptr(node_), index{index_} {}
325 bool operator!=(NodeRecord const& rhs)
326 {
327 return this->node_ptr != rhs.node_ptr;
328 }
329};
330
332template <typename L>
333void walk(Node* head, L&& pred)
334{
335 std::stack<NodeRecord> path;
336 path.emplace(head, 0);
337 while (!path.empty()) {
338 auto& top = path.top();
339 pred(top.node_ptr);
340
341 auto* leftp = top.node_ptr->left.get();
342 auto* rightp = top.node_ptr->right.get();
343 auto* condp = top.node_ptr->condition.get();
344 path.pop();
345
346 if (leftp != nullptr) {
347 path.emplace(leftp, 0);
348 }
349 if (rightp != nullptr) {
350 path.emplace(rightp, 0);
351 }
352 if (condp != nullptr) {
353 path.emplace(condp, 0);
354 }
355 }
356}
357
359template <typename T>
360concept arithmetic = std::is_arithmetic_v<T>;
361
363
364#define BINARY_OP_NODES(_operator_, _operation_) \
365 inline Node operator _operator_(Node&& left, Node&& right) \
366 { \
367 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), std::forward<Node>(right)}; \
368 } \
369 template <arithmetic T> \
370 inline Node operator _operator_(Node&& left, T right) \
371 { \
372 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), LiteralNode{right}}; \
373 } \
374 template <arithmetic T> \
375 inline Node operator _operator_(T left, Node&& right) \
376 { \
377 return Node{OpNode{BasicOp::_operation_}, LiteralNode{left}, std::forward<Node>(right)}; \
378 } \
379 template <typename T> \
380 inline Node operator _operator_(Node&& left, Configurable<T> const& right) \
381 { \
382 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), PlaceholderNode{right}}; \
383 } \
384 template <typename T> \
385 inline Node operator _operator_(Configurable<T> const& left, Node&& right) \
386 { \
387 return Node{OpNode{BasicOp::_operation_}, PlaceholderNode{left}, std::forward<Node>(right)}; \
388 } \
389 inline Node operator _operator_(BindingNode const& left, BindingNode const& right) \
390 { \
391 return Node{OpNode{BasicOp::_operation_}, left, right}; \
392 } \
393 inline Node operator _operator_(BindingNode const& left, Node&& right) \
394 { \
395 return Node{OpNode{BasicOp::_operation_}, left, std::forward<Node>(right)}; \
396 } \
397 inline Node operator _operator_(Node&& left, BindingNode const& right) \
398 { \
399 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), right}; \
400 } \
401 template <typename T> \
402 inline Node operator _operator_(Configurable<T> const& left, BindingNode const& right) \
403 { \
404 return Node{OpNode{BasicOp::_operation_}, PlaceholderNode{left}, right}; \
405 } \
406 template <typename T> \
407 inline Node operator _operator_(BindingNode const& left, Configurable<T> const& right) \
408 { \
409 return Node{OpNode{BasicOp::_operation_}, left, PlaceholderNode{right}}; \
410 }
411
427
429template <arithmetic T>
430inline Node npow(Node&& left, T right)
431{
432 return Node{OpNode{BasicOp::Power}, std::forward<Node>(left), LiteralNode{right}};
433}
434
435#define BINARY_FUNC_NODES(_func_, _node_) \
436 template <arithmetic L, arithmetic R> \
437 inline Node _node_(L left, R right) \
438 { \
439 return Node{OpNode{BasicOp::_func_}, LiteralNode{left}, LiteralNode{right}}; \
440 } \
441 \
442 inline Node _node_(Node&& left, Node&& right) \
443 { \
444 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), std::forward<Node>(right)}; \
445 } \
446 \
447 inline Node _node_(Node&& left, BindingNode const& right) \
448 { \
449 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), right}; \
450 } \
451 \
452 inline Node _node_(BindingNode const& left, BindingNode const& right) \
453 { \
454 return Node{OpNode{BasicOp::_func_}, left, right}; \
455 } \
456 \
457 inline Node _node_(BindingNode const& left, Node&& right) \
458 { \
459 return Node{OpNode{BasicOp::_func_}, left, std::forward<Node>(right)}; \
460 } \
461 \
462 template <typename T> \
463 inline Node _node_(Node&& left, Configurable<T> const& right) \
464 { \
465 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), PlaceholderNode{right}}; \
466 } \
467 \
468 template <typename T> \
469 inline Node _node_(Configurable<T> const& left, Node&& right) \
470 { \
471 return Node{OpNode{BasicOp::_func_}, PlaceholderNode{left}, std::forward<Node>(right)}; \
472 } \
473 \
474 template <typename T> \
475 inline Node _node_(BindingNode const& left, Configurable<T> const& right) \
476 { \
477 return Node{OpNode{BasicOp::_func_}, left, PlaceholderNode{right}}; \
478 } \
479 \
480 template <typename T> \
481 inline Node _node_(Configurable<T> const& left, BindingNode const& right) \
482 { \
483 return Node{OpNode{BasicOp::_func_}, PlaceholderNode{left}, right}; \
484 }
485
487#define ncheckbit(_node_, _bit_) ((_node_ & _bit_) == _bit_)
488
490#define UNARY_FUNC_NODES(_func_, _node_) \
491 inline Node _node_(Node&& arg) \
492 { \
493 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(arg)}; \
494 }
495
509
511inline Node ifnode(Node&& condition_, Node&& then_, Node&& else_)
512{
513 return Node{ConditionalNode{}, std::forward<Node>(then_), std::forward<Node>(else_), std::forward<Node>(condition_)};
514}
515
516template <arithmetic L>
517inline Node ifnode(Node&& condition_, Node&& then_, L else_)
518{
519 return Node{ConditionalNode{}, std::forward<Node>(then_), LiteralNode{else_}, std::forward<Node>(condition_)};
520}
521
522template <arithmetic L>
523inline Node ifnode(Node&& condition_, L then_, Node&& else_)
524{
525 return Node{ConditionalNode{}, LiteralNode{then_}, std::forward<Node>(else_), std::forward<Node>(condition_)};
526}
527
528template <arithmetic L1, arithmetic L2>
529inline Node ifnode(Node&& condition_, L1 then_, L2 else_)
530{
531 return Node{ConditionalNode{}, LiteralNode{then_}, LiteralNode{else_}, std::forward<Node>(condition_)};
532}
533
534template <typename T>
535inline Node ifnode(Configurable<T> const& condition_, Node&& then_, Node&& else_)
536{
537 return Node{ConditionalNode{}, std::forward<Node>(then_), std::forward<Node>(else_), PlaceholderNode{condition_}};
538}
539
540template <typename L>
541inline Node ifnode(Node&& condition_, Node&& then_, Configurable<L> const& else_)
542{
543 return Node{ConditionalNode{}, std::forward<Node>(then_), PlaceholderNode{else_}, std::forward<Node>(condition_)};
544}
545
546template <typename L>
547inline Node ifnode(Node&& condition_, Configurable<L> const& then_, Node&& else_)
548{
549 return Node{ConditionalNode{}, PlaceholderNode{then_}, std::forward<Node>(else_), std::forward<Node>(condition_)};
550}
551
552template <typename L1, typename L2>
553inline Node ifnode(Node&& condition_, Configurable<L1> const& then_, Configurable<L2> const& else_)
554{
555 return Node{ConditionalNode{}, PlaceholderNode{then_}, PlaceholderNode{else_}, std::forward<Node>(condition_)};
556}
557
559inline Node par(int index)
560{
561 return Node{ParameterNode{index}};
562}
563
565template <typename T>
566inline Node binned(std::vector<T> const& binning, std::vector<T> const& parameters, Node&& binned, Node&& pexp, Node&& out)
567{
568 int bins = binning.size() - 1;
569 const auto binned_copy = binned;
570 const auto out_copy = out;
571 auto root = ifnode(Node{binned_copy} < binning[0], Node{out_copy}, LiteralNode{-1});
572 auto* current = &root;
573 for (auto i = 0; i < bins; ++i) {
574 current->right = std::make_unique<Node>(ifnode(Node{binned_copy} < binning[i + 1], updateParameters(pexp, bins, parameters, i), LiteralNode{-1}));
575 current = current->right.get();
576 }
577 current->right = std::make_unique<Node>(out);
578 return root;
579}
580
581template <typename T>
582inline Node updateParameters(Node const& pexp, int bins, std::vector<T> const& parameters, int bin)
583{
584 Node result{pexp};
585 walk(&result, [&bins, &parameters, &bin](Node* node) {
586 if (node->self.index() == 5) {
587 auto* n = std::get_if<5>(&node->self);
588 n->reset(parameters[n->index * bins + bin]);
589 }
590 });
591 return result;
592}
593
595template <typename T>
596inline Node clamp(Node&& expr, T low, T hi)
597{
598 auto copy = expr;
599 return ifnode(Node{copy} < LiteralNode{low}, LiteralNode{low}, ifnode(Node{copy} > LiteralNode{hi}, LiteralNode{hi}, Node{copy}));
600}
601
603inline Node protect0(Node&& expr)
604{
605 auto copy = expr;
607}
608
610template <typename T>
611inline Node ncfg(T defaultValue, std::string path)
612{
613 return PlaceholderNode(defaultValue, path);
614}
615
617struct Filter {
618 Filter() = default;
619
620 Filter(Node&& node_) : node{std::make_unique<Node>(std::forward<Node>(node_))}
621 {
623 }
624
625 Filter(Filter&& other) : node{std::forward<std::unique_ptr<Node>>(other.node)}
626 {
628 }
629
630 Filter(std::string const& input_) : input{input_} {}
631
633 {
634 node = std::move(other.node);
635 input = std::move(other.input);
636 return *this;
637 }
638
639 Filter& operator=(std::string const& input_)
640 {
641 input = input_;
642 if (node != nullptr) {
643 node = nullptr;
644 }
645 return *this;
646 }
647
648 std::unique_ptr<Node> node = nullptr;
649 std::string input;
650
651 size_t designateSubtrees(Node* node, size_t index = 0);
652 void parse();
653};
654
655template <typename T>
656concept is_filter = std::same_as<T, Filter>;
657
659
661gandiva::Selection createSelection(std::shared_ptr<arrow::Table> const& table, Filter const& expression);
663gandiva::Selection createSelection(std::shared_ptr<arrow::Table> const& table, std::shared_ptr<gandiva::Filter> const& gfilter);
664
666using Operations = std::vector<ColumnOperationSpec>;
667
669Operations createOperations(Filter const& expression);
670
672bool isTableCompatible(std::set<uint32_t> const& hashes, Operations const& specs);
674gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
675 gandiva::SchemaPtr const& Schema);
677std::shared_ptr<gandiva::Filter> createFilter(gandiva::SchemaPtr const& Schema,
678 gandiva::ConditionPtr condition);
680std::shared_ptr<gandiva::Filter> createFilter(gandiva::SchemaPtr const& Schema,
681 Operations const& opSpecs);
683std::shared_ptr<gandiva::Projector> createProjector(gandiva::SchemaPtr const& Schema,
684 Operations const& opSpecs,
685 gandiva::FieldPtr result);
687std::shared_ptr<gandiva::Projector> createProjector(gandiva::SchemaPtr const& Schema,
688 Projector&& p,
689 gandiva::FieldPtr result);
691void updateExpressionInfos(expressions::Filter const& filter, std::vector<ExpressionInfo>& eInfos);
693gandiva::ConditionPtr makeCondition(gandiva::NodePtr node);
695gandiva::ExpressionPtr makeExpression(gandiva::NodePtr node, gandiva::FieldPtr result);
698
699std::shared_ptr<gandiva::Projector> createProjectorHelper(size_t nColumns, expressions::Projector* projectors,
700 std::shared_ptr<arrow::Schema> schema,
701 std::vector<std::shared_ptr<arrow::Field>> const& fields);
702
703template <typename... C>
704std::shared_ptr<gandiva::Projector> createProjectors(framework::pack<C...>, std::vector<std::shared_ptr<arrow::Field>> const& fields, gandiva::SchemaPtr schema)
705{
706 std::array<expressions::Projector, sizeof...(C)> projectors{{std::move(C::Projector())...}};
707
708 return createProjectorHelper(sizeof...(C), projectors.data(), schema, fields);
709}
710
711void updateFilterInfo(ExpressionInfo& info, std::shared_ptr<arrow::Table>& table);
712
713/*
714 * The formal grammar for framework expressions.
715 * Operations are in the order of increasing priority.
716 * Identifier includes namespaces, e.g. o2::aod::track::pt.
717 *
718 * top ::= primary
719 *
720 * primary ::= tier1 ('||' tier1)*
721 * tier1 ::= tier2 ('&&' tier2)*
722 * tier2 ::= tier3 ('|' tier3)*
723 * tier3 ::= tier4 ('^' tier4)*
724 * tier4 ::= tier5 ('&' tier5)*
725 * tier5 ::= tier6 (('=='|'!=') tier6)*
726 * tier6 ::= tier7 (('<'|'>'|'<='|'>=') tier7)*
727 * tier7 ::= tier8 (('+'|'-') tier8)*
728 * tier8 ::= base (('*'|'/') base)*
729 *
730 * base ::= identifier
731 * | number
732 * | function_call
733 * | '(' primary ')'
734 *
735 * number ::= -?[0-9]+(\.[0-9]*)?([uf])?
736 * identifier ::= [a-zA-Z][a-zA-Z0-9_]* ('::' [a-zA-Z][a-zA-Z0-9_]*)*
737 * function_call ::= identifier '(' (primary (',' primary)*)? ')'
738 */
739
741enum Token : int {
742 EoL = -1,
747 Unexpected = -100
749
750struct Tokenizer {
751 std::string source;
752 std::string::iterator current;
753 std::string IdentifierStr;
754 std::string BinaryOpStr;
755 std::string StrValue;
756 std::string TokenStr;
757 std::variant<uint32_t, int32_t, uint64_t, int64_t> IntegerValue;
758 std::variant<float, double> FloatValue;
761
762 Tokenizer(std::string const& input = "");
763 void reset(std::string const& input);
764 [[maybe_unused]] int nextToken();
765 void pop();
766 char peek();
767};
768
769struct Parser {
770 static Node parse(std::string const& input);
771 static std::unique_ptr<Node> parsePrimary(Tokenizer& tk);
772 static std::unique_ptr<Node> parseTier1(Tokenizer& tk);
773 static std::unique_ptr<Node> parseTier2(Tokenizer& tk);
774 static std::unique_ptr<Node> parseTier3(Tokenizer& tk);
775 static std::unique_ptr<Node> parseTier4(Tokenizer& tk);
776 static std::unique_ptr<Node> parseTier5(Tokenizer& tk);
777 static std::unique_ptr<Node> parseTier6(Tokenizer& tk);
778 static std::unique_ptr<Node> parseTier7(Tokenizer& tk);
779 static std::unique_ptr<Node> parseTier8(Tokenizer& tk);
780 static std::unique_ptr<Node> parseBase(Tokenizer& tk);
781
782 static OpNode opFromToken(std::string const& token);
783};
784
785} // namespace o2::framework::expressions
786
787#endif // O2_FRAMEWORK_EXPRESSIONS_H_
const auto bins
Definition PID.cxx:49
#define SELECT_ARROW_TYPE(_Ctype_, _Atype_)
Definition Expressions.h:88
#define BINARY_FUNC_NODES(_func_, _node_)
arrow::Type atype
Definition Expressions.h:50
#define UNARY_FUNC_NODES(_func_, _node_)
unary functions on nodes
int32_t i
uint32_t op
useful math constants
uint32_t gfilter
Definition RawData.h:6
ConfigParamRegistry const & options()
Definition InitContext.h:33
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLdouble n
Definition glcorearb.h:1982
GLuint64EXT * result
Definition glcorearb.h:5662
const GLdouble * v
Definition glcorearb.h:832
GLuint index
Definition glcorearb.h:781
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble GLdouble right
Definition glcorearb.h:4077
GLdouble f
Definition glcorearb.h:310
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLenum clamp
Definition glcorearb.h:1245
GLboolean r
Definition glcorearb.h:1233
std::shared_ptr< gandiva::Filter > FilterPtr
Definition Expressions.h:47
std::shared_ptr< gandiva::SelectionVector > Selection
Definition Expressions.h:46
constexpr float Almost0
std::shared_ptr< arrow::DataType > concreteArrowType(atype::type type)
std::shared_ptr< gandiva::Filter > createFilter(gandiva::SchemaPtr const &Schema, gandiva::ConditionPtr condition)
Function to create gandiva filter from gandiva condition.
gandiva::ExpressionPtr makeExpression(gandiva::NodePtr node, gandiva::FieldPtr result)
Function to create gandiva projecting expression from generic gandiva expression tree.
BINARY_OP_NODES && LogicalAnd
BINARY_OP_NODES & BitwiseAnd
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)
gandiva::Selection createSelection(std::shared_ptr< arrow::Table > const &table, Filter const &expression)
Function for creating gandiva selection from our internal filter tree.
PlaceholderNode as(Configurable< T > const &v)
const char * stringType(atype::type t)
std::vector< ColumnOperationSpec > Operations
void updateExpressionInfos(expressions::Filter const &filter, std::vector< ExpressionInfo > &eInfos)
Function for attaching gandiva filters to to compatible task inputs.
constexpr auto selectArrowType()
Definition Expressions.h:83
Node par(int index)
Parameters.
Operations createOperations(Filter const &expression)
Function to create an internal operation sequence from a filter tree.
Node updateParameters(Node const &pexp, int bins, std::vector< T > const &parameters, int bin)
gandiva::ConditionPtr makeCondition(gandiva::NodePtr node)
Function to create gandiva condition expression from generic gandiva expression tree.
bool isTableCompatible(std::set< uint32_t > const &hashes, Operations const &specs)
Function to check compatibility of a given arrow schema with operation sequence.
void unknownParameterUsed(const char *name)
void walk(Node *head, L &&pred)
Tree-walker helper.
Node ifnode(Node &&condition_, Node &&then_, Node &&else_)
conditionals
Node npow(Node &&left, T right)
functions
gandiva::NodePtr createExpressionTree(Operations const &opSpecs, gandiva::SchemaPtr const &Schema)
Function to create gandiva expression tree from operation sequence.
Node binned(std::vector< T > const &binning, std::vector< T > const &parameters, Node &&binned, Node &&pexp, Node &&out)
binned functional
void updatePlaceholders(Filter &filter, InitContext &context)
Update placeholder nodes from context.
BINARY_OP_NODES^ BitwiseXor
BINARY_OP_NODES * Multiplication
Node protect0(Node &&expr)
division by 0 protector
Node ncfg(T defaultValue, std::string path)
context-independent configurable
std::string upcastTo(atype::type f)
std::shared_ptr< gandiva::Projector > createProjector(gandiva::SchemaPtr const &Schema, Operations const &opSpecs, gandiva::FieldPtr result)
Function to create gandiva projector from operation sequence.
std::shared_ptr< gandiva::Projector > createProjectors(framework::pack< C... >, std::vector< std::shared_ptr< arrow::Field > > const &fields, gandiva::SchemaPtr schema)
void updateFilterInfo(ExpressionInfo &info, std::shared_ptr< arrow::Table > &table)
@ GreaterThanOrEqual
Definition BasicOps.h:29
constexpr VariantType variant_trait_v
Definition Variant.h:190
std::vector< int64_t > SelectionVector
Definition ASoA.h:412
Defining DataPointCompositeObject explicitly as copiable.
gandiva::Selection selection
Definition Expressions.h:65
gandiva::SchemaPtr schema
Definition Expressions.h:62
ExpressionInfo(int ai, size_t hash, std::set< uint32_t > &&hs, gandiva::SchemaPtr sc)
Definition Expressions.h:52
std::set< uint32_t > hashes
Definition Expressions.h:61
gandiva::NodePtr tree
Definition Expressions.h:63
size_t processHash
Definition Expressions.h:60
An expression tree node corresponding to a column binding.
constexpr BindingNode(const char *name_, uint32_t hash_, atype::type type_)
BindingNode(BindingNode const &)=default
constexpr BindingNode(uint32_t hash_, atype::type type_)
A struct, containing the root of the expression tree.
Filter & operator=(std::string const &input_)
Filter(std::string const &input_)
Filter & operator=(Filter &&other) noexcept
size_t designateSubtrees(Node *node, size_t index=0)
std::unique_ptr< Node > node
An expression tree node corresponding to a literal value.
LiteralValue::stored_type var_t
helper struct used to parse trees
bool operator!=(NodeRecord const &rhs)
Node * node_ptr
pointer to the actual tree node
NodeRecord(Node *node_, size_t index_)
std::unique_ptr< Node > condition
Node(ConditionalNode op, Node &&then_, std::unique_ptr< Node > &&else_, Node &&condition_)
std::unique_ptr< Node > right
std::variant< LiteralNode, BindingNode, OpNode, PlaceholderNode, ConditionalNode, ParameterNode > self_t
variant with possible nodes
Node(BindingNode const &n)
Node(OpNode op, Node &&l, Node &&r)
Node(OpNode op, std::unique_ptr< Node > &&l, Node &&r)
std::string binding
buffer for dynamic binding
Node(BindingNode const &n, std::string binding_)
Node(ConditionalNode op, Node &&then_, Node &&else_, Node &&condition_)
An expression tree node corresponding to binary or unary operation.
A placeholder node for parameters taken from an array.
void reset(T value_, int index_=-1)
static std::unique_ptr< Node > parseBase(Tokenizer &tk)
static std::unique_ptr< Node > parseTier8(Tokenizer &tk)
static std::unique_ptr< Node > parseTier3(Tokenizer &tk)
static std::unique_ptr< Node > parseTier1(Tokenizer &tk)
static std::unique_ptr< Node > parseTier6(Tokenizer &tk)
static std::unique_ptr< Node > parseTier7(Tokenizer &tk)
static std::unique_ptr< Node > parsePrimary(Tokenizer &tk)
static std::unique_ptr< Node > parseTier4(Tokenizer &tk)
static std::unique_ptr< Node > parseTier2(Tokenizer &tk)
static Node parse(std::string const &input)
static OpNode opFromToken(std::string const &token)
static std::unique_ptr< Node > parseTier5(Tokenizer &tk)
A placeholder node for simple type configurable.
LiteralNode::var_t(* retrieve)(InitContext &, char const *)
PlaceholderNode(Configurable< T > const &v)
PlaceholderNode(Configurable< T > const &v, AT *)
PlaceholderNode(T defaultValue, std::string &&path)
void reset(std::string const &input)
std::variant< uint32_t, int32_t, uint64_t, int64_t > IntegerValue
std::variant< float, double > FloatValue
VectorOfTObjectPtrs other