Build collection dependencies and cache layouts

This commit is contained in:
milner committed 2017-03-27 17:14:00 +00:00
1 parent 4c06f9e15d
commit 98336592fc
7 files changed
+344 -3

No files matched your search

+77
View File
@@ -120,3 +120,80 @@ let cases =
in
check_equal_string "wrapped" (string_of_int min_int) (Value.to_string result) );
]
let plan text = Graph.build (Anf.program (Specialize.program (infer text)))
let plan_of_fixture name = Graph.build (Anf.program (Specialize.program (infer (read_fixture name))))
let graph_cases =
[
( "the example plan is a source, a filter and a map",
fun () ->
let plan = plan_of_fixture "expensive_order.delta" in
check_equal_int "three nodes" 3 (List.length plan.Graph.pl_nodes);
let nodes = plan.Graph.pl_nodes in
check "source first" (match (List.nth nodes 0).Graph.n_kind with Graph.Source -> true | _ -> false);
check "filter second"
(match (List.nth nodes 1).Graph.n_kind with Graph.Filter _ -> true | _ -> false);
check "map last" (match (List.nth nodes 2).Graph.n_kind with Graph.Map _ -> true | _ -> false);
check_equal_string "output" "collection (string, int)" (Types.pp plan.Graph.pl_output) );
( "the revenue plan ends in a sum accumulator",
fun () ->
let plan = plan_of_fixture "revenue.delta" in
let root = Graph.node_of_id plan (match plan.Graph.pl_result with Graph.Result_collection id -> id | _ -> -1) in
check "sum" (match root.Graph.n_kind with Graph.Sum -> true | _ -> false);
check "accumulator cache" (root.Graph.n_cache = Graph.Accumulator);
check_equal_string "linear output" "int" (Types.pp plan.Graph.pl_output) );
( "the count query counts the retained rows",
fun () ->
let plan = plan_of_fixture "count_large.delta" in
check_equal_int "three nodes" 3 (List.length plan.Graph.pl_nodes);
let root =
match plan.Graph.pl_result with
| Graph.Result_collection id -> Graph.node_of_id plan id
| Graph.Result_scalar _ ->
fail "plan" "expected a node result";
{ Graph.n_id = -1; n_kind = Graph.Source; n_input = None; n_element = Types.TInt; n_cache = Graph.No_cache; n_span = Location.none }
in
check "count" (match root.Graph.n_kind with Graph.Count -> true | _ -> false) );
( "collection nodes record their consumers",
fun () ->
let plan = plan_of_fixture "expensive_order.delta" in
check_equal_string "source consumers" "1" (Util.join "," (List.map string_of_int plan.Graph.pl_consumers.(0)));
check_equal_string "filter consumers" "2" (Util.join "," (List.map string_of_int plan.Graph.pl_consumers.(1)));
check_equal_string "map has no consumers" "" (Util.join "," (List.map string_of_int plan.Graph.pl_consumers.(2))) );
( "an identity query has a single source node",
fun () ->
let plan = plan "input rows : collection int\nquery q = rows\n" in
check_equal_int "one node" 1 (List.length plan.Graph.pl_nodes);
check "the result is the source"
(match plan.Graph.pl_result with Graph.Result_collection 0 -> true | _ -> false) );
( "a plan dump is deterministic",
fun () ->
Ident.reset ();
Types.reset ();
Anf.reset ();
let first = Graph.dump (plan_of_fixture "expensive_order.delta") in
Ident.reset ();
Types.reset ();
Anf.reset ();
let second = Graph.dump (plan_of_fixture "expensive_order.delta") in
check_equal_string "identical" first second );
( "an integer query that only uses the input is a plain plan",
fun () ->
let plan = plan "input rows : collection int\nquery q = rows |> sum\n" in
check_equal_int "two nodes" 2 (List.length plan.Graph.pl_nodes);
check "integer output" (Types.repr plan.Graph.pl_output = Types.TInt) );
( "a constant integer query produces no collection nodes",
fun () ->
let plan = plan "input rows : collection int\nquery q = 40 + 2\n" in
check_equal_int "no nodes" 0 (List.length plan.Graph.pl_nodes);
check "scalar result" (match plan.Graph.pl_result with Graph.Result_scalar _ -> true | _ -> false) );
( "shared collection temporaries are reuse",
fun () ->
let plan =
plan
"input rows : collection int\nquery q = rows |> filter (fun r -> r > 0) |> map (fun r -> r + 1) |> sum\n"
in
check_equal_int "four nodes" 4 (List.length plan.Graph.pl_nodes) );
]
+1
View File
@@ -379,5 +379,6 @@ let () =
Test_harness.run_suite "changes" Test_change.law_cases;
Test_harness.run_suite "batches" Test_change.batch_cases;
Test_harness.run_suite "interpret" Test_incremental.cases;
Test_harness.run_suite "graph" Test_incremental.graph_cases;
Printf.printf "%d cases, %d failures\n" (Test_harness.case_count ()) (Test_harness.failure_count ());
exit (if Test_harness.failure_count () = 0 then 0 else 1)