I am trying to do the following:
subschema = T.ArrayType(T.StructType([
T.StructField("AA", T.LongType(), True),
T.StructField("BB", T.StringType(), True),
]), True)
s = T.StructType([
T.StructField("B", subschema, True),
T.StructField("A", T.StringType(), True),
])
d = [Row(
B=None,
A="AAA",
)]
df = spark.createDataFrame(d, schema=s)
But I am getting an error that does not make sense to me:
ValueError: Unexpected tuple 'A' with StructType
If I comment either row A or row B, the error disappears, but I don't understand why this is happening. What is the problem? Is this a bug, or is there something wrong in my code?