Skip to content

Commit c1c9dc6

Browse files
committed
NRL-1411 convert null types to strings
1 parent 22003b3 commit c1c9dc6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

terraform/account-wide-infrastructure/modules/glue/src/transformations.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
to_timestamp,
1010
when,
1111
)
12+
from pyspark.sql.types import NullType
1213

1314

1415
def resolve_dupes(df):
@@ -49,4 +50,15 @@ def dtype_conversion(df):
4950
.withColumn("time", from_unixtime(col("time")).cast("timestamp"))
5051
.withColumn("date", to_date(col("time")))
5152
)
52-
return df.drop("event_timestamp_cleaned")
53+
54+
df = df.drop("event_timestamp_cleaned")
55+
56+
select_exprs = []
57+
for column_name in df.columns:
58+
column_type = df.schema[column_name].dataType
59+
if isinstance(column_type, NullType):
60+
select_exprs.append(col(column_name).cast("string").alias(column_name))
61+
else:
62+
select_exprs.append(col(column_name))
63+
64+
return df.select(*select_exprs)

0 commit comments

Comments
 (0)