(
relation: &ReprRelationType,
)
| 1423 | } |
| 1424 | |
| 1425 | fn gen_expr_for_relation( |
| 1426 | relation: &ReprRelationType, |
| 1427 | ) -> BoxedStrategy<(MirScalarExpr, ReprColumnType)> { |
| 1428 | let column_gen = { |
| 1429 | let column_types = relation.column_types.clone(); |
| 1430 | any::<Index>() |
| 1431 | .prop_map(move |idx| { |
| 1432 | let id = idx.index(column_types.len()); |
| 1433 | (MirScalarExpr::column(id), column_types[id].clone()) |
| 1434 | }) |
| 1435 | .boxed() |
| 1436 | }; |
| 1437 | |
| 1438 | let literal_gen = (select(SCALAR_TYPES), any::<bool>()) |
| 1439 | .prop_map(|(s, b)| s.nullable(b)) |
| 1440 | .prop_flat_map(|ct| { |
| 1441 | let error_gen = any::<EvalError>().prop_map(Err).boxed(); |
| 1442 | let value_gen = gen_datums_for_type(&ct) |
| 1443 | .prop_map(move |datum| Ok(Row::pack_slice(&[datum]))) |
| 1444 | .boxed(); |
| 1445 | error_gen.prop_union(value_gen).prop_map(move |result| { |
| 1446 | (MirScalarExpr::Literal(result, ct.clone()), ct.clone()) |
| 1447 | }) |
| 1448 | }) |
| 1449 | .boxed(); |
| 1450 | |
| 1451 | column_gen |
| 1452 | .prop_union(literal_gen) |
| 1453 | .prop_recursive(4, 64, 8, |self_gen| { |
| 1454 | let unary_gen = (select(INTERESTING_UNARY_FUNCS), self_gen.clone()) |
| 1455 | .prop_filter_map("unary func", |(func, (expr_in, type_in))| { |
| 1456 | if !unary_typecheck(&func, &type_in) { |
| 1457 | return None; |
| 1458 | } |
| 1459 | let type_out = func.output_type(type_in); |
| 1460 | let expr_out = MirScalarExpr::CallUnary { |
| 1461 | func, |
| 1462 | expr: Box::new(expr_in), |
| 1463 | }; |
| 1464 | Some((expr_out, type_out)) |
| 1465 | }) |
| 1466 | .boxed(); |
| 1467 | let binary_gen = ( |
| 1468 | select(interesting_binary_funcs()), |
| 1469 | self_gen.clone(), |
| 1470 | self_gen.clone(), |
| 1471 | ) |
| 1472 | .prop_filter_map( |
| 1473 | "binary func", |
| 1474 | |(func, (expr_left, type_left), (expr_right, type_right))| { |
| 1475 | if !binary_typecheck(&func, &type_left, &type_right) { |
| 1476 | return None; |
| 1477 | } |
| 1478 | let type_out = func.output_type(&[type_left, type_right]); |
| 1479 | let expr_out = MirScalarExpr::CallBinary { |
| 1480 | func, |
| 1481 | expr1: Box::new(expr_left), |
| 1482 | expr2: Box::new(expr_right), |
no test coverage detected