@@ -24,6 +24,10 @@ using namespace o2::framework;
2424
2525namespace o2 ::framework::expressions
2626{
27+ void unknownParameterUsed (const char * name)
28+ {
29+ runtime_error_f (" Unknown parameter used in expression: %s" , name);
30+ }
2731
2832// / a map between BasicOp and gandiva node definitions
2933// / note that logical 'and' and 'or' are created separately
@@ -89,43 +93,41 @@ size_t Filter::designateSubtrees(Node* node, size_t index)
8993 return index;
9094}
9195
92- namespace
96+ template <typename T>
97+ constexpr inline auto makeDatum (T const &)
9398{
94- struct LiteralNodeHelper {
95- DatumSpec operator ()(LiteralNode const & node) const
96- {
97- return DatumSpec{node.value , node.type };
98- }
99- };
99+ return DatumSpec{};
100+ }
100101
101- struct BindingNodeHelper {
102- DatumSpec operator ()(BindingNode const & node) const
103- {
104- return DatumSpec{node.name , node.hash , node.type };
105- }
106- };
102+ template <is_literal_like T>
103+ constexpr inline auto makeDatum (T const & node)
104+ {
105+ return DatumSpec{node.value , node.type };
106+ }
107107
108- struct OpNodeHelper {
109- ColumnOperationSpec operator ()(OpNode const & node) const
110- {
111- return ColumnOperationSpec{node.op };
112- }
113- };
108+ template <is_binding T>
109+ constexpr inline auto makeDatum (T const & node)
110+ {
111+ return DatumSpec{node.name , node.hash , node.type };
112+ }
114113
115- struct PlaceholderNodeHelper {
116- DatumSpec operator ()(PlaceholderNode const & node) const
117- {
118- return DatumSpec{node.value , node.type };
119- }
120- };
114+ template <typename T>
115+ constexpr inline auto makeOp (T const &, size_t const &)
116+ {
117+ return ColumnOperationSpec{};
118+ }
121119
122- struct ParameterNodeHelper {
123- DatumSpec operator ()(ParameterNode const & node) const
124- {
125- return DatumSpec{node.value , node.type };
126- }
127- };
128- } // namespace
120+ template <is_operation T>
121+ constexpr inline auto makeOp (T const & node, size_t const & index)
122+ {
123+ return ColumnOperationSpec{node.op , index};
124+ }
125+
126+ template <is_conditional T>
127+ constexpr inline auto makeOp (T const &, size_t const & index)
128+ {
129+ return ColumnOperationSpec{BasicOp::Conditional, index};
130+ }
129131
130132std::shared_ptr<arrow::DataType> concreteArrowType (atype::type type)
131133{
@@ -169,7 +171,7 @@ std::string upcastTo(atype::type f)
169171 case atype::DOUBLE:
170172 return " castFLOAT8" ;
171173 default :
172- throw runtime_error_f (" Do not know how to cast to %d " , f );
174+ throw runtime_error_f (" Do not know how to cast to %s " , stringType (f) );
173175 }
174176}
175177
@@ -196,13 +198,11 @@ std::ostream& operator<<(std::ostream& os, DatumSpec const& spec)
196198
197199void updatePlaceholders (Filter& filter, InitContext& context)
198200{
199- auto updateNode = [&](Node* node) {
201+ expressions::walk (filter. node . get (), [&](Node* node) {
200202 if (node->self .index () == 3 ) {
201203 std::get_if<3 >(&node->self )->reset (context);
202204 }
203- };
204-
205- expressions::walk (filter.node .get (), updateNode);
205+ });
206206}
207207
208208const char * stringType (atype::type t)
@@ -246,12 +246,7 @@ Operations createOperations(Filter const& expression)
246246
247247 auto processLeaf = [](Node const * const node) {
248248 return std::visit (
249- overloaded{
250- [lh = LiteralNodeHelper{}](LiteralNode const & node) { return lh (node); },
251- [bh = BindingNodeHelper{}](BindingNode const & node) { return bh (node); },
252- [ph = PlaceholderNodeHelper{}](PlaceholderNode const & node) { return ph (node); },
253- [pr = ParameterNodeHelper{}](ParameterNode const & node) { return pr (node); },
254- [](auto &&) { return DatumSpec{}; }},
249+ [](auto const & n) { return makeDatum (n); },
255250 node->self );
256251 };
257252
@@ -266,10 +261,7 @@ Operations createOperations(Filter const& expression)
266261 // create operation spec, pop the node and add its children
267262 auto operationSpec =
268263 std::visit (
269- overloaded{
270- [&](OpNode node) { return ColumnOperationSpec{node.op , top.node_ptr ->index }; },
271- [&](ConditionalNode) { return ColumnOperationSpec{BasicOp::Conditional, top.node_ptr ->index }; },
272- [](auto &&) { return ColumnOperationSpec{}; }},
264+ [&](auto const & n) { return makeOp (n, top.node_ptr ->index ); },
273265 top.node_ptr ->self );
274266
275267 operationSpec.result = DatumSpec{top.index , operationSpec.type };
@@ -623,15 +615,15 @@ gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
623615 auto rightNode = datumNode (it->right );
624616 auto condNode = datumNode (it->condition );
625617
626- auto insertUpcastNode = [& ](gandiva::NodePtr node, atype::type t) {
627- if (t != it-> type ) {
628- auto upcast = gandiva::TreeExprBuilder::MakeFunction (upcastTo (it-> type ), {node}, concreteArrowType (it-> type ));
618+ auto insertUpcastNode = [](gandiva::NodePtr node, atype::type t0 , atype::type t) {
619+ if (t != t0 ) {
620+ auto upcast = gandiva::TreeExprBuilder::MakeFunction (upcastTo (t0 ), {node}, concreteArrowType (t0 ));
629621 node = upcast;
630622 }
631623 return node;
632624 };
633625
634- auto insertEqualizeUpcastNode = [& ](gandiva::NodePtr& node1, gandiva::NodePtr& node2, atype::type t1, atype::type t2) {
626+ auto insertEqualizeUpcastNode = [](gandiva::NodePtr& node1, gandiva::NodePtr& node2, atype::type t1, atype::type t2) {
635627 if (t2 > t1) {
636628 auto upcast = gandiva::TreeExprBuilder::MakeFunction (upcastTo (t2), {node1}, concreteArrowType (t2));
637629 node1 = upcast;
@@ -656,14 +648,14 @@ gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
656648 default :
657649 if (it->op < BasicOp::Sqrt) {
658650 if (it->type != atype::BOOL) {
659- leftNode = insertUpcastNode (leftNode, it->left .type );
660- rightNode = insertUpcastNode (rightNode, it->right .type );
651+ leftNode = insertUpcastNode (leftNode, it->type , it-> left .type );
652+ rightNode = insertUpcastNode (rightNode, it->type , it-> right .type );
661653 } else if (it->op == BasicOp::Equal || it->op == BasicOp::NotEqual) {
662654 insertEqualizeUpcastNode (leftNode, rightNode, it->left .type , it->right .type );
663655 }
664656 temp_node = gandiva::TreeExprBuilder::MakeFunction (basicOperationsMap[it->op ], {leftNode, rightNode}, concreteArrowType (it->type ));
665657 } else {
666- leftNode = insertUpcastNode (leftNode, it->left .type );
658+ leftNode = insertUpcastNode (leftNode, it->type , it-> left .type );
667659 temp_node = gandiva::TreeExprBuilder::MakeFunction (basicOperationsMap[it->op ], {leftNode}, concreteArrowType (it->type ));
668660 }
669661 break ;
0 commit comments