Esempio n. 1
0
    def execute(self, test, manifest):
        failed_rows = self.execute_test(test)
        severity = test.config['severity'].upper()

        if failed_rows == 0:
            return RunModelResult(test, status=failed_rows)
        elif severity == 'ERROR' or dbt.flags.WARN_ERROR:
            return RunModelResult(test, status=failed_rows, failed=True)
        else:
            return RunModelResult(test, status=failed_rows, warned=True)
Esempio n. 2
0
    def on_skip(self):
        schema_name = self.node.schema
        node_name = self.node.name

        error = None
        if not self.is_ephemeral_model(self.node):
            # if this model was skipped due to an upstream ephemeral model
            # failure, print a special 'error skip' message.
            if self._skip_caused_by_ephemeral_failure():
                dbt.ui.printer.print_skip_caused_by_error(
                    self.node,
                    schema_name,
                    node_name,
                    self.node_index,
                    self.num_nodes,
                    self.skip_cause
                )
                # set an error so dbt will exit with an error code
                error = (
                    'Compilation Error in {}, caused by compilation error '
                    'in referenced ephemeral model {}'
                    .format(self.node.unique_id,
                            self.skip_cause.node.unique_id)
                )
            else:
                dbt.ui.printer.print_skip_line(
                    self.node,
                    schema_name,
                    node_name,
                    self.node_index,
                    self.num_nodes
                )

        node_result = RunModelResult(self.node, skip=True, error=error)
        return node_result
Esempio n. 3
0
    def on_skip(self):
        schema_name = self.node.schema
        node_name = self.node.name

        error = None
        if not self.node.is_ephemeral_model:
            # if this model was skipped due to an upstream ephemeral model
            # failure, print a special 'error skip' message.
            if self._skip_caused_by_ephemeral_failure():
                print_skip_caused_by_error(self.node, schema_name, node_name,
                                           self.node_index, self.num_nodes,
                                           self.skip_cause)
                if self.skip_cause is None:  # mypy appeasement
                    raise InternalException(
                        'Skip cause not set but skip was somehow caused by '
                        'an ephemeral failure')
                # set an error so dbt will exit with an error code
                error = (
                    'Compilation Error in {}, caused by compilation error '
                    'in referenced ephemeral model {}'.format(
                        self.node.unique_id, self.skip_cause.node.unique_id))
            else:
                print_skip_line(self.node, schema_name, node_name,
                                self.node_index, self.num_nodes)

        node_result = RunModelResult(self.node, skip=True, error=error)
        return node_result
Esempio n. 4
0
    def execute(self, test: CompiledTestNode, manifest: Manifest):
        if isinstance(test, CompiledDataTestNode):
            failed_rows = self.execute_data_test(test)
        elif isinstance(test, CompiledSchemaTestNode):
            failed_rows = self.execute_schema_test(test)
        else:

            raise InternalException(
                f'Expected compiled schema test or compiled data test, got '
                f'{type(test)}'
            )
        severity = test.config.severity.upper()

        if failed_rows == 0:
            return RunModelResult(test, status=failed_rows)
        elif severity == 'ERROR' or flags.WARN_ERROR:
            return RunModelResult(test, status=failed_rows, fail=True)
        else:
            return RunModelResult(test, status=failed_rows, warn=True)
Esempio n. 5
0
    def on_skip(self):
        schema_name = self.node.schema
        node_name = self.node.name

        if not self.is_ephemeral_model(self.node):
            dbt.ui.printer.print_skip_line(self.node, schema_name, node_name,
                                           self.node_index, self.num_nodes)

        node_result = RunModelResult(self.node, skip=True)
        return node_result
Esempio n. 6
0
    def safe_run(self, manifest):
        catchable_errors = (dbt.exceptions.CompilationException,
                            dbt.exceptions.RuntimeException)

        result = RunModelResult(self.node)
        started = time.time()

        try:
            # if we fail here, we still have a compiled node to return
            # this has the benefit of showing a build path for the errant model
            compiled_node = self.compile(manifest)
            result.node = compiled_node

            # for ephemeral nodes, we only want to compile, not run
            if not self.is_ephemeral_model(self.node):
                result = self.run(compiled_node, manifest)

        except catchable_errors as e:
            if e.node is None:
                e.node = result.node

            result.error = dbt.compat.to_string(e)
            result.status = 'ERROR'

        except dbt.exceptions.InternalException as e:
            build_path = self.node.build_path
            prefix = 'Internal error executing {}'.format(build_path)

            error = "{prefix}\n{error}\n\n{note}".format(
                prefix=dbt.ui.printer.red(prefix),
                error=str(e).strip(),
                note=INTERNAL_ERROR_STRING)
            logger.debug(error)

            result.error = dbt.compat.to_string(e)
            result.status = 'ERROR'

        except Exception as e:
            prefix = "Unhandled error while executing {filepath}".format(
                filepath=self.node.build_path)

            error = "{prefix}\n{error}".format(
                prefix=dbt.ui.printer.red(prefix), error=str(e).strip())

            logger.debug(error)
            raise e

        finally:
            node_name = self.node.name
            self.adapter.release_connection(self.profile, node_name)

        result.execution_time = time.time() - started
        return result
