Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-25381

Stratified sampling by Column argument

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.4.0
    • 3.0.0
    • SQL
    • None

    Description

      Currently the sampleBy method accepts the first argument of string type only. Need to provide overloaded method which accepts Column type too. So, it will allow sampling by multiple columns , for example:

      import org.apache.spark.sql.Row
      import org.apache.spark.sql.functions.struct
      val df = spark.createDataFrame(Seq(("Bob", 17), ("Alice", 10), ("Nico", 8), ("Bob", 17),
        ("Alice", 10))).toDF("name", "age")
      val fractions = Map(Row("Alice", 10) -> 0.3, Row("Nico", 8) -> 1.0)
      df.stat.sampleBy(struct($"name", $"age"), fractions, 36L).show()
             +-----+---+
             | name|age|
             +-----+---+
             | Nico|  8|
             |Alice| 10|
             +-----+---+
      

      Attachments

        Activity

          People

            maxgekk Max Gekk
            maxgekk Max Gekk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: