concept union() in category spark

This is an excerpt from Manning's book Spark in Action, Second Edition.
You now have two dataframes with the same number of columns. Therefore, you can union them in the
combineDataframes()method. There are two ways of combining two dataframes in a SQL-like union: you can use theunion()orunionByName()method.The
union()method does not care about the names of the columns, just their order. This method will always union column 1 from the first dataframe with column 1 from the second dataframe, and then move to column 2, and then 3 --regardless of the names. After a few transformative operations (in which you create new columns, rename them, dump them, or combine them), it can be difficult to remember whether the columns are in the right order. If fields don’t match, you could have inconsistent data in the worst case, or a program stop at best. On the other hand,unionByName()matches columns by names, which is safer.