Skip to content

Last updated: July 22, 2025

Percentile 25 in range data quality checks, SQL examples

This check finds the 25th percentile value in a numeric column. The 10th percentile is a value greater than 25% of the smallest values and smaller than the remaining 75% of other values. This check verifies that the 25th percentile is within the range of accepted values and raises a data quality issue when it is not within a valid range.


The percentile 25 in range data quality check has the following variants for each type of data quality checks supported by DQOps.

profile percentile 25 in range

Check description

Verifies that the percentile 25 of all values in a column is not outside the expected range.

Data quality check name Friendly name Category Check type Time scale Quality dimension Sensor definition Quality rule Standard
profile_percentile_25_in_range The selected 25th percentile of numeric values is in the range numeric profiling Reasonableness percentile between_floats

Command-line examples

Please expand the section below to see the DQOps command-line examples to run or activate the profile percentile 25 in range data quality check.

Managing profile percentile 25 in range check from DQOps shell

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the warning rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=profile_percentile_25_in_range --enable-warning

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=profile_percentile_25_in_range --enable-warning

Additional rule parameters are passed using the -Wrule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=profile_percentile_25_in_range --enable-warning
                    -Wfrom=value

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the error rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=profile_percentile_25_in_range --enable-error

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=profile_percentile_25_in_range --enable-error

Additional rule parameters are passed using the -Erule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=profile_percentile_25_in_range --enable-error
                    -Efrom=value

Run this data quality check using the check run CLI command by providing the check name and all other targeting filters. The following example shows how to run the profile_percentile_25_in_range check on all tables and columns on a single data source.

dqo> check run -c=data_source_name -ch=profile_percentile_25_in_range

It is also possible to run this check on a specific connection and table. In order to do this, use the connection name and the full table name parameters.

dqo> check run -c=connection_name -t=schema_name.table_name -ch=profile_percentile_25_in_range

You can also run this check on all tables (and columns) on which the profile_percentile_25_in_range check is enabled using patterns to find tables.

dqo> check run -c=connection_name -t=schema_prefix*.fact_* -col=column_name_* -ch=profile_percentile_25_in_range

YAML configuration

The sample schema_name.table_name.dqotable.yaml file with the check configured is shown below.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  columns:
    target_column:
      profiling_checks:
        numeric:
          profile_percentile_25_in_range:
            parameters:
              percentile_value: 0.25
            error:
              from: 10.0
              to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
Samples of generated SQL queries for each data source type

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile data quality sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM  AS analyzed_table
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_table>" original_table
) analyzed_table
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value
FROM "<target_schema>"."<target_table>" analyzed_table
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table

Expand the Configure with data grouping section to see additional examples for configuring this data quality checks to use data grouping (GROUP BY).

Configuration with data grouping

Sample configuration with data grouping enabled (YAML) The sample below shows how to configure the data grouping and how it affects the generated SQL query.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  default_grouping_name: group_by_country_and_state
  groupings:
    group_by_country_and_state:
      level_1:
        source: column_value
        column: country
      level_2:
        source: column_value
        column: state
  columns:
    target_column:
      profiling_checks:
        numeric:
          profile_percentile_25_in_range:
            parameters:
              percentile_value: 0.25
            error:
              from: 10.0
              to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    country:
      labels:
      - column used as the first grouping key
    state:
      labels:
      - column used as the second grouping key

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    analyzed_table.grouping_level_1,
    analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM  AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            original_table."country",
            original_table."state"
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2

FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            analyzed_table.[country],
            analyzed_table.[state]
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2

daily percentile 25 in range

Check description

Verifies that the percentile 25 of all values in a column is not outside the expected range. Stores the most recent captured value for each day when the data quality check was evaluated.

Data quality check name Friendly name Category Check type Time scale Quality dimension Sensor definition Quality rule Standard
daily_percentile_25_in_range The selected 25th percentile of numeric values is in the range numeric monitoring daily Reasonableness percentile between_floats

Command-line examples

Please expand the section below to see the DQOps command-line examples to run or activate the daily percentile 25 in range data quality check.

Managing daily percentile 25 in range check from DQOps shell

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the warning rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=daily_percentile_25_in_range --enable-warning

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_percentile_25_in_range --enable-warning

Additional rule parameters are passed using the -Wrule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_percentile_25_in_range --enable-warning
                    -Wfrom=value

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the error rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=daily_percentile_25_in_range --enable-error

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_percentile_25_in_range --enable-error

