-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathExpressionHelpers.h
More file actions
115 lines (106 loc) · 3.34 KB
/
ExpressionHelpers.h
File metadata and controls
115 lines (106 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_EXPRESSIONS_HELPERS_H_
#define O2_FRAMEWORK_EXPRESSIONS_HELPERS_H_
#include "Framework/Expressions.h"
#include <vector>
#include <iosfwd>
#include <fmt/format.h>
namespace o2::framework::expressions
{
/// a map between BasicOp and gandiva node definitions
/// note that logical 'and' and 'or' are created separately
static std::array<std::string, BasicOp::BitwiseNot + 1> basicOperationsMap = {
"and",
"or",
"add",
"subtract",
"divide",
"multiply",
"bitwise_and",
"bitwise_or",
"bitwise_xor",
"less_than",
"less_than_or_equal_to",
"greater_than",
"greater_than_or_equal_to",
"equal",
"not_equal",
"powerf",
"sqrtf",
"expf",
"logf",
"log10f",
"sinf",
"cosf",
"tanf",
"asinf",
"acosf",
"atanf",
"absf",
"bitwise_not"};
struct DatumSpec {
/// datum spec either contains an index, a value of a literal or a binding label
using datum_t = std::variant<std::monostate, size_t, LiteralNode::var_t, std::string>;
datum_t datum = std::monostate{};
size_t hash = 0;
atype::type type = atype::NA;
explicit DatumSpec(size_t index, atype::type type_) : datum{index}, type{type_} {}
explicit DatumSpec(LiteralNode::var_t literal, atype::type type_) : datum{literal}, type{type_} {}
explicit DatumSpec(std::string binding, size_t hash_, atype::type type_) : datum{binding}, hash{hash_}, type{type_} {}
DatumSpec() = default;
DatumSpec(DatumSpec const&) = default;
DatumSpec(DatumSpec&&) = default;
DatumSpec& operator=(DatumSpec const&) = default;
DatumSpec& operator=(DatumSpec&&) = default;
};
bool operator==(DatumSpec const& lhs, DatumSpec const& rhs);
std::ostream& operator<<(std::ostream& os, DatumSpec const& spec);
struct ColumnOperationSpec {
BasicOp op;
DatumSpec left;
DatumSpec right;
DatumSpec result;
atype::type type = atype::NA;
ColumnOperationSpec() = default;
// TODO: extend this to support unary ops seamlessly
explicit ColumnOperationSpec(BasicOp op_) : op{op_},
left{},
right{},
result{}
{
switch (op) {
case BasicOp::LogicalOr:
case BasicOp::LogicalAnd:
case BasicOp::LessThan:
case BasicOp::LessThanOrEqual:
case BasicOp::GreaterThan:
case BasicOp::GreaterThanOrEqual:
case BasicOp::Equal:
case BasicOp::NotEqual:
type = atype::BOOL;
break;
case BasicOp::Division:
type = atype::FLOAT;
default:
type = atype::NA;
}
result.type = type;
}
};
/// helper struct used to parse trees
struct NodeRecord {
/// pointer to the actual tree node
Node* node_ptr = nullptr;
size_t index = 0;
explicit NodeRecord(Node* node_, size_t index_) : node_ptr(node_), index{index_} {}
};
} // namespace o2::framework::expressions
#endif // O2_FRAMEWORK_EXPRESSIONS_HELPERS_H_