zhengruifeng opened a new pull request, #46456:
URL: https://github.com/apache/spark/pull/46456

   ### What changes were proposed in this pull request?
   Always set the seed of `Dataframe.sample` in Client side
   
   
   ### Why are the changes needed?
   Bug fix
   
   If the seed is not set in Client, it will be set in server side with a 
random int
   
   
https://github.com/apache/spark/blob/c4df12cc884cddefcfcf8324b4d7b9349fb4f6a0/connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala#L386
   
   which cause inconsistent results in multiple executions
   
   In Spark Classic:
   ```
   In [1]: df = spark.range(10000).sample(0.1)
   
   In [2]: [df.count() for i in range(10)]
   Out[2]: [1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006]
   ```
   
   In Spark Connect:
   
   before:
   ```
   In [1]: df = spark.range(10000).sample(0.1)
   
   In [2]: [df.count() for i in range(10)]                                      
                                                                 Out[2]: [969, 
1005, 958, 996, 987, 1026, 991, 1020, 1012, 979]
   ```
   
   after:
   ```
   In [1]: df = spark.range(10000).sample(0.1)
   
   In [2]: [df.count() for i in range(10)]                                      
                                                                      Out[2]: 
[1032, 1032, 1032, 1032, 1032, 1032, 1032, 1032, 1032, 1032]
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   yes, bug fix
   
   
   ### How was this patch tested?
   ci
   
   ### Was this patch authored or co-authored using generative AI tooling?
   no


-- 
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.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to