Additional rule parameters are passed using the -Erule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_percentile_25_in_range --enable-error
                    -Efrom=value

Run this data quality check using the check run CLI command by providing the check name and all other targeting filters. The following example shows how to run the daily_percentile_25_in_range check on all tables and columns on a single data source.

dqo> check run -c=data_source_name -ch=daily_percentile_25_in_range

It is also possible to run this check on a specific connection and table. In order to do this, use the connection name and the full table name parameters.

dqo> check run -c=connection_name -t=schema_name.table_name -ch=daily_percentile_25_in_range

You can also run this check on all tables (and columns) on which the daily_percentile_25_in_range check is enabled using patterns to find tables.

dqo> check run -c=connection_name -t=schema_prefix*.fact_* -col=column_name_* -ch=daily_percentile_25_in_range

YAML configuration

The sample schema_name.table_name.dqotable.yaml file with the check configured is shown below.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  columns:
    target_column:
      monitoring_checks:
        daily:
          numeric:
            daily_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
Samples of generated SQL queries for each data source type

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile data quality sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM  AS analyzed_table
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_table>" original_table
) analyzed_table
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value
FROM "<target_schema>"."<target_table>" analyzed_table
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table

Expand the Configure with data grouping section to see additional examples for configuring this data quality checks to use data grouping (GROUP BY).

Configuration with data grouping

Sample configuration with data grouping enabled (YAML) The sample below shows how to configure the data grouping and how it affects the generated SQL query.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  default_grouping_name: group_by_country_and_state
  groupings:
    group_by_country_and_state:
      level_1:
        source: column_value
        column: country
      level_2:
        source: column_value
        column: state
  columns:
    target_column:
      monitoring_checks:
        daily:
          numeric:
            daily_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    country:
      labels:
      - column used as the first grouping key
    state:
      labels:
      - column used as the second grouping key

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    analyzed_table.grouping_level_1,
    analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM  AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            original_table."country",
            original_table."state"
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2

FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            analyzed_table.[country],
            analyzed_table.[state]
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2

monthly percentile 25 in range

Check description

Verifies that the percentile 25 of all values in a column is not outside the expected range. Stores the most recent value for each month when the data quality check was evaluated.

Data quality check name Friendly name Category Check type Time scale Quality dimension Sensor definition Quality rule Standard
monthly_percentile_25_in_range The selected 25th percentile of numeric values is in the range numeric monitoring monthly Reasonableness percentile between_floats

Command-line examples

Please expand the section below to see the DQOps command-line examples to run or activate the monthly percentile 25 in range data quality check.

Managing monthly percentile 25 in range check from DQOps shell

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the warning rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=monthly_percentile_25_in_range --enable-warning

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_percentile_25_in_range --enable-warning

Additional rule parameters are passed using the -Wrule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_percentile_25_in_range --enable-warning
                    -Wfrom=value

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the error rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=monthly_percentile_25_in_range --enable-error

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_percentile_25_in_range --enable-error

Additional rule parameters are passed using the -Erule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_percentile_25_in_range --enable-error
                    -Efrom=value

Run this data quality check using the check run CLI command by providing the check name and all other targeting filters. The following example shows how to run the monthly_percentile_25_in_range check on all tables and columns on a single data source.

dqo> check run -c=data_source_name -ch=monthly_percentile_25_in_range

It is also possible to run this check on a specific connection and table. In order to do this, use the connection name and the full table name parameters.

dqo> check run -c=connection_name -t=schema_name.table_name -ch=monthly_percentile_25_in_range

You can also run this check on all tables (and columns) on which the monthly_percentile_25_in_range check is enabled using patterns to find tables.

dqo> check run -c=connection_name -t=schema_prefix*.fact_* -col=column_name_* -ch=monthly_percentile_25_in_range

YAML configuration

The sample schema_name.table_name.dqotable.yaml file with the check configured is shown below.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  columns:
    target_column:
      monitoring_checks:
        monthly:
          numeric:
            monthly_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
Samples of generated SQL queries for each data source type

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile data quality sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM  AS analyzed_table
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value
FROM(
    SELECT
        original_table.*
    FROM "<target_table>" original_table
) analyzed_table
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value
FROM "<target_schema>"."<target_table>" analyzed_table
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            NULL
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table

Expand the Configure with data grouping section to see additional examples for configuring this data quality checks to use data grouping (GROUP BY).

