def init(self, conf: ConfigTree) -> None:
        """
        Establish connections and import data model class if provided
        :param conf:
        """
        self.conf = conf.with_fallback(Neo4jExtractor.DEFAULT_CONFIG)
        self.graph_url = conf.get_string('graph_url')

        self.included_keys = conf.get('included_keys', None)
        self.excluded_keys = conf.get('excluded_keys', None)
        self.included_key_regex = conf.get('included_key_regex', None)
        self.excluded_key_regex = conf.get('excluded_key_regex', None)

        # Add where clause based on configuration inputs.
        keys = ['schema.key', 'db.key', 'cluster.key', 'table.key']
        or_where_clauses = []
        and_where_clauses = []
        if self.included_keys is not None:
            for key in keys:
                or_where_clauses \
                    .append('{} IN {}'.format(key, self.included_keys))

        if self.excluded_keys is not None:
            for key in keys:
                and_where_clauses \
                    .append('{} NOT IN {}'.format(key, self.excluded_keys))

        if self.included_key_regex is not None:
            for key in keys:
                or_where_clauses \
                    .append(
                        "{} =~ '{}'"
                        .format(key, self.included_key_regex))

        if self.excluded_key_regex is not None:
            for key in keys:
                and_where_clauses \
                    .append(
                        "NOT {} =~ '{}'"
                        .format(key, self.excluded_key_regex))

        where_clause = combine_where_clauses(and_clauses=and_where_clauses,
                                             or_clauses=or_where_clauses)

        self.cypher_query = \
            AmundsenNeo4jMetadataExtractor.CYPHER_QUERY.format(
                where_clause=where_clause
            )
        self.driver = self._get_driver()

        self._extract_iter = None
Beispiel #2
0
def test_combine_where_clauses_with_result():
    statement = combine_where_clauses(and_clauses=AND_CLAUSES,
                                      or_clauses=OR_CLAUSES)
    assert "WHERE" in statement
Beispiel #3
0
def test_combine_where_clauses_with_no_result():
    statement = combine_where_clauses()
    assert statement == ""