Пример #1
0
def test_graph_builds_dags_correctly(stub_graph_set):
    shgraph = SnowShuGraph()
    _, vals = stub_graph_set

    full_catalog = [
        vals.iso_relation, vals.view_relation, vals.downstream_relation,
        vals.upstream_relation, vals.birelation_left, vals.birelation_right
    ]

    graph = nx.Graph()
    graph.add_nodes_from(full_catalog)
    shgraph.graph = graph

    for sub in shgraph.get_graphs():
        assert isinstance(sub, nx.DiGraph)
Пример #2
0
    def _execute(self,
                 barf: bool = False,
                 name: Optional[str] = None) -> Optional[str]:
        graph = SnowShuGraph()
        if name is not None:
            self.config.name = name

        graph.build_graph(self.config)

        if self.incremental:
            # TODO replica container should not be started for analyze commands
            self.config.target_profile.adapter.initialize_replica(
                self.config.source_profile.name, self.incremental)

            incremental_target_catalog = self.config.target_profile.adapter.build_catalog(
                patterns=SnowShuGraph.build_sum_patterns_from_configs(
                    self.config),
                thread_workers=self.config.threads)

            graph.graph = SnowShuGraph.catalog_difference(
                graph.graph, incremental_target_catalog)
        graphs = graph.get_connected_subgraphs()
        if len(graphs) < 1:
            args = (' new ', ' incremental ',
                    '; image up-to-date') if self.incremental else (' ', ' ',
                                                                    '')
            message = "No{}relations found per provided{}replica configuration{}, exiting.".format(
                *args)
            return message

        if not self.config.target_profile.adapter.container:
            # TODO replica container should not be started for analyze commands
            self.config.target_profile.adapter.initialize_replica(
                self.config.source_profile.name)

        runner = GraphSetRunner()
        runner.execute_graph_set(graphs,
                                 self.config.source_profile.adapter,
                                 self.config.target_profile.adapter,
                                 threads=self.config.threads,
                                 analyze=self.run_analyze,
                                 barf=barf)
        if not self.run_analyze:
            relations = [
                relation for graph in graphs for relation in graph.nodes
            ]
            if self.config.source_profile.adapter.SUPPORTS_CROSS_DATABASE:
                logger.info('Creating x-database links in target...')
                self.config.target_profile.adapter.enable_cross_database()
                logger.info('X-database enabled.')
            self.config.target_profile.adapter.create_all_database_extensions()

            logger.info('Applying %s emulation functions to target...',
                        self.config.source_profile.adapter.name)
            for function in self.config.source_profile.adapter.SUPPORTED_FUNCTIONS:
                self.config.target_profile.adapter.create_function_if_available(
                    function, relations)
            logger.info('Emulation functions applied.')
            self.config.target_profile.adapter.finalize_replica()

        return printable_result(graph_to_result_list(graphs), self.run_analyze)