Im creating structure of nested elements . Im having difficulties about how to create a nested struct with tests. Have a look on my code below. I want to add struct:
(if x2.fields3 == 1 then create struct_1, if x2.fields3==2 create struct_2)
df = df.withColumn("General",
struct(
col("x1.field1").alias("gen1"),
col("x1.field2").alias("gen2"),
struct(col("x1.field1").alias("gen3.1"),
col("x2.field1").alias("gen3.2"),
col("x1.field4").alias("gen3.3"),
col("x2.field4").alias("gen3.4"),
col("x1.field5").alias("gen3.5"),
col("x1.field3").alias("gen3.6"),
struct(struct(lit('AA').alias("gen3.7.1.1"),
lit("BB").alias("gen3.7.1.2")).alias("gen3.7.1")
#Add new struct with test
).alias("gen3.7")).alias("gen3")
)).drop('x1','x2')