Configuration with data grouping

Sample configuration with data grouping enabled (YAML) The sample below shows how to configure the data grouping and how it affects the generated SQL query.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  default_grouping_name: group_by_country_and_state
  groupings:
    group_by_country_and_state:
      level_1:
        source: column_value
        column: country
      level_2:
        source: column_value
        column: state
  columns:
    target_column:
      monitoring_checks:
        monthly:
          numeric:
            monthly_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    country:
      labels:
      - column used as the first grouping key
    state:
      labels:
      - column used as the second grouping key

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    analyzed_table.grouping_level_1,
    analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM  AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            original_table."country",
            original_table."state"
                    ) AS actual_value
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2

FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            analyzed_table.[country],
            analyzed_table.[state]
        ) AS actual_value
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2
ORDER BY grouping_level_1, grouping_level_2

daily partition percentile 25 in range

Check description

Verifies that the percentile 25 of all values in a column is not outside the expected range. Stores a separate data quality check result for each daily partition.

Data quality check name Friendly name Category Check type Time scale Quality dimension Sensor definition Quality rule Standard
daily_partition_percentile_25_in_range The selected 25th percentile of numeric values is in the range numeric partitioned daily Reasonableness percentile between_floats

Command-line examples

Please expand the section below to see the DQOps command-line examples to run or activate the daily partition percentile 25 in range data quality check.

Managing daily partition percentile 25 in range check from DQOps shell

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the warning rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=daily_partition_percentile_25_in_range --enable-warning

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_partition_percentile_25_in_range --enable-warning

Additional rule parameters are passed using the -Wrule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_partition_percentile_25_in_range --enable-warning
                    -Wfrom=value

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the error rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=daily_partition_percentile_25_in_range --enable-error

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_partition_percentile_25_in_range --enable-error

Additional rule parameters are passed using the -Erule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=daily_partition_percentile_25_in_range --enable-error
                    -Efrom=value

Run this data quality check using the check run CLI command by providing the check name and all other targeting filters. The following example shows how to run the daily_partition_percentile_25_in_range check on all tables and columns on a single data source.

dqo> check run -c=data_source_name -ch=daily_partition_percentile_25_in_range

It is also possible to run this check on a specific connection and table. In order to do this, use the connection name and the full table name parameters.

dqo> check run -c=connection_name -t=schema_name.table_name -ch=daily_partition_percentile_25_in_range

You can also run this check on all tables (and columns) on which the daily_partition_percentile_25_in_range check is enabled using patterns to find tables.

dqo> check run -c=connection_name -t=schema_prefix*.fact_* -col=column_name_* -ch=daily_partition_percentile_25_in_range

YAML configuration

The sample schema_name.table_name.dqotable.yaml file with the check configured is shown below.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  timestamp_columns:
    partition_by_column: date_column
  incremental_time_window:
    daily_partitioning_recent_days: 7
    monthly_partitioning_recent_months: 1
  columns:
    target_column:
      partitioned_checks:
        daily:
          numeric:
            daily_partition_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    date_column:
      labels:
      - "date or datetime column used as a daily or monthly partitioning key, dates\
        \ (and times) are truncated to a day or a month by the sensor's query for\
        \ partitioned checks"
