It seems like StructType preserves order, so two StructType containing same StructFields are not considered equivalent.
For example:
val st1 = StructType(
StructField("ii",StringType,true) ::
StructField("i",StringType,true) :: Nil)
val st2 = StructType(
StructField("i",StringType,true) ::
StructField("ii",StringType,true) :: Nil)
println(st1 == st2)
returns false even though they both have StructField("i",StringType,true) and StructField("ii",StringType,true), just in different order.
I need a test that can say that these two are equivalent because for my purpose, these two are not different.
val schema1 = StructType(StructField("A",ArrayType(st1,true),true) :: Nil)
val schema2 = StructType(StructField("A",ArrayType(st2,true),true) :: Nil)
val final_schema = StructType((schema1 ++ schema2).distinct)
The result of final_schmea should only have one StructType of A instead of two, but distinct considers these two StructType as different, so I end up getting two different StructField named A. So my question is, is there a way to compare two StructTypes based on their contents, not on orders?
EDIT:
After further investigation, since StructType is basically Seq<StructField>, I can do content comparison for that works for Seq, but I am trying to think of a way I can do comparison for embedded StructType most efficiently.