Example #1
0
    def information_schema(self, identifier=None):
        include_db = self.database is not None
        include_policy = filter_null_values({
            'database':
            include_db,
            'schema':
            True,
            'identifier':
            identifier is not None
        })
        quote_policy = filter_null_values({
            'database':
            self.quote_policy['database'],
            'schema':
            False,
            'identifier':
            False,
        })

        path_update = {
            'schema': 'information_schema',
            'identifier': identifier
        }

        return self.incorporate(quote_policy=quote_policy,
                                include_policy=include_policy,
                                path=path_update,
                                table_name=identifier)
Example #2
0
    def matches(
        self,
        database: Optional[str] = None,
        schema: Optional[str] = None,
        identifier: Optional[str] = None,
    ) -> bool:
        search = filter_null_values({
            ComponentName.Database: database,
            ComponentName.Schema: schema,
            ComponentName.Identifier: identifier
        })

        if not search:
            # nothing was passed in
            raise dbt.exceptions.RuntimeException(
                "Tried to match relation, but no search path was passed!")

        exact_match = True
        approximate_match = True

        for k, v in search.items():
            if not self._is_exactish_match(k, v):
                exact_match = False

            if self.path.get_lowered_part(k) != v.lower():
                approximate_match = False

        if approximate_match and not exact_match:
            target = self.create(database=database,
                                 schema=schema,
                                 identifier=identifier)
            dbt.exceptions.approximate_relation_match(target, self)

        return exact_match
Example #3
0
 def _make_match_kwargs(self, database: str, schema: str,
                        identifier: str) -> Dict[str, str]:
     return filter_null_values({
         'database': database,
         'identifier': identifier,
         'schema': schema,
     })
Example #4
0
    def matches(self, database=None, schema=None, identifier=None):
        search = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        if not search:
            # nothing was passed in
            raise dbt.exceptions.RuntimeException(
                "Tried to match relation, but no search path was passed!")

        exact_match = True
        approximate_match = True

        for k, v in search.items():
            if self.get_path_part(k) != v:
                exact_match = False

            if self.get_path_part(k).lower() != v.lower():
                approximate_match = False

        if approximate_match and not exact_match:
            target = self.create(
                database=database, schema=schema, identifier=identifier)
            dbt.exceptions.approximate_relation_match(target, self)

        return exact_match
Example #5
0
    def matches(self, database=None, schema=None, identifier=None):
        search = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        if not search:
            # nothing was passed in
            raise dbt.exceptions.RuntimeException(
                "Tried to match relation, but no search path was passed!")

        exact_match = True
        approximate_match = True

        for k, v in search.items():
            if self.get_path_part(k) != v:
                exact_match = False

            if self.get_path_part(k).lower() != v.lower():
                approximate_match = False

        if approximate_match and not exact_match:
            target = self.create(database=database,
                                 schema=schema,
                                 identifier=identifier)
            dbt.exceptions.approximate_relation_match(target, self)

        return exact_match
Example #6
0
    def include(self, project=None, schema=None, identifier=None):
        policy = filter_null_values({
            'project': project,
            'schema': schema,
            'identifier': identifier
        })

        return self.incorporate(include_policy=policy)
Example #7
0
    def quote(self, database=None, schema=None, identifier=None):
        policy = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        return self.incorporate(quote_policy=policy)
Example #8
0
    def include(self, database=None, schema=None, identifier=None):
        policy = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        return self.incorporate(include_policy=policy)
Example #9
0
    def _make_match_kwargs(self, schema, identifier):
        quoting = self.config.quoting
        if identifier is not None and quoting['identifier'] is False:
            identifier = identifier.lower()

        if schema is not None and quoting['schema'] is False:
            schema = schema.lower()

        return filter_null_values({'identifier': identifier, 'schema': schema})
Example #10
0
    def _make_match_kwargs(cls, project_cfg, schema, identifier):
        if identifier is not None and \
           project_cfg.get('quoting', {}).get('identifier') is False:
            identifier = identifier.lower()

        if schema is not None and \
           project_cfg.get('quoting', {}).get('schema') is False:
            schema = schema.lower()

        return filter_null_values({'identifier': identifier, 'schema': schema})
