Skip to content

Commit

Permalink
Check for null values in the string column
Browse files Browse the repository at this point in the history
  • Loading branch information
ghanse committed Jan 29, 2025
1 parent f7d7cd5 commit d502011
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/databricks/labs/dqx/col_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def is_valid_date(col_name: str, date_format: str = "yyyy-MM-dd") -> Column:
:return: Column object for condition
"""
column = F.col(col_name)
condition = F.to_date(column, date_format).isNull()
condition = F.when(column.isNull(), F.lit(None)).otherwise(F.to_date(column, date_format).isNull())
return make_condition(
condition,
F.concat_ws("", F.lit("Value '"), column, F.lit(f"' is not a valid date with format '{date_format}'")),
Expand All @@ -397,7 +397,7 @@ def is_valid_timestamp(col_name: str, timestamp_format: str = "yyyy-MM-dd HH:mm:
:return: Column object for condition
"""
column = F.col(col_name)
condition = F.to_timestamp(column, timestamp_format).isNull()
condition = F.when(column.isNull(), F.lit(None)).otherwise(F.to_timestamp(column, timestamp_format).isNull())
return make_condition(
condition,
F.concat_ws(
Expand Down

0 comments on commit d502011

Please sign in to comment.