Skip to content

Commit d92491b

Browse files
authored
invalid: fix cfg(linux) -> cfg(unix) & ScalarExpression::constant_calculation adds new expression (#163)
1 parent 937ec7e commit d92491b

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ tokio-test = { version = "0.4.3" }
7474
# Benchmark
7575
sqlite = { version = "0.34.0" }
7676

77-
[target.'cfg(linux)'.dev-dependencies]
77+
[target.'cfg(unix)'.dev-dependencies]
7878
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }
7979

8080
[workspace]

benchmarks/query_benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use fnck_sql::db::DataBaseBuilder;
33
use fnck_sql::errors::DatabaseError;
44
use indicatif::{ProgressBar, ProgressStyle};
55
use itertools::Itertools;
6-
#[cfg(linux)]
6+
#[cfg(unix)]
77
use pprof::criterion::{Output, PProfProfiler};
88
use sqlite::Error;
99
use std::fs;

src/expression/simplify.rs

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,89 @@ impl ScalarExpression {
230230
expr.constant_calculation()?;
231231
}
232232
}
233-
_ => (),
233+
ScalarExpression::In { expr, args, .. } => {
234+
expr.constant_calculation()?;
235+
for arg in args {
236+
arg.constant_calculation()?;
237+
}
238+
}
239+
ScalarExpression::Between {
240+
expr,
241+
left_expr,
242+
right_expr,
243+
..
244+
} => {
245+
expr.constant_calculation()?;
246+
left_expr.constant_calculation()?;
247+
right_expr.constant_calculation()?;
248+
}
249+
ScalarExpression::SubString {
250+
expr,
251+
from_expr,
252+
for_expr,
253+
} => {
254+
expr.constant_calculation()?;
255+
if let Some(from_expr) = from_expr {
256+
from_expr.constant_calculation()?;
257+
}
258+
if let Some(for_expr) = for_expr {
259+
for_expr.constant_calculation()?;
260+
}
261+
}
262+
ScalarExpression::Position { expr, in_expr } => {
263+
expr.constant_calculation()?;
264+
in_expr.constant_calculation()?;
265+
}
266+
ScalarExpression::Tuple(exprs) | ScalarExpression::Coalesce { exprs, .. } => {
267+
for expr in exprs {
268+
expr.constant_calculation()?;
269+
}
270+
}
271+
ScalarExpression::If {
272+
condition,
273+
left_expr,
274+
right_expr,
275+
..
276+
} => {
277+
condition.constant_calculation()?;
278+
left_expr.constant_calculation()?;
279+
right_expr.constant_calculation()?;
280+
}
281+
ScalarExpression::IfNull {
282+
left_expr,
283+
right_expr,
284+
..
285+
}
286+
| ScalarExpression::NullIf {
287+
left_expr,
288+
right_expr,
289+
..
290+
} => {
291+
left_expr.constant_calculation()?;
292+
right_expr.constant_calculation()?;
293+
}
294+
ScalarExpression::CaseWhen {
295+
operand_expr,
296+
expr_pairs,
297+
else_expr,
298+
..
299+
} => {
300+
if let Some(operand_expr) = operand_expr {
301+
operand_expr.constant_calculation()?;
302+
}
303+
for (left_expr, right_expr) in expr_pairs {
304+
left_expr.constant_calculation()?;
305+
right_expr.constant_calculation()?;
306+
}
307+
if let Some(else_expr) = else_expr {
308+
else_expr.constant_calculation()?;
309+
}
310+
}
311+
ScalarExpression::Constant(_)
312+
| ScalarExpression::ColumnRef(_)
313+
| ScalarExpression::Empty
314+
| ScalarExpression::Reference { .. }
315+
| ScalarExpression::Function(_) => (),
234316
}
235317

236318
Ok(())

0 commit comments

Comments
 (0)