I have the following code as shown below. I need to check if the column y.lc.eoouh.ci
is present in the input source and populate the column only if present, else it should be NULL.(The key lc
is also optional)
The code below doesn't seem to work the way it is supposed to as even though y.lc.eoouch.ci
is present in the input, it evaluates to NULL.
The has_column
implementation is from here.
df = df_s_a \
.withColumn("ceci", \
udf(
lambda y : y.lc[-1].eoouh.ci \
if has_column(y, 'lc.eoouh.ci') \
else None, \
StringType()
)(col('eh') \
) \
) \
.select(
col('ceci')
)
df.show()
Sample input:
{
eh: {
lc: [
eoouch: {
ci: "1234ABC"
}
]
}
}