Skip to content

Commit

Permalink
Merge pull request #160 from icanbwell/sg-HDE-3445
Browse files Browse the repository at this point in the history
HDE-3445: Adding support for other datatypes in skip_if_column_null
  • Loading branch information
shubhamgoeljtg committed Oct 5, 2023
2 parents 79ebe68 + d40b739 commit 172e48a
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions spark_auto_mapper/automappers/with_column_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

# noinspection PyUnresolvedReferences
from pyspark.sql.functions import col, when, lit, size
from pyspark.sql.types import DataType, StructField, ArrayType
from pyspark.sql.types import (
DataType,
StructField,
ArrayType,
StringType,
TimestampType,
DateType,
MapType,
ByteType,
BinaryType,
)
from pyspark.sql.utils import AnalysisException
from spark_data_frame_comparer.schema_comparer import SchemaComparer

Expand Down Expand Up @@ -71,7 +81,24 @@ def get_column_spec(self, source_df: Optional[DataFrame]) -> Column:
)
column_to_check = f"b.{column}"
# wrap column spec in when
if isinstance(column_type, ArrayType):
if isinstance(
column_type,
(StringType, TimestampType, DateType, ByteType, BinaryType),
):
column_spec = (
when(
col(column_to_check).isNull()
| col(column_to_check).eqNullSafe(""),
lit(None),
)
if is_first_when_case
else column_spec.when(
col(column_to_check).isNull()
| col(column_to_check).eqNullSafe(""),
lit(None),
)
)
elif isinstance(column_type, (ArrayType, MapType)):
column_spec = (
when(
col(column_to_check).isNull()
Expand All @@ -88,14 +115,12 @@ def get_column_spec(self, source_df: Optional[DataFrame]) -> Column:
else:
column_spec = (
when(
col(column_to_check).isNull()
| col(column_to_check).eqNullSafe(""),
col(column_to_check).isNull(),
lit(None),
)
if is_first_when_case
else column_spec.when(
col(column_to_check).isNull()
| col(column_to_check).eqNullSafe(""),
col(column_to_check).isNull(),
lit(None),
)
)
Expand Down

0 comments on commit 172e48a

Please sign in to comment.