Samples of generated SQL queries for each data source type

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile data quality sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE))
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    CAST(original_table."date_column" AS DATE) AS time_period,
    toDateTime64(CAST(original_table."date_column" AS DATE), 3) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE))
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    CAST(original_table."date_column" AS DATE) AS time_period,
    TIMESTAMP(CAST(original_table."date_column" AS DATE)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM  AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            CAST(original_table."date_column" AS DATE),
             CAST(original_table."date_column" AS DATE)
                    ) AS actual_value,
    CAST(original_table."date_column" AS DATE) AS time_period,
    TO_TIMESTAMP(CAST(original_table."date_column" AS DATE)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    TRUNC(CAST(original_table."date_column" AS DATE)) AS time_period,
    CAST(TRUNC(CAST(original_table."date_column" AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            CAST(analyzed_table."date_column" AS date),
             CAST(analyzed_table."date_column" AS date)
        ) AS actual_value,
        CAST(analyzed_table."date_column" AS date) AS time_period,
        CAST(CAST(analyzed_table."date_column" AS date) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    CAST(DATE_TRUNC('day', original_table."date_column") AS DATE) AS time_period,
    CAST((CAST(DATE_TRUNC('day', original_table."date_column") AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    TO_TIMESTAMP(CAST(analyzed_table."date_column" AS date)) AS time_period_utc
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE))
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            CAST(analyzed_table.[date_column] AS date),
            CAST(CAST(analyzed_table.[date_column] AS date) AS DATETIME)
        ) AS actual_value,
        CAST(analyzed_table.[date_column] AS date) AS time_period,
        CAST((CAST(analyzed_table.[date_column] AS date)) AS DATETIME) AS time_period_utc
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
GROUP BY nested_table.[time_period], nested_table.[time_period_utc]
ORDER BY nested_table.[time_period], nested_table.[time_period_utc]
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    CAST(analyzed_table."date_column" AS DATE) AS time_period,
    CAST(CAST(analyzed_table."date_column" AS DATE) AS TIMESTAMP) AS time_period_utc
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            CAST(analyzed_table."date_column" AS date),
             CAST(analyzed_table."date_column" AS date)
        ) AS actual_value,
        CAST(analyzed_table."date_column" AS date) AS time_period,
        CAST(CAST(analyzed_table."date_column" AS date) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc

Expand the Configure with data grouping section to see additional examples for configuring this data quality checks to use data grouping (GROUP BY).

Configuration with data grouping

Sample configuration with data grouping enabled (YAML) The sample below shows how to configure the data grouping and how it affects the generated SQL query.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  timestamp_columns:
    partition_by_column: date_column
  incremental_time_window:
    daily_partitioning_recent_days: 7
    monthly_partitioning_recent_months: 1
  default_grouping_name: group_by_country_and_state
  groupings:
    group_by_country_and_state:
      level_1:
        source: column_value
        column: country
      level_2:
        source: column_value
        column: state
  columns:
    target_column:
      partitioned_checks:
        daily:
          numeric:
            daily_partition_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    date_column:
      labels:
      - "date or datetime column used as a daily or monthly partitioning key, dates\
        \ (and times) are truncated to a day or a month by the sensor's query for\
        \ partitioned checks"
    country:
      labels:
      - column used as the first grouping key
    state:
      labels:
      - column used as the second grouping key

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    analyzed_table.grouping_level_1,
    analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    CAST(original_table."date_column" AS DATE) AS time_period,
    toDateTime64(CAST(original_table."date_column" AS DATE), 3) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    CAST(original_table."date_column" AS DATE) AS time_period,
    TIMESTAMP(CAST(original_table."date_column" AS DATE)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM  AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    time_period,
    time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            CAST(original_table."date_column" AS DATE),
             CAST(original_table."date_column" AS DATE),
            original_table."country",
            original_table."state"
                    ) AS actual_value,
    CAST(original_table."date_column" AS DATE) AS time_period,
    TO_TIMESTAMP(CAST(original_table."date_column" AS DATE)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    TRUNC(CAST(original_table."date_column" AS DATE)) AS time_period,
    CAST(TRUNC(CAST(original_table."date_column" AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            CAST(analyzed_table."date_column" AS date),
             CAST(analyzed_table."date_column" AS date),
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value,
        CAST(analyzed_table."date_column" AS date) AS time_period,
        CAST(CAST(analyzed_table."date_column" AS date) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    CAST(DATE_TRUNC('day', original_table."date_column") AS DATE) AS time_period,
    CAST((CAST(DATE_TRUNC('day', original_table."date_column") AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    CAST((CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    CAST(analyzed_table."date_column" AS date) AS time_period,
    TO_TIMESTAMP(CAST(analyzed_table."date_column" AS date)) AS time_period_utc
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            CAST(analyzed_table.`date_column` AS DATE),
            TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        CAST(analyzed_table.`date_column` AS DATE) AS time_period,
        TIMESTAMP(CAST(analyzed_table.`date_column` AS DATE)) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc,
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            CAST(analyzed_table.[date_column] AS date),
            CAST(CAST(analyzed_table.[date_column] AS date) AS DATETIME),
            analyzed_table.[country],
            analyzed_table.[state]
        ) AS actual_value,
        CAST(analyzed_table.[date_column] AS date) AS time_period,
        CAST((CAST(analyzed_table.[date_column] AS date)) AS DATETIME) AS time_period_utc
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
GROUP BY nested_table.[time_period], nested_table.[time_period_utc],
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
ORDER BY nested_table.[time_period], nested_table.[time_period_utc],
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    CAST(analyzed_table."date_column" AS DATE) AS time_period,
    CAST(CAST(analyzed_table."date_column" AS DATE) AS TIMESTAMP) AS time_period_utc
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            CAST(analyzed_table."date_column" AS date),
             CAST(analyzed_table."date_column" AS date),
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value,
        CAST(analyzed_table."date_column" AS date) AS time_period,
        CAST(CAST(analyzed_table."date_column" AS date) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc

monthly partition percentile 25 in range

Check description

Verifies that the percentile 25 of all values in a column is not outside the expected range. Stores a separate data quality check result for each monthly partition.

Data quality check name Friendly name Category Check type Time scale Quality dimension Sensor definition Quality rule Standard
monthly_partition_percentile_25_in_range The selected 25th percentile of numeric values is in the range numeric partitioned monthly Reasonableness percentile between_floats

Command-line examples

Please expand the section below to see the DQOps command-line examples to run or activate the monthly partition percentile 25 in range data quality check.

Managing monthly partition percentile 25 in range check from DQOps shell

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the warning rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-warning

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-warning

Additional rule parameters are passed using the -Wrule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-warning
                    -Wfrom=value

Activate this data quality using the check activate CLI command, providing the connection name, table name, check name, and all other filters. Activates the error rule with the default parameters.

dqo> check activate -c=connection_name -t=schema_name.table_name -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-error

You can also use patterns to activate the check on all matching tables and columns.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-error

Additional rule parameters are passed using the -Erule_parameter_name=value.

dqo> check activate -c=connection_name -t=schema_prefix*.fact_* -col=column_name -ch=monthly_partition_percentile_25_in_range --enable-error
                    -Efrom=value

Run this data quality check using the check run CLI command by providing the check name and all other targeting filters. The following example shows how to run the monthly_partition_percentile_25_in_range check on all tables and columns on a single data source.

dqo> check run -c=data_source_name -ch=monthly_partition_percentile_25_in_range

It is also possible to run this check on a specific connection and table. In order to do this, use the connection name and the full table name parameters.

dqo> check run -c=connection_name -t=schema_name.table_name -ch=monthly_partition_percentile_25_in_range

You can also run this check on all tables (and columns) on which the monthly_partition_percentile_25_in_range check is enabled using patterns to find tables.

dqo> check run -c=connection_name -t=schema_prefix*.fact_* -col=column_name_* -ch=monthly_partition_percentile_25_in_range

YAML configuration

The sample schema_name.table_name.dqotable.yaml file with the check configured is shown below.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  timestamp_columns:
    partition_by_column: date_column
  incremental_time_window:
    daily_partitioning_recent_days: 7
    monthly_partitioning_recent_months: 1
  columns:
    target_column:
      partitioned_checks:
        monthly:
          numeric:
            monthly_partition_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    date_column:
      labels:
      - "date or datetime column used as a daily or monthly partitioning key, dates\
        \ (and times) are truncated to a day or a month by the sensor's query for\
        \ partitioned checks"
Samples of generated SQL queries for each data source type

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile data quality sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH),
            TIMESTAMP(DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH))
        ) AS actual_value,
        DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH) AS time_period,
        TIMESTAMP(DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH)) AS time_period_utc
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    DATE_TRUNC('month', CAST(original_table."date_column" AS DATE)) AS time_period,
    toDateTime64(DATE_TRUNC('month', CAST(original_table."date_column" AS DATE)), 3) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)),
            TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)))
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)) AS time_period,
        TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    DATE_TRUNC('MONTH', CAST(original_table."date_column" AS DATE)) AS time_period,
    TIMESTAMP(DATE_TRUNC('MONTH', CAST(original_table."date_column" AS DATE))) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM  AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN),
             SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN)
                    ) AS actual_value,
    SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN) AS time_period,
    TO_TIMESTAMP(SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    TRUNC(CAST(original_table."date_column" AS DATE), 'MONTH') AS time_period,
    CAST(TRUNC(CAST(original_table."date_column" AS DATE), 'MONTH') AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
             DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
        CAST(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    CAST(DATE_TRUNC('month', original_table."date_column") AS DATE) AS time_period,
    CAST((CAST(DATE_TRUNC('month', original_table."date_column") AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    TO_TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS time_period_utc
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)),
            TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)))
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)) AS time_period,
        TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1),
            CAST(DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1) AS DATETIME)
        ) AS actual_value,
        DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1) AS time_period,
        CAST((DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1)) AS DATETIME) AS time_period_utc
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
GROUP BY nested_table.[time_period], nested_table.[time_period_utc]
ORDER BY nested_table.[time_period], nested_table.[time_period_utc]
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    TRUNC(CAST(analyzed_table."date_column" AS DATE), 'MM') AS time_period,
    CAST(TRUNC(CAST(analyzed_table."date_column" AS DATE), 'MM') AS TIMESTAMP) AS time_period_utc
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
             DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
        CAST(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY time_period, time_period_utc
ORDER BY time_period, time_period_utc

Expand the Configure with data grouping section to see additional examples for configuring this data quality checks to use data grouping (GROUP BY).

Configuration with data grouping

Sample configuration with data grouping enabled (YAML) The sample below shows how to configure the data grouping and how it affects the generated SQL query.

# yaml-language-server: $schema=https://cloud.dqops.com/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  timestamp_columns:
    partition_by_column: date_column
  incremental_time_window:
    daily_partitioning_recent_days: 7
    monthly_partitioning_recent_months: 1
  default_grouping_name: group_by_country_and_state
  groupings:
    group_by_country_and_state:
      level_1:
        source: column_value
        column: country
      level_2:
        source: column_value
        column: state
  columns:
    target_column:
      partitioned_checks:
        monthly:
          numeric:
            monthly_partition_percentile_25_in_range:
              parameters:
                percentile_value: 0.25
              error:
                from: 10.0
                to: 20.5
      labels:
      - This is the column that is analyzed for data quality issues
    date_column:
      labels:
      - "date or datetime column used as a daily or monthly partitioning key, dates\
        \ (and times) are truncated to a day or a month by the sensor's query for\
        \ partitioned checks"
    country:
      labels:
      - column used as the first grouping key
    state:
      labels:
      - column used as the second grouping key

Please expand the database engine name section to see the SQL query rendered by a Jinja2 template for the percentile sensor.

BigQuery
{% import '/dialects/bigquery.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH),
            TIMESTAMP(DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH)),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH) AS time_period,
        TIMESTAMP(DATE_TRUNC(CAST(analyzed_table.`date_column` AS DATE), MONTH)) AS time_period_utc
    FROM `your-google-project-id`.`<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ClickHouse
{% import '/dialects/clickhouse.sql.jinja2' as lib with context -%}

SELECT
    quantile({{ parameters.percentile_value }})({{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    ORDER BY {{ lib.render_target_column('original_table')}}
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    quantile(0.25)(analyzed_table."target_column") AS actual_value,
    analyzed_table.grouping_level_1,
    analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    DATE_TRUNC('month', CAST(original_table."date_column" AS DATE)) AS time_period,
    toDateTime64(DATE_TRUNC('month', CAST(original_table."date_column" AS DATE)), 3) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
    ORDER BY original_table."target_column"
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Databricks
{% import '/dialects/databricks.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)),
            TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)) AS time_period,
        TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
DB2
{% import '/dialects/db2.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    DATE_TRUNC('MONTH', CAST(original_table."date_column" AS DATE)) AS time_period,
    TIMESTAMP(DATE_TRUNC('MONTH', CAST(original_table."date_column" AS DATE))) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
DuckDB
{% import '/dialects/duckdb.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM  AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
HANA
{% import '/dialects/hana.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(analyzed_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    time_period,
    time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
            WITHIN GROUP (ORDER BY {{ lib.render_target_column('original_table')}})
            OVER (
                {%- if lib.data_groupings is not none or lib.time_series is not none %}
                PARTITION BY
                {%- endif -%}
                        {{ render_local_time_dimension_projection('original_table') -}}
                        {{ render_local_data_grouping_projections('original_table') }}
                    ) AS actual_value
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
    {{- lib.render_where_clause(indentation = '    ', table_alias_prefix='original_table') -}}
) analyzed_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(analyzed_table.actual_value) AS actual_value,
    time_period,
    time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
            WITHIN GROUP (ORDER BY original_table."target_column")
            OVER (
                PARTITION BY
            SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN),
             SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN),
            original_table."country",
            original_table."state"
                    ) AS actual_value,
    SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN) AS time_period,
    TO_TIMESTAMP(SERIES_ROUND(CAST(original_table."date_column" AS DATE), 'INTERVAL 1 MONTH', ROUND_DOWN)) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Oracle
{% import '/dialects/oracle.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2
,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    TRUNC(CAST(original_table."date_column" AS DATE), 'MONTH') AS time_period,
    CAST(TRUNC(CAST(original_table."date_column" AS DATE), 'MONTH') AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_schema>"."<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
PostgreSQL
{% import '/dialects/postgresql.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_postgresql_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Presto
{% import '/dialects/presto.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
             DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
        CAST(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_database"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
QuestDB
{% import '/dialects/questdb.sql.jinja2' as lib with context -%}

SELECT
    APPROX_PERCENTILE({{ lib.render_target_column('analyzed_table')}} * 1.0, {{ parameters.percentile_value }}, 2) AS actual_value
    {{- lib.render_data_grouping_projections_reference('analyzed_table') }}
    {{- lib.render_time_dimension_projection_reference('analyzed_table') }}
FROM(
    SELECT
        original_table.*
        {{- lib.render_data_grouping_projections('original_table') }}
        {{- lib.render_time_dimension_projection('original_table') }}
    FROM {{ lib.render_target_table() }} original_table
) analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    APPROX_PERCENTILE(analyzed_table."target_column" * 1.0, 0.25, 2) AS actual_value,

                analyzed_table.grouping_level_1,

                analyzed_table.grouping_level_2,
    time_period,
    time_period_utc
FROM(
    SELECT
        original_table.*,
    original_table."country" AS grouping_level_1,
    original_table."state" AS grouping_level_2,
    CAST(DATE_TRUNC('month', original_table."date_column") AS DATE) AS time_period,
    CAST((CAST(DATE_TRUNC('month', original_table."date_column") AS DATE)) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
    FROM "<target_table>" original_table
) analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Redshift
{% import '/dialects/redshift.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    CAST((DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS TIMESTAMP WITH TIME ZONE) AS time_period_utc
FROM "your_redshift_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Snowflake
{% import '/dialects/snowflake.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}}) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} AS analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column") AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
    TO_TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date))) AS time_period_utc
FROM "your_snowflake_database"."<target_schema>"."<target_table>" AS analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Spark
{% import '/dialects/spark.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}TIMESTAMP({{ lib.render_time_dimension_expression(table_alias_prefix) }})
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE(
        ({{ lib.render_target_column('analyzed_table')}}),
        {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.`time_period` AS time_period,
    nested_table.`time_period_utc` AS time_period_utc,
    analyzed_table.`country` AS grouping_level_1,
    analyzed_table.`state` AS grouping_level_2
FROM(
    SELECT
        PERCENTILE(
        (analyzed_table.`target_column`),
        0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)),
            TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))),
            analyzed_table.`country`,
            analyzed_table.`state`
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE)) AS time_period,
        TIMESTAMP(DATE_TRUNC('MONTH', CAST(analyzed_table.`date_column` AS DATE))) AS time_period_utc
    FROM `<target_schema>`.`<target_table>` AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
SQL Server
{% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }}CAST({{ lib.render_time_dimension_expression(table_alias_prefix) }} AS DATETIME)
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_time_period_columns() -%}
    {% if lib.time_series is not none -%}
        nested_table.[time_period], nested_table.[time_period_utc]
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        PERCENTILE_CONT({{ parameters.percentile_value }})
        WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{% if lib.time_series is not none or (data_groupings is not none and (data_groupings | length()) > 0) -%}
GROUP BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
ORDER BY {{render_time_period_columns()}} {{- lib.render_data_grouping_projections('analyzed_table', set_leading_comma=(lib.time_series is not none)) }}
{%- endif -%}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table.[time_period] AS time_period,
    nested_table.[time_period_utc] AS time_period_utc,
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
FROM(
    SELECT
        PERCENTILE_CONT(0.25)
        WITHIN GROUP (ORDER BY analyzed_table.[target_column])
        OVER (PARTITION BY
            DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1),
            CAST(DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1) AS DATETIME),
            analyzed_table.[country],
            analyzed_table.[state]
        ) AS actual_value,
        DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1) AS time_period,
        CAST((DATEFROMPARTS(YEAR(CAST(analyzed_table.[date_column] AS date)), MONTH(CAST(analyzed_table.[date_column] AS date)), 1)) AS DATETIME) AS time_period_utc
    FROM [your_sql_server_database].[<target_schema>].[<target_table>] AS analyzed_table) AS nested_table
GROUP BY nested_table.[time_period], nested_table.[time_period_utc],
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
ORDER BY nested_table.[time_period], nested_table.[time_period_utc],
    analyzed_table.[country] AS grouping_level_1,
    analyzed_table.[state] AS grouping_level_2
Teradata
{% import '/dialects/teradata.sql.jinja2' as lib with context -%}

SELECT
    PERCENTILE_CONT({{ parameters.percentile_value }})
    WITHIN GROUP (ORDER BY {{ lib.render_target_column('analyzed_table')}} * 1.0) AS actual_value
    {{- lib.render_data_grouping_projections('analyzed_table') }}
    {{- lib.render_time_dimension_projection('analyzed_table') }}
FROM {{ lib.render_target_table() }} analyzed_table
{{- lib.render_where_clause() -}}
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    PERCENTILE_CONT(0.25)
    WITHIN GROUP (ORDER BY analyzed_table."target_column" * 1.0) AS actual_value,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2,
    TRUNC(CAST(analyzed_table."date_column" AS DATE), 'MM') AS time_period,
    CAST(TRUNC(CAST(analyzed_table."date_column" AS DATE), 'MM') AS TIMESTAMP) AS time_period_utc
FROM "<target_schema>"."<target_table>" analyzed_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc
Trino
{% import '/dialects/trino.sql.jinja2' as lib with context -%}

{%- macro render_local_time_dimension_projection(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.time_series is not none -%}
        {{- lib.eol() -}}
        {{ indentation }}{{ lib.render_time_dimension_expression(table_alias_prefix) }},{{ lib.eol() -}}
        {{ indentation }} {{ lib.render_time_dimension_expression(table_alias_prefix) }}
        {{- "," if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_local_data_grouping_projections(table_alias_prefix = 'analyzed_table', indentation = '            ') -%}
    {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%}
        {%- for attribute in lib.data_groupings -%}
            {%- with data_grouping_level = lib.data_groupings[attribute] -%}
                {%- if data_grouping_level.source == 'tag' -%}
                    {{ lib.eol() }}{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
                {%- elif data_grouping_level.source == 'column_value' -%}
                    {{ lib.eol() }}{{ indentation }}{{ table_alias_prefix }}.{{ lib.quote_identifier(data_grouping_level.column) }}
                {%- endif -%}
                {{ "," if not loop.last }}
            {%- endwith %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}

SELECT
    MAX(nested_table.actual_value) AS actual_value {{-"," if lib.time_series is not none -}}
    {% if lib.time_series is not none %}
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc
    {%- endif -%}
    {{- lib.render_data_grouping_projections('analyzed_table') }}
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST({{ lib.render_target_column('analyzed_table')}} AS DOUBLE),
            {{ parameters.percentile_value }})
        OVER (PARTITION BY
            {%- if lib.data_groupings is none and lib.time_series is none %}
            NULL
            {%- endif -%}
            {{render_local_time_dimension_projection('analyzed_table') -}}
            {{render_local_data_grouping_projections('analyzed_table') }}
        ) AS actual_value
        {{- lib.render_time_dimension_projection('analyzed_table', indentation='        ') }}
    FROM {{ lib.render_target_table() }} AS analyzed_table
    {{- lib.render_where_clause(indentation = '    ') -}}) AS nested_table
{{- lib.render_group_by() -}}
{{- lib.render_order_by() -}}
SELECT
    MAX(nested_table.actual_value) AS actual_value,
    nested_table."time_period" AS time_period,
    nested_table."time_period_utc" AS time_period_utc,
    analyzed_table."country" AS grouping_level_1,
    analyzed_table."state" AS grouping_level_2
FROM(
    SELECT
        APPROX_PERCENTILE(
            CAST(analyzed_table."target_column" AS DOUBLE),
            0.25)
        OVER (PARTITION BY
            DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
             DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)),
            analyzed_table."country",
            analyzed_table."state"
        ) AS actual_value,
        DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS time_period,
        CAST(DATE_TRUNC('MONTH', CAST(analyzed_table."date_column" AS date)) AS TIMESTAMP) AS time_period_utc
    FROM "your_trino_catalog"."<target_schema>"."<target_table>" AS analyzed_table) AS nested_table
GROUP BY grouping_level_1, grouping_level_2, time_period, time_period_utc
ORDER BY grouping_level_1, grouping_level_2, time_period, time_period_utc

What's next