class_docstr: Check that metrics given as SQL expressions are within tolerance of the ones from days_back before.
  
  :param table: the table name
  :param conn_id: the connection ID used to connect to the database.
  :param database: name of database which will overwrite the defined one in connection
  :param days_back: number of days between ds and the ds we want to check
      against. Defaults to 7 days
  :param date_filter_column: The column name for the dates to filter on. Defaults to 'ds'
  :param ratio_formula: which formula to use to compute the ratio between
      the two metrics. Assuming cur is the metric of today and ref is
      the metric to today - days_back. Default: 'max_over_min'
  
      * ``max_over_min``: computes max(cur, ref) / min(cur, ref)
      * ``relative_diff``: computes abs(cur-ref) / ref
  
  :param ignore_zero: whether we should ignore zero metrics
  :param metrics_thresholds: a dictionary of ratios indexed by metrics
class_docstr_tok: ["Check","that","metrics","given","as","SQL","expressions","are","within","tolerance","of","the","ones","from","days_back","before",".",":","param","table",":","the","table","name",":","param","conn_id",":","the","connection","ID","used","to","connect","to","the","database",".",":","param","database",":","name","of","database","which","will","overwrite","the","defined","one","in","connection",":","param","days_back",":","number","of","days","between","ds","and","the","ds","we","want","to","check","against",".","Defaults","to","7","days",":","param","date_filter_column",":","The","column","name","for","the","dates","to","filter","on",".","Defaults","to","'ds'",":","param","ratio_formula",":","which","formula","to","use","to","compute","the","ratio","between","the","two","metrics",".","Assuming","cur","is","the","metric","of","today","and","ref","is","the","metric","to","today","-","days_back",".","Default",":","'max_over_min'","*","``","max_over_min","``",":","computes","max","(","cur",",","ref",")","\/","min","(","cur",",","ref",")","*","``","relative_diff","``",":","computes","abs","(","cur-ref",")","\/","ref",":","param","ignore_zero",":","whether","we","should","ignore","zero","metrics",":","param","metrics_thresholds",":","a","dictionary","of","ratios","indexed","by","metrics"]
code: def execute(self, context: Context):
      hook = self.get_db_hook()
      self.log.info("Using ratio formula: %s", self.ratio_formula)
      self.log.info("Executing SQL check: %s", self.sql2)
      row2 = hook.get_first(self.sql2)
      self.log.info("Executing SQL check: %s", self.sql1)
      row1 = hook.get_first(self.sql1)
  
      if not row2:
          self._raise_exception(
              f"The following query returned zero rows: {self.sql2}"
          )
      if not row1:
          self._raise_exception(
              f"The following query returned zero rows: {self.sql1}"
          )
  
      current = dict(zip(self.metrics_sorted, row1))
      reference = dict(zip(self.metrics_sorted, row2))
  
      ratios: dict[str, int | None] = {}
      test_results = {}
  
      for metric in self.metrics_sorted:
          cur = current[metric]
          ref = reference[metric]
          threshold = self.metrics_thresholds[metric]
          if cur == 0 or ref == 0:
              ratios[metric] = None
              test_results[metric] = self.ignore_zero
          else:
              ratio_metric = self.ratio_formulas[self.ratio_formula](
                  current[metric], reference[metric]
              )
              ratios[metric] = ratio_metric
              if ratio_metric is not None:
                  test_results[metric] = ratio_metric < threshold
              else:
                  test_results[metric] = self.ignore_zero
  
          self.log.info(
              (
                  "Current metric for %s: %s\n"
                  "Past metric for %s: %s\n"
                  "Ratio for %s: %s\n"
                  "Threshold: %s\n"
              ),
              metric,
              cur,
              metric,
              ref,
              metric,
              ratios[metric],
              threshold,
          )
  
      if not all(test_results.values()):
          failed_tests = [
              it[0] for it in test_results.items() if not it[1]
          ]
          self.log.warning(
              "The following %s tests out of %s failed:",
              len(failed_tests),
              len(self.metrics_sorted),
          )
          for k in failed_tests:
              self.log.warning(
                  "'%s' check failed. %s is above %s",
                  k,
                  ratios[k],
                  self.metrics_thresholds[k],
              )
          self._raise_exception(
              f"The following tests have failed:\n {', '.join(sorted(failed_tests))}"
          )
  
      self.log.info("All tests have passed")
  
imports: from __future__ import annotations
  import ast
  import re
  from functools import cached_property
  from typing import TYPE_CHECKING, Any, Callable, Iterable, Mapping, NoReturn, Sequence, SupportsAbs
  from airflow.exceptions import AirflowException, AirflowFailException
  from airflow.hooks.base import BaseHook
  from airflow.models import BaseOperator, SkipMixin
  from airflow.providers.common.sql.hooks.sql import DbApiHook, fetch_all_handler, return_single_query_results
  from airflow.utils.helpers import merge_dicts
label_desc: Use image node_id 2 for calling the SQLIntervalCheckOperator obj's underlying member method code with example usage: obj.execute(context) without return types