def test_join_composite_agg(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) j = join(rel_one, rel_two, "join", party_data[0]["col_names"][:1], party_data[1]["col_names"][:1]) agg = aggregate(j, "agg", [party_data[0]["col_names"][0]], party_data[0]["col_names"][1], "mean") d = multiply(agg, "mult", party_data[0]["col_names"][1], [7]) collect(d, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushDown() pd.rewrite(d) pu = PushUp() pu.rewrite(d) ic = InsertCloseOps() ic.rewrite(d) io = InsertOpenOps() io.rewrite(d) compare_to_expected(d, expected)
def test_concat_composite_three_party_agg_mean(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) cols_in_three = create_cols(party_data[2]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) rel_three = create("in3", cols_in_three, party_data[2]["stored_with"]) cc = concat([rel_one, rel_two, rel_three], "concat", party_data[0]["col_names"]) p = project(cc, "conc", party_data[0]["col_names"][:2]) mult = multiply(p, "mult", party_data[0]["col_names"][0], [5]) agg = aggregate(mult, "agg", [party_data[0]["col_names"][0]], party_data[0]["col_names"][1], "mean") collect(agg, {1, 2, 3}) d = Dag({rel_one, rel_two, rel_three}) pd = PushDown() pd.rewrite(d) pu = PushUp() pu.rewrite(d) ic = InsertCloseOps() ic.rewrite(d) io = InsertOpenOps() io.rewrite(d) compare_to_expected(d, expected)
def test_join_composite(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) j = join(rel_one, rel_two, "join", party_data[0]["col_names"][:1], party_data[1]["col_names"][:1]) d = divide(j, "div", party_data[0]["col_names"][1], [party_data[1]["col_names"][1]]) collect(d, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushDown() pd.rewrite(d) pu = PushUp() pu.rewrite(d) ic = InsertCloseOps() ic.rewrite(d) io = InsertOpenOps() io.rewrite(d) compare_to_expected(d, expected)
def test_all_stats(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) all_stat = all_stats(cc, "all_stat", [party_data[0]["col_names"][0]], party_data[0]["col_names"][1]) collect(all_stat, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushUp() pd.rewrite(d) compare_to_expected(d, expected)
def test_project_reversible(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) p = project(cc, "proj", party_data[0]["col_names"][::-1]) collect(p, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushUp() pd.rewrite(d) compare_to_expected(d, expected)
def test_divide(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) p = divide(cc, "div", party_data[0]["col_names"][0], [party_data[0]["col_names"][1], 10]) collect(p, {1, 2}) d = Dag({rel_one, rel_two}) pu = PushUp() pu.rewrite(d) compare_to_expected(d, expected)
def test_std_dev_no_key_cols(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) std_dev = aggregate(cc, "std_dev", [], party_data[0]["col_names"][0], "std_dev") collect(std_dev, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushUp() pd.rewrite(d) compare_to_expected(d, expected)
def test_variance(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) variance = aggregate(cc, "variance", [party_data[0]["col_names"][0]], party_data[0]["col_names"][1], "variance") collect(variance, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushUp() pd.rewrite(d) compare_to_expected(d, expected)
def test_concat(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) collect(cc, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushDown() pd.rewrite(d) pu = PushUp() pu.rewrite(d) ic = InsertCloseOps() ic.rewrite(d) io = InsertOpenOps() io.rewrite(d) compare_to_expected(d, expected)
def test_agg_std_dev(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) std_dev = aggregate(cc, "std_dev", [party_data[0]["col_names"][0]], party_data[0]["col_names"][1], "std_dev") mult = multiply(std_dev, "mult", party_data[0]["col_names"][0], [party_data[0]["col_names"][1], 7]) collect(mult, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushDown() pd.rewrite(d) pu = PushUp() pu.rewrite(d) compare_to_expected(d, expected)
def test_std_dev_alt_key_col(party_data, expected): cols_in_one = create_cols(party_data[0]) cols_in_two = create_cols(party_data[1]) rel_one = create("in1", cols_in_one, party_data[0]["stored_with"]) rel_two = create("in2", cols_in_two, party_data[1]["stored_with"]) cc = concat([rel_one, rel_two], "concat", party_data[0]["col_names"]) std_dev = aggregate(cc, "std_dev", [party_data[0]["col_names"][1]], party_data[0]["col_names"][0], "std_dev") collect(std_dev, {1, 2}) d = Dag({rel_one, rel_two}) pd = PushUp() pd.rewrite(d) compare_to_expected(d, expected) zip_col_names = zip(d.top_sort(), [e["col_names"] for e in expected["ownership_data"]]) col_name_checks = [[c.name for c in z[0].out_rel.columns] == z[1] for z in zip_col_names] assert all(col_name_checks)
from congregation.lang import * from congregation.dag import Dag from congregation.comp import PushDown, PushUp from tests.utils import create_cols, compare_to_expected import pytest """ Tests for correct propagation of the following relation-level and column-level attributes after both the PushDown() and the PushUp() phases of the compiler have been run: - DAG node order - node.requires_mpc() attribute - relation-level stored_with sets - column-level plaintext sets - column-level trust_with sets """ @pytest.mark.parametrize("party_data, expected", [ ([{ "col_names": ["a", "b"], "stored_with": {1}, "plaintext_sets": [{1}, {1}], "trust_with_sets": [{1}, {1}] }, { "col_names": ["c", "d"], "stored_with": {2}, "plaintext_sets": [{2}, {2}], "trust_with_sets": [{2}, {2}] }], { "node_order": [Create, Divide, Create, Divide, Concat, Collect], "requires_mpc": [False, False, False, False, True, False],