Example #11
0
    def include(
        self: Self,
        database: Optional[bool] = None,
        schema: Optional[bool] = None,
        identifier: Optional[bool] = None,
    ) -> Self:
        policy = filter_null_values({
            ComponentName.Database: database,
            ComponentName.Schema: schema,
            ComponentName.Identifier: identifier
        })

        new_include_policy = self.include_policy.replace_dict(policy)
        return self.replace(include_policy=new_include_policy)
Example #12
0
    def information_schema(self, identifier=None):
        include_db = self.database is not None
        include_policy = filter_null_values({
            'database': include_db,
            'schema': True,
            'identifier': identifier is not None
        })
        quote_policy = filter_null_values({
            'database': self.quote_policy['database'],
            'schema': False,
            'identifier': False,
        })

        path_update = {
            'schema': 'information_schema',
            'identifier': identifier
        }

        return self.incorporate(
            quote_policy=quote_policy,
            include_policy=include_policy,
            path=path_update,
            table_name=identifier)
Example #13
0
    def _make_match_kwargs(self, database, schema, identifier):
        quoting = self.config.quoting
        if identifier is not None and quoting["identifier"] is False:
            identifier = identifier.upper()

        if schema is not None and quoting["schema"] is False:
            schema = schema.upper()

        if database is not None and quoting["database"] is False:
            database = database.upper()

        return filter_null_values(
            {"identifier": identifier, "schema": schema, "database": database}
        )
Example #14
0
    def _make_match_kwargs(self, database: str, schema: str,
                           identifier: str) -> Dict[str, str]:
        quoting = self.config.quoting
        if identifier is not None and quoting['identifier'] is False:
            identifier = identifier.lower()

        if schema is not None and quoting['schema'] is False:
            schema = schema.lower()

        if database is not None and quoting['database'] is False:
            database = database.lower()

        return filter_null_values({
            'identifier': identifier,
            'schema': schema,
        })
Example #15
0
    def _make_match_kwargs(self, database, schema, identifier):
        quoting = self.config.quoting
        if identifier is not None and quoting['identifier'] is False:
            identifier = identifier.lower()

        if schema is not None and quoting['schema'] is False:
            schema = schema.lower()

        if database is not None and quoting['schema'] is False:
            database = database.lower()

        return filter_null_values({
            'database': database,
            'identifier': identifier,
            'schema': schema,
        })
Example #16
0
    def _make_match_kwargs(self, database, schema, identifier):
        quoting = self.config.quoting
        if identifier is not None and quoting['identifier'] is False:
            identifier = identifier.upper()

        if schema is not None and quoting['schema'] is False:
            schema = schema.upper()

        if database is not None and quoting['database'] is False:
            database = database.upper()

        return filter_null_values({
            'identifier': identifier,
            'schema': schema,
            'database': database
        })
Example #17
0
    def matches(self, project=None, schema=None, identifier=None):
        search = filter_null_values({
            'project': project,
            'schema': schema,
            'identifier': identifier
        })

        if not search:
            # nothing was passed in
            pass

        for k, v in search.items():
            if self.get_path_part(k) != v:
                return False

        return True
Example #18
0
    def matches(self, database=None, schema=None, identifier=None):
        search = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        if not search:
            # nothing was passed in
            pass

        for k, v in search.items():
            if not self._is_exactish_match(k, v):
                return False

        return True
Example #19
0
    def matches(self, database=None, schema=None, identifier=None):
        search = filter_null_values({
            'database': database,
            'schema': schema,
            'identifier': identifier
        })

        if not search:
            # nothing was passed in
            pass

        for k, v in search.items():
            if self.get_path_part(k) != v:
                return False

        return True
Example #20
0
    def matches(
        self,
        database: Optional[str] = None,
        schema: Optional[str] = None,
        identifier: Optional[str] = None,
    ) -> bool:
        search = filter_null_values({
            ComponentName.Database: database,
            ComponentName.Schema: schema,
            ComponentName.Identifier: identifier
        })

        if not search:
            # nothing was passed in
            pass

        for k, v in search.items():
            if not self._is_exactish_match(k, v):
                return False

        return True