Q:

Select all columns of a dataframe as a StructType

In pyspark, I have two dataframes, dfA and dfB, with complex schemas. A common column in the schemas is 'time'. I'd like to make a new dataframe that is the union of these two, so that I can sort on time, however I don't want to lose anything in the original dataframes. I can't figure out how to get everything from one of the original dataframes and group it together in a new structType of the union. 
That is, if I have
# dfA
root
 |--time
 |--fieldA
 |--fieldB

# dfB
root
 |--time
 |--fieldC
 |--fieldD

I'd like to create a union dataframe that has schema
# root
   |--time
   |--dfA
       |--time
       |--fieldA
       |--fieldB
   |--dfB
       |--time
       |--fieldC
       |--fieldD  

After the union, the fields dfA and dfB will null sometimes, depending on which of the original dataframes the row came from.
I imagine I could define the common schema by doing
common_schema = T.StructType([T.StructField('time', T.TimestampType()),
                              T.StructField('dfA', dfA.schema, True),
                              T.StructField('dfB', dfB.schema, True)])

But then I get stuck on the syntax for how to select everything from a dataframe as a column. I'm looking for something like
commonA = dfA.select('time', 
                     F.col('*').alias('dfA'))
commonB = dfB.select('time',
                     F.col('*').alias('dfB'))
common_df = commonA.union(commonB)

But this is an illegal use of '*'

A:

Select all columns of a dataframe as a StructType

from pyspark.sql.functions import struct, lit

commonA = dfA.select("time", struct(*[c for c in df.columns]).alias("dfA"))
commonB = dfB.select("time", struct(*[c for c in df.columns]).alias("dfB"))

but this cannot be unioned as described. You could:
commonA_ = commonA.select("time", "dfA", lit(None).cast(dfB.schema).alias("dfB"))
commonB_ = commonB.select("time", lit(None).cast(dfA.schema).alias("dfA"), "dfB")
commonA_.union(commonB_)

but it sounds you are looking for something more like outer join
dfA.alias("A").join(dfB.alias("B"), ["time"], "fullouter")

