MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / reduce

Function reduce

src/expr/tests/test_runner.rs:21–39  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

19 use serde::{Deserialize, Serialize};
20
21 fn reduce(s: &str) -> Result<MirScalarExpr, String> {
22 let mut input_stream = tokenize(s)?.into_iter();
23 let mut ctx = MirScalarExprDeserializeContext::default();
24 let mut scalar: MirScalarExpr = deserialize(&mut input_stream, "MirScalarExpr", &mut ctx)?;
25 let typ: Vec<SqlColumnType> =
26 deserialize(&mut input_stream, "Vec<SqlColumnType> ", &mut ctx)?;
27 let repr_typ: Vec<ReprColumnType> = typ.iter().map(ReprColumnType::from).collect();
28 let before = scalar.sql_typ(&typ);
29 scalar.reduce(&repr_typ);
30 let after = scalar.sql_typ(&typ);
31 // Verify that `reduce` did not change the type of the scalar.
32 if before.scalar_type != after.scalar_type {
33 return Err(format!(
34 "FAIL: Type of scalar has changed:\nbefore: {:?}\nafter: {:?}\n",
35 before, after
36 ));
37 }
38 Ok(scalar)
39 }
40
41 fn test_canonicalize_pred(s: &str) -> Result<Vec<MirScalarExpr>, String> {
42 let mut input_stream = tokenize(s)?.into_iter();

Callers 1

runFunction · 0.70

Calls 8

tokenizeFunction · 0.50
deserializeFunction · 0.50
into_iterMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
sql_typMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected