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

Function test_interpret

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

Source from the content-addressed store, hash-verified

119 }
120
121 fn test_interpret(s: &str) -> Result<Vec<String>, String> {
122 let mut input_stream = tokenize(s)?.into_iter();
123 let mut ctx = MirScalarExprDeserializeContext::default();
124 let types: Vec<SqlColumnType> =
125 deserialize(&mut input_stream, "Vec<SqlColumnType>", &mut ctx)?;
126 let values: Vec<Vec<MirScalarExpr>> =
127 deserialize(&mut input_stream, "Vec<Vec<MirScalarExpr>>", &mut ctx)?;
128 let expr: MirScalarExpr = deserialize(&mut input_stream, "MirScalarExpr", &mut ctx)?;
129 let tests: Vec<MirScalarExpr> =
130 deserialize(&mut input_stream, "Vec<MirScalarExpr>", &mut ctx)?;
131
132 let arena = RowArena::new();
133 let relation = ReprRelationType::new(types.iter().map(ReprColumnType::from).collect());
134 let mut interpreter = ColumnSpecs::new(&relation, &arena);
135
136 let specs: Vec<_> = values
137 .into_iter()
138 .map(|col_exprs| {
139 col_exprs
140 .into_iter()
141 .map(|expr| interpreter.expr(&expr).range)
142 .reduce(|a, b| a.union(b))
143 .expect("at least one literal")
144 })
145 .collect();
146
147 for (id, spec) in specs.into_iter().enumerate() {
148 interpreter.push_column(id, spec);
149 }
150 let output = interpreter.expr(&expr);
151
152 let mut may_contain: Vec<_> = tests
153 .iter()
154 .map(|t| t.eval(&[], &arena).expect("literal datum"))
155 .filter(|d| output.range.may_contain(*d))
156 .map(|d| d.to_string())
157 .collect();
158
159 if output.range.may_fail() {
160 may_contain.push("<err>".into())
161 }
162
163 Ok(may_contain)
164 }
165
166 #[mz_ore::test]
167 #[cfg_attr(miri, ignore)] // error: unsupported operation: can't call foreign function `decContextDefault` on OS `linux`

Callers 1

runFunction · 0.85

Calls 15

expectMethod · 0.80
enumerateMethod · 0.80
push_columnMethod · 0.80
may_containMethod · 0.80
may_failMethod · 0.80
tokenizeFunction · 0.50
deserializeFunction · 0.50
into_iterMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected