Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13116#discussion_r63274238
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala 
---
    @@ -402,6 +402,76 @@ class DatasetSuite extends QueryTest with 
SharedSQLContext {
           3, 17, 27, 58, 62)
       }
     
    +  test("takeSample") {
    +    val n = 1000
    +    val data = sparkContext.parallelize(1 to n, 2).toDS()
    +    for (num <- List(0, 5, 20, 100)) {
    +      val sample = data.takeSample(withReplacement = false, num = num)
    +      assert(sample.count === num) // Got exactly num elements
    +      assert(sample.distinct.count === num) // Elements are distinct
    +      val sampleData = sample.collect()
    +      assert(sampleData.forall(x => 1 <= x && x <= n), s"element not in 
[1, $n]")
    +    }
    +    for (seed <- 1 to 5) {
    +      val sample = data.takeSample(withReplacement = false, 20, seed)
    +      assert(sample.count() === 20) // Got exactly 20 elements
    +      assert(sample.distinct.count === 20) // Elements are distinct
    +      val sampleData = sample.collect()
    +      assert(sampleData.forall(x => 1 <= x && x <= n), s"element not in 
[1, $n]")
    +    }
    +    for (seed <- 1 to 5) {
    +      val sample = data.takeSample(withReplacement = false, 100, seed)
    +      assert(sample.count === 100) // Got only 100 elements
    +      assert(sample.distinct.count === 100) // Elements are distinct
    +      val sampleData = sample.collect()
    +      assert(sampleData.forall(x => 1 <= x && x <= n), s"element not in 
[1, $n]")
    +    }
    +    for (seed <- 1 to 5) {
    +      val sample = data.takeSample(withReplacement = true, 20, seed)
    +      assert(sample.count === 20) // Got exactly 20 elements
    +      val sampleData = sample.collect()
    +      assert(sampleData.forall(x => 1 <= x && x <= n), s"element not in 
[1, $n]")
    +    }
    +    {
    +      val sample = data.takeSample(withReplacement = true, num = 20)
    +      assert(sample.count === 20) // Got exactly 100 elements
    +    val sampleDisCount = sample.distinct.count
    --- End diff --
    
    (It seems indentation is not consistent here.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to