Skip to content

Non negative percent

Description

The non_negative_percent check calculates the percentage of non-negative column's values.


When to use

The usability of this check is obvious. It is useful for validation of numerical values that we expect to be non-negative.


Used sensor

Non negative percent


Accepted rules

Min count

Count equals


Parameters

This check takes no parameters.


How to use

The default configuration of column validity check non_negative_percent on columns id with min_count rule, looks like this

# yaml-language-server: $schema=https://cloud.dqo.ai/dqo-yaml-schema/TableYaml-schema.json
apiVersion: dqo/v1
kind: table
spec:
  target:
    schema_name: dqo_ai_test_data
    table_name: table
  time_series:
    mode: current_time
    time_gradient: day
  columns:
    id:
      type_snapshot:
        column_type: INT64
        nullable: true
      checks:
        validity:
          non_negative_percent:
            rules:
              min_count:
                low:
                  min_value: 90.0
                medium:
                  min_value: 80.0
                high:
                  min_value: 70.0
The rendered query is
SELECT
    100.0 * SUM(
        CASE
            WHEN analyzed_table.`id` < 0 THEN 0
            ELSE 1
        END
    ) / COUNT(*) AS actual_value
FROM `dqo-ai-testing`.`dqo_ai_test_data`.`table` AS analyzed_table