Skip to content

Commit acf0438

Browse files
authored
[query-engine] Static scalar expressions (open-telemetry#584)
## Changes * Refactor static scalar expressions into their own enum
1 parent 005ea88 commit acf0438

File tree

4 files changed

+326
-298
lines changed

4 files changed

+326
-298
lines changed

rust/experimental/query_engine/expressions/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod expression;
22
pub(crate) mod logical_expressions;
33
pub(crate) mod scalar_expressions;
4+
pub(crate) mod static_scalar_expressions;
45
pub(crate) mod value_accessor;
56

67
pub use expression::Expression;
@@ -11,3 +12,4 @@ pub use value_accessor::ValueSelector;
1112

1213
pub use logical_expressions::*;
1314
pub use scalar_expressions::*;
15+
pub use static_scalar_expressions::*;
Lines changed: 6 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use chrono::{DateTime, FixedOffset};
2-
3-
use crate::{Expression, LogicalExpression, QueryLocation, ValueAccessor, ValueSelector};
1+
use crate::{
2+
Expression, LogicalExpression, QueryLocation, StaticScalarExpression, ValueAccessor,
3+
ValueSelector,
4+
};
45

56
#[derive(Debug, Clone, PartialEq)]
67
pub enum ScalarExpression {
@@ -26,20 +27,8 @@ pub enum ScalarExpression {
2627
/// executions.
2728
Variable(VariableScalarExpression),
2829

29-
/// Resolve a static bool value provided directly in a query.
30-
Boolean(BooleanScalarExpression),
31-
32-
/// Resolve a static DateTime value provided directly in a query.
33-
DateTime(DateTimeScalarExpression),
34-
35-
/// Resolve a static double value provided directly in a query.
36-
Double(DoubleScalarExpression),
37-
38-
/// Resolve a static integer value provided directly in a query.
39-
Integer(IntegerScalarExpression),
40-
41-
/// Resolve a static string value provided directly in a query.
42-
String(StringScalarExpression),
30+
/// Resolve a static value provided directly in a query.
31+
Static(StaticScalarExpression),
4332

4433
/// Negate the value returned by the inner scalar expression.
4534
Negate(NegateScalarExpression),
@@ -170,131 +159,3 @@ impl Expression for NegateScalarExpression {
170159
&self.query_location
171160
}
172161
}
173-
174-
#[derive(Debug, Clone, PartialEq)]
175-
pub struct BooleanScalarExpression {
176-
query_location: QueryLocation,
177-
value: bool,
178-
}
179-
180-
impl BooleanScalarExpression {
181-
pub fn new(query_location: QueryLocation, value: bool) -> BooleanScalarExpression {
182-
Self {
183-
query_location,
184-
value,
185-
}
186-
}
187-
188-
pub fn get_value(&self) -> bool {
189-
self.value
190-
}
191-
}
192-
193-
impl Expression for BooleanScalarExpression {
194-
fn get_query_location(&self) -> &QueryLocation {
195-
&self.query_location
196-
}
197-
}
198-
199-
#[derive(Debug, Clone, PartialEq)]
200-
pub struct DateTimeScalarExpression {
201-
query_location: QueryLocation,
202-
value: DateTime<FixedOffset>,
203-
}
204-
205-
impl DateTimeScalarExpression {
206-
pub fn new(
207-
query_location: QueryLocation,
208-
value: DateTime<FixedOffset>,
209-
) -> DateTimeScalarExpression {
210-
Self {
211-
query_location,
212-
value,
213-
}
214-
}
215-
216-
pub fn get_value(&self) -> DateTime<FixedOffset> {
217-
self.value
218-
}
219-
}
220-
221-
impl Expression for DateTimeScalarExpression {
222-
fn get_query_location(&self) -> &QueryLocation {
223-
&self.query_location
224-
}
225-
}
226-
227-
#[derive(Debug, Clone, PartialEq)]
228-
pub struct DoubleScalarExpression {
229-
query_location: QueryLocation,
230-
value: f64,
231-
}
232-
233-
impl DoubleScalarExpression {
234-
pub fn new(query_location: QueryLocation, value: f64) -> DoubleScalarExpression {
235-
Self {
236-
query_location,
237-
value,
238-
}
239-
}
240-
241-
pub fn get_value(&self) -> f64 {
242-
self.value
243-
}
244-
}
245-
246-
impl Expression for DoubleScalarExpression {
247-
fn get_query_location(&self) -> &QueryLocation {
248-
&self.query_location
249-
}
250-
}
251-
252-
#[derive(Debug, Clone, PartialEq)]
253-
pub struct IntegerScalarExpression {
254-
query_location: QueryLocation,
255-
value: i64,
256-
}
257-
258-
impl IntegerScalarExpression {
259-
pub fn new(query_location: QueryLocation, value: i64) -> IntegerScalarExpression {
260-
Self {
261-
query_location,
262-
value,
263-
}
264-
}
265-
266-
pub fn get_value(&self) -> i64 {
267-
self.value
268-
}
269-
}
270-
271-
impl Expression for IntegerScalarExpression {
272-
fn get_query_location(&self) -> &QueryLocation {
273-
&self.query_location
274-
}
275-
}
276-
277-
#[derive(Debug, Clone, PartialEq)]
278-
pub struct StringScalarExpression {
279-
query_location: QueryLocation,
280-
value: Box<str>,
281-
}
282-
283-
impl StringScalarExpression {
284-
pub fn new(query_location: QueryLocation, value: &str) -> StringScalarExpression {
285-
Self {
286-
query_location,
287-
value: value.into(),
288-
}
289-
}
290-
291-
pub fn get_value(&self) -> &str {
292-
&self.value
293-
}
294-
}
295-
296-
impl Expression for StringScalarExpression {
297-
fn get_query_location(&self) -> &QueryLocation {
298-
&self.query_location
299-
}
300-
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
use chrono::{DateTime, FixedOffset};
2+
3+
use crate::{Expression, QueryLocation};
4+
5+
#[derive(Debug, Clone, PartialEq)]
6+
pub enum StaticScalarExpression {
7+
/// Resolve a static bool value provided directly in a query.
8+
Boolean(BooleanScalarExpression),
9+
10+
/// Resolve a static DateTime value provided directly in a query.
11+
DateTime(DateTimeScalarExpression),
12+
13+
/// Resolve a static double value provided directly in a query.
14+
Double(DoubleScalarExpression),
15+
16+
/// Resolve a static integer value provided directly in a query.
17+
Integer(IntegerScalarExpression),
18+
19+
/// Resolve a static string value provided directly in a query.
20+
String(StringScalarExpression),
21+
}
22+
23+
#[derive(Debug, Clone, PartialEq)]
24+
pub struct BooleanScalarExpression {
25+
query_location: QueryLocation,
26+
value: bool,
27+
}
28+
29+
impl BooleanScalarExpression {
30+
pub fn new(query_location: QueryLocation, value: bool) -> BooleanScalarExpression {
31+
Self {
32+
query_location,
33+
value,
34+
}
35+
}
36+
37+
pub fn get_value(&self) -> bool {
38+
self.value
39+
}
40+
}
41+
42+
impl Expression for BooleanScalarExpression {
43+
fn get_query_location(&self) -> &QueryLocation {
44+
&self.query_location
45+
}
46+
}
47+
48+
#[derive(Debug, Clone, PartialEq)]
49+
pub struct DateTimeScalarExpression {
50+
query_location: QueryLocation,
51+
value: DateTime<FixedOffset>,
52+
}
53+
54+
impl DateTimeScalarExpression {
55+
pub fn new(
56+
query_location: QueryLocation,
57+
value: DateTime<FixedOffset>,
58+
) -> DateTimeScalarExpression {
59+
Self {
60+
query_location,
61+
value,
62+
}
63+
}
64+
65+
pub fn get_value(&self) -> DateTime<FixedOffset> {
66+
self.value
67+
}
68+
}
69+
70+
impl Expression for DateTimeScalarExpression {
71+
fn get_query_location(&self) -> &QueryLocation {
72+
&self.query_location
73+
}
74+
}
75+
76+
#[derive(Debug, Clone, PartialEq)]
77+
pub struct DoubleScalarExpression {
78+
query_location: QueryLocation,
79+
value: f64,
80+
}
81+
82+
impl DoubleScalarExpression {
83+
pub fn new(query_location: QueryLocation, value: f64) -> DoubleScalarExpression {
84+
Self {
85+
query_location,
86+
value,
87+
}
88+
}
89+
90+
pub fn get_value(&self) -> f64 {
91+
self.value
92+
}
93+
}
94+
95+
impl Expression for DoubleScalarExpression {
96+
fn get_query_location(&self) -> &QueryLocation {
97+
&self.query_location
98+
}
99+
}
100+
101+
#[derive(Debug, Clone, PartialEq)]
102+
pub struct IntegerScalarExpression {
103+
query_location: QueryLocation,
104+
value: i64,
105+
}
106+
107+
impl IntegerScalarExpression {
108+
pub fn new(query_location: QueryLocation, value: i64) -> IntegerScalarExpression {
109+
Self {
110+
query_location,
111+
value,
112+
}
113+
}
114+
115+
pub fn get_value(&self) -> i64 {
116+
self.value
117+
}
118+
}
119+
120+
impl Expression for IntegerScalarExpression {
121+
fn get_query_location(&self) -> &QueryLocation {
122+
&self.query_location
123+
}
124+
}
125+
126+
#[derive(Debug, Clone, PartialEq)]
127+
pub struct StringScalarExpression {
128+
query_location: QueryLocation,
129+
value: Box<str>,
130+
}
131+
132+
impl StringScalarExpression {
133+
pub fn new(query_location: QueryLocation, value: &str) -> StringScalarExpression {
134+
Self {
135+
query_location,
136+
value: value.into(),
137+
}
138+
}
139+
140+
pub fn get_value(&self) -> &str {
141+
&self.value
142+
}
143+
}
144+
145+
impl Expression for StringScalarExpression {
146+
fn get_query_location(&self) -> &QueryLocation {
147+
&self.query_location
148+
}
149+
}

0 commit comments

Comments
 (0)