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

Stratified sampling by Column argument

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.0
    • Fix Version/s: 3.0.0
    • Component/s: SQL
    • Labels:
      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

            • Assignee:
              maxgekk Max Gekk
              Reporter:
              maxgekk Max Gekk
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: