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 __init__(
      self,
      *,
      table: str,
      metrics_thresholds: dict[str, int],
      date_filter_column: str | None = "ds",
      days_back: SupportsAbs[int] = -7,
      ratio_formula: str | None = "max_over_min",
      ignore_zero: bool = True,
      conn_id: str | None = None,
      database: str | None = None,
      **kwargs,
  ):
      super().__init__(conn_id=conn_id, database=database, **kwargs)
      if ratio_formula not in self.ratio_formulas:
          msg_template = "Invalid diff_method: {diff_method}. Supported diff methods are: {diff_methods}"
  
          raise AirflowFailException(
              msg_template.format(
                  diff_method=ratio_formula,
                  diff_methods=self.ratio_formulas,
              )
          )
      self.ratio_formula = ratio_formula
      self.ignore_zero = ignore_zero
      self.table = table
      self.metrics_thresholds = metrics_thresholds
      self.metrics_sorted = sorted(metrics_thresholds.keys())
      self.date_filter_column = date_filter_column
      self.days_back = -abs(days_back)
      sqlexp = ", ".join(self.metrics_sorted)
      sqlt = f"SELECT {sqlexp} FROM {table} WHERE {date_filter_column}="
  
      self.sql1 = f"{sqlt}'{{{{ ds }}}}'"
      self.sql2 = (
          f"{sqlt}'{{{{ macros.ds_add(ds, {self.days_back}) }}}}'"
      )
  
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 1 to create a new SQLIntervalCheckOperator object from inherited base classes: BaseSQLOperator with example: obj = SQLIntervalCheckOperator()