sqlmesh.core.audit.builtin API documentation

Edit on GitHub

# sqlmesh.core.audit.builtin

View Source

     1from __future__ import annotations
     2
     3from sqlmesh.core.audit.definition import Audit
     4
     5not_null_audit = Audit(
     6    name="not_null",
     7    query="""
     8SELECT *
     9FROM @this_model
    10WHERE @REDUCE(
    11  @EACH(
    12    @columns,
    13    c -> c IS NULL
    14  ),
    15  (l, r) -> l OR r
    16)
    17    """,
    18)
    19
    20
    21unique_values_audit = Audit(
    22    name="unique_values",
    23    query="""
    24SELECT *
    25FROM (
    26  SELECT
    27    @EACH(
    28      @columns,
    29      c -> row_number() OVER (PARTITION BY c ORDER BY 1) AS @SQL('@{c}_rank')
    30    )
    31  FROM @this_model
    32)
    33WHERE @REDUCE(
    34  @EACH(
    35    @columns,
    36    c -> @SQL('@{c}_rank') > 1
    37  ),
    38  (l, r) -> l OR r
    39)
    40    """,
    41)
    42
    43
    44accepted_values_audit = Audit(
    45    name="accepted_values",
    46    query="""
    47SELECT *
    48FROM @this_model
    49WHERE @column NOT IN @values
    50""",
    51)
    52
    53
    54number_of_rows_audit = Audit(
    55    name="number_of_rows",
    56    query="""
    57SELECT 1
    58FROM @this_model
    59LIMIT @threshold + 1
    60HAVING COUNT(*) <= @threshold
    61    """,
    62)