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

    https://github.com/apache/spark/pull/10937#discussion_r50942377
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/DataFrameStatFunctions.scala ---
    @@ -309,4 +312,77 @@ final class DataFrameStatFunctions private[sql](df: 
DataFrame) {
       def sampleBy[T](col: String, fractions: ju.Map[T, jl.Double], seed: 
Long): DataFrame = {
         sampleBy(col, fractions.asScala.toMap.asInstanceOf[Map[T, Double]], 
seed)
       }
    +
    +  /**
    +   * Builds a Bloom filter over a specified column.
    +   *
    +   * @param colName name of the column over which the filter is built
    +   * @param expectedNumItems expected number of items which will be put 
into the filter.
    +   * @param fpp expected false positive probability of the filter.
    +   *
    +   * @since 2.0.0
    +   */
    +  def bloomFilter(colName: String, expectedNumItems: Long, fpp: Double): 
BloomFilter = {
    +    buildBloomFilter(Column(colName), BloomFilter.create(expectedNumItems, 
fpp))
    +  }
    +
    +  /**
    +   * Builds a Bloom filter over a specified column.
    +   *
    +   * @param col the column over which the filter is built
    +   * @param expectedNumItems expected number of items which will be put 
into the filter.
    +   * @param fpp expected false positive probability of the filter.
    +   *
    +   * @since 2.0.0
    +   */
    +  def bloomFilter(col: Column, expectedNumItems: Long, fpp: Double): 
BloomFilter = {
    +    buildBloomFilter(col, BloomFilter.create(expectedNumItems, fpp))
    +  }
    +
    +  /**
    +   * Builds a Bloom filter over a specified column.
    +   *
    +   * @param colName name of the column over which the filter is built
    +   * @param expectedNumItems expected number of items which will be put 
into the filter.
    +   * @param numBits expected number of bits of the filter.
    +   *
    +   * @since 2.0.0
    +   */
    +  def bloomFilter(colName: String, expectedNumItems: Long, numBits: Long): 
BloomFilter = {
    +    buildBloomFilter(Column(colName), BloomFilter.create(expectedNumItems, 
numBits))
    +  }
    +
    +  /**
    +   * Builds a Bloom filter over a specified column.
    +   *
    +   * @param col the column over which the filter is built
    +   * @param expectedNumItems expected number of items which will be put 
into the filter.
    +   * @param numBits expected number of bits of the filter.
    +   *
    +   * @since 2.0.0
    +   */
    +  def bloomFilter(col: Column, expectedNumItems: Long, numBits: Long): 
BloomFilter = {
    +    buildBloomFilter(col, BloomFilter.create(expectedNumItems, numBits))
    +  }
    +
    +  private def buildBloomFilter(col: Column, zero: BloomFilter): 
BloomFilter = {
    +    val singleCol = df.select(col)
    +    val colType = singleCol.schema.head.dataType
    +
    +    require(colType == StringType || colType.isInstanceOf[IntegralType],
    +      s"Bloom filter only supports string type and integral types, but got 
$colType.")
    +
    +    val seqOp: (BloomFilter, InternalRow) => BloomFilter = if (colType == 
StringType) {
    +      (filter, row) =>
    +        filter.putBinary(row.getUTF8String(0).getBytes)
    +        filter
    --- End diff --
    
    Also add comment to explain the branching at 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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to