11#ifndef O2_FRAMEWORK_EXPRESSIONS_H_
12#define O2_FRAMEWORK_EXPRESSIONS_H_
22#include <arrow/type_fwd.h>
23#include <gandiva/gandiva_aliases.h>
24#include <arrow/type.h>
25#include <gandiva/arrow.h>
26#if !defined(__CLING__) && !defined(__ROOTCLING__)
27#include <arrow/table.h>
28#include <gandiva/selection_vector.h>
29#include <gandiva/node.h>
30#include <gandiva/filter.h>
31#include <gandiva/projector.h>
46using Selection = std::shared_ptr<gandiva::SelectionVector>;
52 ExpressionInfo(
int ai,
size_t hash, std::set<uint32_t>&& hs, gandiva::SchemaPtr sc)
63 gandiva::NodePtr
tree =
nullptr;
73template <
typename... T>
79using LiteralValue =
LiteralStorage<int, bool, float, double, uint8_t, int64_t, int16_t, uint16_t, int8_t, uint32_t, uint64_t>;
87#define SELECT_ARROW_TYPE(_Ctype_, _Atype_) \
88 template <typename T> \
89 requires std::same_as<T, _Ctype_> \
90 constexpr auto selectArrowType() \
92 return atype::_Atype_; \
112 template <
typename T>
140 template <
typename T>
200 using self_t = std::variant<LiteralNode, BindingNode, OpNode, PlaceholderNode, ConditionalNode>;
211#define BINARY_OP_NODES(_operator_, _operation_) \
212 inline Node operator _operator_(Node&& left, Node&& right) \
214 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), std::forward<Node>(right)}; \
216 template <typename T> \
217 inline Node operator _operator_(Node&& left, T right) requires(std::is_arithmetic_v<std::decay_t<T>>) \
219 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), LiteralNode{right}}; \
221 template <typename T> \
222 inline Node operator _operator_(T left, Node&& right) requires(std::is_arithmetic_v<std::decay_t<T>>) \
224 return Node{OpNode{BasicOp::_operation_}, LiteralNode{left}, std::forward<Node>(right)}; \
226 template <typename T> \
227 inline Node operator _operator_(Node&& left, Configurable<T> const& right) \
229 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), PlaceholderNode{right}}; \
231 template <typename T> \
232 inline Node operator _operator_(Configurable<T> const& left, Node&& right) \
234 return Node{OpNode{BasicOp::_operation_}, PlaceholderNode{left}, std::forward<Node>(right)}; \
236 inline Node operator _operator_(BindingNode const& left, BindingNode const& right) \
238 return Node{OpNode{BasicOp::_operation_}, left, right}; \
240 inline Node operator _operator_(BindingNode const& left, Node&& right) \
242 return Node{OpNode{BasicOp::_operation_}, left, std::forward<Node>(right)}; \
244 inline Node operator _operator_(Node&& left, BindingNode const& right) \
246 return Node{OpNode{BasicOp::_operation_}, std::forward<Node>(left), right}; \
248 template <typename T> \
249 inline Node operator _operator_(Configurable<T> const& left, BindingNode const& right) \
251 return Node{OpNode{BasicOp::_operation_}, PlaceholderNode{left}, right}; \
253 template <typename T> \
254 inline Node operator _operator_(BindingNode const& left, Configurable<T> const& right) \
256 return Node{OpNode{BasicOp::_operation_}, left, PlaceholderNode{right}}; \
282#define BINARY_FUNC_NODES(_func_, _node_) \
283 template <typename L, typename R> \
284 inline Node _node_(L left, R right) requires(std::is_arithmetic_v<L> && std::is_arithmetic_v<R>) \
286 return Node{OpNode{BasicOp::_func_}, LiteralNode{left}, LiteralNode{right}}; \
289 inline Node _node_(Node&& left, Node&& right) \
291 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), std::forward<Node>(right)}; \
294 inline Node _node_(Node&& left, BindingNode const& right) \
296 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), right}; \
299 inline Node _node_(BindingNode const& left, BindingNode const& right) \
301 return Node{OpNode{BasicOp::_func_}, left, right}; \
304 inline Node _node_(BindingNode const& left, Node&& right) \
306 return Node{OpNode{BasicOp::_func_}, left, std::forward<Node>(right)}; \
309 template <typename T> \
310 inline Node _node_(Node&& left, Configurable<T> const& right) \
312 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(left), PlaceholderNode{right}}; \
315 template <typename T> \
316 inline Node _node_(Configurable<T> const& left, Node&& right) \
318 return Node{OpNode{BasicOp::_func_}, PlaceholderNode{left}, std::forward<Node>(right)}; \
321 template <typename T> \
322 inline Node _node_(BindingNode const& left, Configurable<T> const& right) \
324 return Node{OpNode{BasicOp::_func_}, left, PlaceholderNode{right}}; \
327 template <typename T> \
328 inline Node _node_(Configurable<T> const& left, BindingNode const& right) \
330 return Node{OpNode{BasicOp::_func_}, PlaceholderNode{left}, right}; \
334#define ncheckbit(_node_, _bit_) ((_node_ & _bit_) == _bit_)
337#define UNARY_FUNC_NODES(_func_, _node_) \
338 inline Node _node_(Node&& arg) \
340 return Node{OpNode{BasicOp::_func_}, std::forward<Node>(arg)}; \
360 return Node{
ConditionalNode{}, std::forward<Node>(then_), std::forward<Node>(else_), std::forward<Node>(condition_)};
375template <
typename L1,
typename L2>
376inline Node ifnode(
Node&& condition_, L1 then_, L2 else_)
requires(std::is_arithmetic_v<L1>&& std::is_arithmetic_v<L2>)
399template <
typename L1,
typename L2>
441 gandiva::SchemaPtr
const& Schema);
443std::shared_ptr<gandiva::Filter>
createFilter(gandiva::SchemaPtr
const& Schema,
444 gandiva::ConditionPtr condition);
446std::shared_ptr<gandiva::Filter>
createFilter(gandiva::SchemaPtr
const& Schema,
449std::shared_ptr<gandiva::Projector>
createProjector(gandiva::SchemaPtr
const& Schema,
451 gandiva::FieldPtr
result);
453std::shared_ptr<gandiva::Projector>
createProjector(gandiva::SchemaPtr
const& Schema,
455 gandiva::FieldPtr
result);
465template <
typename... C>
468 return {C::Projector()...};
472 std::shared_ptr<arrow::Schema> schema,
473 std::vector<std::shared_ptr<arrow::Field>>
const& fields);
475template <
typename... C>
#define SELECT_ARROW_TYPE(_Ctype_, _Atype_)
#define BINARY_FUNC_NODES(_func_, _node_)
#define UNARY_FUNC_NODES(_func_, _node_)
unary functions on nodes
T get(const char *key) const
ConfigParamRegistry const & options()
GLuint const GLchar * name
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
std::shared_ptr< gandiva::Filter > FilterPtr
std::shared_ptr< gandiva::SelectionVector > Selection
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.
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()
Operations createOperations(Filter const &expression)
Function to create an internal operation sequence from a filter tree.
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.
BINARY_OP_NODES(<, LessThan)
Node ifnode(Node &&condition_, Node &&then_, Node &&else_)
conditionals
gandiva::NodePtr createExpressionTree(Operations const &opSpecs, gandiva::SchemaPtr const &Schema)
Function to create gandiva expression tree from operation sequence.
void updatePlaceholders(Filter &filter, InitContext &context)
Update placeholder nodes from context.
BINARY_OP_NODES^ BitwiseXor
BINARY_OP_NODES * Multiplication
Node npow(Node &&left, T right)
functions
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::vector< expressions::Projector > makeProjectors(framework::pack< C... >)
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)
RuntimeErrorRef runtime_error(const char *)
std::vector< int64_t > SelectionVector
Defining DataPointCompositeObject explicitly as copiable.
gandiva::Selection selection
gandiva::SchemaPtr schema
ExpressionInfo(int ai, size_t hash, std::set< uint32_t > &&hs, gandiva::SchemaPtr sc)
std::set< uint32_t > hashes
An expression tree node corresponding to a column binding.
constexpr BindingNode(const char *name_, uint32_t hash_, atype::type type_)
BindingNode(BindingNode const &)=default
BindingNode(BindingNode &&)=delete
A struct, containing the root of the expression tree.
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
std::variant< T... > stored_type
Node(PlaceholderNode &&v)
Node(OpNode op, Node &&l)
std::unique_ptr< Node > condition
std::variant< LiteralNode, BindingNode, OpNode, PlaceholderNode, ConditionalNode > self_t
variant with possible nodes
std::unique_ptr< Node > right
Node(BindingNode const &n)
Node(OpNode op, Node &&l, Node &&r)
Node(ConditionalNode op, Node &&then_, Node &&else_, Node &&condition_)
std::unique_ptr< Node > left
pointers to children
An expression tree node corresponding to binary or unary operation.
A placeholder node for simple type configurable.
void reset(InitContext &context)
LiteralNode::var_t(* retrieve)(InitContext &, char const *)
PlaceholderNode(Configurable< T > const &v)
VectorOfTObjectPtrs other