Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply sample limit to UDFailedRowsExpressionQuery #1986

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def get_failed_rows_sql(self) -> str:
scan = self.data_source_scan.scan
condition = scan.jinja_resolve(definition=partition_filter, location=self.check_cfg.location)
sql += f"\n AND ({condition})"

return sql

def get_log_diagnostic_dict(self) -> dict:
Expand Down
3 changes: 1 addition & 2 deletions soda/core/soda/execution/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def fetchall(self):
finally:
self.duration = datetime.now() - start

def store(self):
def store(self, allow_samples=True):
"""
DataSource query execution exceptions will be caught and result in the
self.exception being populated.
Expand All @@ -174,7 +174,6 @@ def store(self):
try:
# Check if query does not contain forbidden columns and only create sample if it does not.
# Query still needs to execute in case this is a query that also sets a metric value. (e.g. reference check)
allow_samples = True
offending_columns = []

if self.partition and self.partition.table:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from soda.execution.query.query import Query

from soda.core.soda.execution.query.sample_query import SampleQuery


class UserDefinedFailedRowsExpressionQuery(Query):
def __init__(
Expand All @@ -23,4 +25,12 @@ def __init__(
self.metric = metric

def execute(self):
self.store()
# By default don't store samples through the store method to circumvent sample limit not being applied to
# failed row checks
self.store(allow_samples=False)

samples_sql = self.sql
if self.metric.samples_limit:
samples_sql += f"\nLIMIT {self.metric.samples_limit}"
sample_query = SampleQuery(self.data_source_scan, self.metric, "failed_rows", samples_sql)
sample_query.execute()