xuanyuanking commented on a change in pull request #28830:
URL: https://github.com/apache/spark/pull/28830#discussion_r439910372



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2548,6 +2548,21 @@ class DataFrameSuite extends QueryTest
       assert(df.schema === new StructType().add(StructField("d", 
DecimalType(38, 0))))
     }
   }
+
+  test("SPARK-31990: preserves the input order of colNames in dropDuplicates") 
{
+    val df = Seq((1, 2, 3, 4, 5), (1, 2, 3, 4, 5)).toDF("c", "e", "d", "a", 
"b")
+    val inputColNames = Seq("c", "b", "c", "d", "b", "c", "b")

Review comment:
       Thanks for adding a new UT here. Since this issue was found when 
investigating the test failure in 
https://github.com/apache/spark/pull/28707#issuecomment-639861273,
   how about reusing the UT `default config of includeHeader doesn't break 
existing query from Spark 2.4` in `KafkaMicroBatchV2SourceSuite`? I think we 
don't need to add a new UT for this regression after #28707. That is to say 
after #28707 is merged, if we don't do the fix, the mentioned UT will fail.

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
##########
@@ -2541,7 +2542,20 @@ class Dataset[T] private[sql](
   def dropDuplicates(colNames: Seq[String]): Dataset[T] = withTypedPlan {
     val resolver = sparkSession.sessionState.analyzer.resolver
     val allColumns = queryExecution.analyzed.output
-    val groupCols = colNames.distinct.flatMap { (colName: String) =>
+    // SPARK-31990: We must preserve the input order of `colNames` because of 
the compatibility
+    // issue (the Streaming's state store depends on the `groupCols` order).
+    val orderPreservingDistinctColNames = {
+      val nameSeen = mutable.Set[String]()

Review comment:
       How about simply revert this line to 
https://github.com/apache/spark/pull/28062/files#diff-7a46f10c3cedbf013cf255564d9483cdL2458,
 use the original implementation of `toSet`.
   Yes, the `toSet.toSeq` might incompatible during to Scala version, but I 
think the current fix should just keep the original order. How to detect the 
order changing and have solid validation should be the work of SPARK-31894 and 
SPARK-27237. WDYT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to