class TestRsaIntersectHost(unittest.TestCase): def setUp(self): self.jobid = str(uuid.uuid1()) session.init(self.jobid) from federatedml.statistic.intersect.intersect_host import RsaIntersectionHost from federatedml.statistic.intersect.intersect_host import RawIntersectionHost intersect_param = IntersectParam() self.rsa_operator = RsaIntersectionHost() self.rsa_operator.load_params(intersect_param) self.raw_operator = RawIntersectionHost() self.raw_operator.load_params(intersect_param) def data_to_table(self, data): return session.parallelize(data, include_key=True, partition=2) def test_func_generate_rsa_key(self): res = self.rsa_operator.generate_rsa_key(1024) self.assertEqual(65537, res[0]) def test_get_common_intersection(self): d1 = [(1, "a"), (2, "b"), (4, "c")] d2 = [(4, "a"), (5, "b"), (6, "c")] d3 = [(4, "a"), (5, "b"), (7, "c")] D1 = self.data_to_table(d1) D2 = self.data_to_table(d2) D3 = self.data_to_table(d3) res = self.raw_operator.get_common_intersection([D1, D2, D3]) gt = [(4, "id")] self.assertListEqual(list(res.collect()), gt) def tearDown(self): session.stop()
def setUp(self): self.jobid = str(uuid.uuid1()) session.init(self.jobid) from federatedml.statistic.intersect.intersect_host import RsaIntersectionHost from federatedml.statistic.intersect.intersect_host import RawIntersectionHost intersect_param = IntersectParam() self.rsa_operator = RsaIntersectionHost(intersect_param) self.raw_operator = RawIntersectionHost(intersect_param)
def intersect(self, data_instance): if self.intersect_param.intersect_method == "rsa": LOGGER.info("Using rsa intersection") self.intersection = RsaIntersectionHost(self.intersect_param) elif self.intersect_param.intersect_method == "raw": LOGGER.info("Using raw intersection") self.intersection = RawIntersectionHost(self.intersect_param) else: raise TypeError("intersect_method {} is not support yet".format( self.workflow_param.intersect_method)) intersect_ids = self.intersection.run(data_instance) self.save_intersect_result(intersect_ids) LOGGER.info("Save intersect results")
class IntersectHostWorkFlow(WorkFlow): def _initialize(self, config_path): self._initialize_workflow_param(config_path) self._initialize_intersect(config_path) def _initialize_intersect(self, config): intersect_param = IntersectParam() self.intersect_param = ParamExtract.parse_param_from_config( intersect_param, config) def intersect(self, data_instance): if self.intersect_param.intersect_method == "rsa": LOGGER.info("Using rsa intersection") self.intersection = RsaIntersectionHost(self.intersect_param) elif self.intersect_param.intersect_method == "raw": LOGGER.info("Using raw intersection") self.intersection = RawIntersectionHost(self.intersect_param) else: raise TypeError("intersect_method {} is not support yet".format( self.workflow_param.intersect_method)) intersect_ids = self.intersection.run(data_instance) self.save_intersect_result(intersect_ids) LOGGER.info("Save intersect results")