示例#1
0
 def create_ephemeral_relation(self, target_model: NonSourceNode,
                               name: str) -> RelationProxy:
     self.model.set_cte(target_model.unique_id, None)
     return self.Relation.create(
         type=self.Relation.CTE,
         identifier=add_ephemeral_model_prefix(name)).quote(
             identifier=False)
示例#2
0
    def do_ref(*args):
        target_model_name = None
        target_model_package = None

        if len(args) == 1:
            target_model_name = args[0]
        elif len(args) == 2:
            target_model_package, target_model_name = args
        else:
            dbt.exceptions.ref_invalid_args(model, args)

        target_model = dbt.parser.ParserUtils.resolve_ref(
            manifest, target_model_name, target_model_package, current_project,
            model.get('package_name'))

        if target_model is None:
            dbt.exceptions.ref_target_not_found(model, target_model_name,
                                                target_model_package)

        target_model_id = target_model.get('unique_id')

        if target_model_id not in model.get('depends_on', {}).get('nodes'):
            dbt.exceptions.ref_bad_context(model, target_model_name,
                                           target_model_package)

        is_ephemeral = (get_materialization(target_model) == 'ephemeral')

        if is_ephemeral:
            model.set_cte(target_model_id, None)
            return adapter.Relation.create(
                type=adapter.Relation.CTE,
                identifier=add_ephemeral_model_prefix(
                    target_model_name)).quote(identifier=False)
        else:
            return adapter.Relation.create_from_node(profile, target_model)