title: Spark Java: how to compare schemas when columns are not in the same order?
body: <p>Following <a href="https://stackoverflow.com/questions/52933120/spark-java-schema-comparison-of-identical-datasets-fails">this question</a>, I now run this code:</p>
  
  <pre><code>List&lt;StructField&gt; fields = new ArrayList&lt;&gt;();
  fields.add(DataTypes.createStructField("A",DataTypes.LongType,true));
  fields.add(DataTypes.createStructField("B",DataTypes.DoubleType,true));
  StructType schema1 = DataTypes.createStructType(fields);
  Dataset&lt;Row&gt; df1 = spark.sql("select 1 as A, 2.2 as B");
  Dataset&lt;Row&gt; finalDf1 = spark.createDataFrame(df1.javaRDD(), schema1);
  
  fields = new ArrayList&lt;&gt;();
  fields.add(DataTypes.createStructField("B",DataTypes.DoubleType,true));
  fields.add(DataTypes.createStructField("A",DataTypes.LongType,true));
  StructType schema2 = DataTypes.createStructType(fields);
  Dataset&lt;Row&gt; df2 = spark.sql("select 2.2 as B, 1 as A");
  Dataset&lt;Row&gt; finalDf2 = spark.createDataFrame(df2.javaRDD(), schema2);
  
  finalDf1.printSchema();
  finalDf2.printSchema();
  System.out.println(finalDf1.schema());
  System.out.println(finalDf2.schema());
  System.out.println(finalDf1.schema().equals(finalDf2.schema()));
  </code></pre>
  
  <p>Here's the output:</p>
  
  <pre><code>root
   |-- A: long (nullable = true)
   |-- B: double (nullable = true)
  
  root
   |-- B: double (nullable = true)
   |-- A: long (nullable = true)
  
  StructType(StructField(A,LongType,true), StructField(B,DoubleType,true))
  StructType(StructField(B,DoubleType,true), StructField(A,LongType,true))
  false
  </code></pre>
  
  <p>While the columns are not arranges in the same order, both these datasets have exactly the same columns and columns types. What comparison in required here in order to get <code>true</code>?</p>