<@U088WCP3B4P> is this right to test for null_coun...
# ask-elementary-ai
s
@kapa.ai is this right to test for null_count and null_percent for the column "Amount Extended Price Base Currency" and say what this test do, does it fail or pass, how can we set threshold and i saw in the documentation it seems like we have to define as per this data_tests: — elementary.column_anomalies: arguments: column_anomalies: column monitors list dimensions: sql expression timestamp_column: column name where_expression: sql expression anomaly_sensitivity: int anomaly_direction: [both | spike | drop] detection_period: period: [hour | day | week | month] count: int training_period: period: [hour | day | week | month] count: int time_bucket: period: [hour | day | week | month] count: int seasonality: day_of_week detection_delay: period: [hour | day | week | month] count: int ignore_small_changes: spike_failure_percent_threshold: int drop_failure_percent_threshold: int anomaly_exclude_metrics: [SQL expression] if so how can i give like this - name: sales_backlog__parquet_common_refined4 data_tests: - elementary.volume_anomalies: anomaly_direction: both ignore_small_changes: spike_failure_percent_threshold: 6 drop_failure_percent_threshold: 6 tags: ["elementary", "daily_elementary", "refined4", "common_refined4"] columns: - name: "salesbacklogskey" quote: true data_tests: - unique: config: severity: error error_if: ">1" warn_if: ">1" - not_null - name: "%companynumber" quote: true data_tests: - not_null - name: "%businessunitskey" quote: true data_tests: - not_null - name: "%part number" quote: true data_tests: - not_null - name: "%customernumber" quote: true data_tests: - not_null - name: "%datekey" quote: true data_tests: - not_null - name: "%itembranchskey" quote: true data_tests: - not_null - name: "Amount Extended Price Base Currency" quote: true tests: - elementary.column_anomalies: column_anomalies: [null_count, null_percent]
k
A message from kapa.ai
Yes, it is correct to test for
null_count
and
null_percent
on the column "Amount Extended Price Base Currency" using the
elementary.column_anomalies
test. Both
null_count
and
null_percent
are supported monitors for any column type, including numeric columns like this one. Here’s how you can define the test in your dbt model YAML:
Copy code
yaml - name: sales_backlog__parquet_common_refined4   columns:     - name: "Amount Extended Price Base Currency"       quote: true       tests:         - elementary.column_anomalies:             column_anomalies: [null_count, null_percent]
This configuration will monitor the number and percentage of nulls in the specified column over time and alert if there is a significant anomaly compared to historical data. The test will pass if no anomaly is detected and fail if an anomaly is found in the detection period, based on the statistical model Elementary uses to compare recent values to historical trends [column_anomalies docs](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/column-anomalies). ### How thresholds work Elementary’s anomaly detection does not use static user-defined thresholds for nulls. Instead, it uses statistical anomaly detection, comparing recent values to historical patterns. However, you can control the sensitivity of the anomaly detection using the
anomaly_sensitivity
parameter. A lower value makes the test more sensitive (alerts on smaller changes), while a higher value makes it less sensitive (alerts only on larger deviations). For example:
Copy code
yaml - name: "Amount Extended Price Base Currency"   quote: true   tests:     - elementary.column_anomalies:         column_anomalies: [null_count, null_percent]         anomaly_sensitivity: 2
You can also configure other parameters such as
timestamp_column
,
detection_period
,
training_period
, and more, to fine-tune how the anomaly detection works [anomaly params](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/anomaly-params). ### About your YAML structure Your example uses
data_tests
, but Elementary tests should be defined under the
tests
key for each column or model, as shown above. The structure you provided for the
elementary.column_anomalies
test is correct if placed under the
tests
key for the column. Summary: - Yes, you can and should use
null_count
and
null_percent
for this column. - The test will fail if an anomaly is detected in the null count or percent, based on historical data. - You can adjust detection sensitivity with
anomaly_sensitivity
. - Use the
tests
key, not
data_tests
, for Elementary test definitions in your YAML. For more details and configuration options, see the official documentation: [column_anomalies configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/column-anomalies), [test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/column-anomalies#test-configuration).
s
@kapa.ai can you provide me the right structure witth sensitivity:4 cuz it is expected to have some nulls give the full code for the particular file
k
A message from kapa.ai
Certainly! Based on the knowledge sources, here is the correct YAML structure for testing
null_count
and
null_percent
on the column "Amount Extended Price Base Currency" with
anomaly_sensitivity: 4
. This configuration is suitable when you expect some nulls and want to reduce false positives by making the test less sensitive to small changes.
Copy code
yaml version: 2  models:   - name: sales_backlog__parquet_common_refined4     columns:       - name: "Amount Extended Price Base Currency"         quote: true         tests:           - elementary.column_anomalies:               column_anomalies: [null_count, null_percent]               anomaly_sensitivity: 4
Explanation: - The test will monitor both the count and percent of nulls in the specified column. -
anomaly_sensitivity: 4
makes the test less sensitive, so only significant deviations from historical null patterns will trigger a failure. - This structure follows the documented approach for configuring column anomaly tests in dbt YAML files [column_anomalies configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/column-anomalies) and [test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/column-anomalies#test-configuration). If you want to add a
timestamp_column
for time-based anomaly detection, you can add it at the model level as shown in the documentation, but it is not required for the test to work. Let me know if you need the structure for additional columns or further customization!