| 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(); |