Esempio n. 7
0
    def execute(self, model, manifest):
        context = dbt.context.runtime.generate(model, self.project.cfg,
                                               manifest)

        materialization_macro = manifest.get_materialization_macro(
            model.get_materialization(), self.adapter.type())

        if materialization_macro is None:
            dbt.exceptions.missing_materialization(model, self.adapter.type())

        materialization_macro.generator(context)()

        result = context['load_result']('main')

        return RunModelResult(model, status=result.status)
Esempio n. 8
0
    def execute(self, model, manifest):
        context = dbt.context.runtime.generate(model, self.config, manifest)

        materialization_macro = manifest.get_materialization_macro(
            model.get_materialization(), self.adapter.type())

        if materialization_macro is None:
            missing_materialization(model, self.adapter.type())

        materialization_macro.generator(context)()

        # we must have built a new model, add it to the cache
        relation = self.adapter.Relation.create_from_node(self.config, model)
        self.adapter.cache_new_relation(relation)

        result = context['load_result']('main')

        return RunModelResult(model, status=result.status)
Esempio n. 9
0
 def _build_run_result(self,
                       node,
                       start_time,
                       error,
                       status,
                       timing_info,
                       skip=False,
                       failed=None):
     execution_time = time.time() - start_time
     thread_id = threading.current_thread().name
     timing = [t.serialize() for t in timing_info]
     return RunModelResult(node=node,
                           error=error,
                           skip=skip,
                           status=status,
                           failed=failed,
                           execution_time=execution_time,
                           thread_id=thread_id,
                           timing=timing)
Esempio n. 10
0
 def _build_run_result(self,
                       node,
                       start_time,
                       error,
                       status,
                       timing_info,
                       skip=False,
                       fail=None,
                       warn=None,
                       agate_table=None):
     execution_time = time.time() - start_time
     thread_id = threading.current_thread().name
     return RunModelResult(
         node=node,
         error=error,
         skip=skip,
         status=status,
         fail=fail,
         warn=warn,
         execution_time=execution_time,
         thread_id=thread_id,
         timing=timing_info,
         agate_table=agate_table,
     )
Esempio n. 11
0
 def execute(self, compiled_node, manifest):
     return RunModelResult(compiled_node)
Esempio n. 12
0
    def safe_run(self, manifest):
        catchable_errors = (dbt.exceptions.CompilationException,
                            dbt.exceptions.RuntimeException)

        result = RunModelResult(self.node)
        started = time.time()
        exc_info = (None, None, None)

        try:
            # if we fail here, we still have a compiled node to return
            # this has the benefit of showing a build path for the errant model
            compiled_node = self.compile(manifest)
            result.node = compiled_node

            # for ephemeral nodes, we only want to compile, not run
            if not self.is_ephemeral_model(self.node):
                result = self.run(compiled_node, manifest)

        except catchable_errors as e:
            if e.node is None:
                e.node = result.node

            result.error = dbt.compat.to_string(e)
            result.status = 'ERROR'

        except dbt.exceptions.InternalException as e:
            build_path = self.node.build_path
            prefix = 'Internal error executing {}'.format(build_path)

            error = "{prefix}\n{error}\n\n{note}".format(
                         prefix=dbt.ui.printer.red(prefix),
                         error=str(e).strip(),
                         note=INTERNAL_ERROR_STRING)
            logger.debug(error)

            result.error = dbt.compat.to_string(e)
            result.status = 'ERROR'

        except Exception as e:
            # set this here instead of finally, as python 2/3 exc_info()
            # behavior with re-raised exceptions are slightly different
            exc_info = sys.exc_info()
            prefix = "Unhandled error while executing {filepath}".format(
                        filepath=self.node.build_path)

            error = "{prefix}\n{error}".format(
                         prefix=dbt.ui.printer.red(prefix),
                         error=str(e).strip())

            logger.error(error)
            raise e

        finally:
            exc_str = self._safe_release_connection()

            # if we had an unhandled exception, re-raise it
            if exc_info and exc_info[1]:
                six.reraise(*exc_info)

            # if releasing failed and the result doesn't have an error yet, set
            # an error
            if exc_str is not None and result.error is None:
                result.error = exc_str
                result.status = 'ERROR'

        result.execution_time = time.time() - started
        return result
Esempio n. 13
0
 def execute(self, test, manifest):
     status = self.execute_test(test)
     return RunModelResult(test, status=status)
Esempio n. 14
0
 def _build_run_model_result(self, model, context):
     result = context['load_result']('main')
     return RunModelResult(model, status=result.status)