-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-42664][CONNECT] Support bloomFilter function for DataFrameStatFunctions
#40352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
af12b55
support
LuciferYang 6f2e736
format
LuciferYang 92da589
remove Alias
LuciferYang 71fba34
support Int/Byte/Short
LuciferYang ab78bae
support string
LuciferYang ebcec0b
support string
LuciferYang 6ee5528
change to check numBits
LuciferYang dfffd53
tmp fix
LuciferYang 8d0e517
refactor
LuciferYang d193de0
move check to server side
LuciferYang 943fcdb
Merge branch 'apache:master' into SPARK-42664
LuciferYang dc62996
try remove lazy
LuciferYang df56a05
make lazy
LuciferYang d225405
Merge branch 'apache:master' into SPARK-42664
LuciferYang f588a6d
Merge branch 'apache:master' into SPARK-42664
LuciferYang e7bb98a
Merge branch 'apache:master' into SPARK-42664
LuciferYang 7a02ad1
Merge branch 'apache:master' into SPARK-42664
LuciferYang f6474c8
add Serializable
LuciferYang 6c756a6
Merge branch 'apache:master' into SPARK-42664
LuciferYang 824fdaa
Merge branch 'apache:master' into SPARK-42664
LuciferYang ad1d205
change since from 3.4.0 to 3.5.0
LuciferYang 9b05105
Merge branch 'apache:master' into SPARK-42664
LuciferYang b22a615
Merge branch 'apache:master' into SPARK-42664
LuciferYang 64bb472
Merge branch 'apache:master' into SPARK-42664
LuciferYang dbada4c
Merge branch 'apache:master' into SPARK-42664
LuciferYang 886809b
Merge branch 'apache:master' into SPARK-42664
LuciferYang 176ce09
merge case
LuciferYang ea2234c
refactor to remove pass dataType
LuciferYang 5bd6169
chanage to always pass 3 parameters
LuciferYang 43d6305
add NaN check in Planner
LuciferYang dbbb61a
bridge optimalNumOfBits
LuciferYang 9520355
Merge branch 'apache:master' into SPARK-42664
LuciferYang 3a24371
Merge branch 'apache:master' into SPARK-42664
LuciferYang c9c9f79
Merge branch 'apache:master' into SPARK-42664
LuciferYang a244420
Merge branch 'apache:master' into SPARK-42664
LuciferYang d004993
Merge branch 'upmaster' into SPARK-42664
LuciferYang 62fdf91
Merge branch 'apache:master' into SPARK-42664
LuciferYang 60217da
Merge branch 'apache:master' into SPARK-42664
LuciferYang 79d7d89
Merge branch 'apache:master' into SPARK-42664
LuciferYang 61bea56
Merge branch 'apache:master' into SPARK-42664
LuciferYang 80d6e6d
Merge branch 'apache:master' into SPARK-42664
LuciferYang caab9bf
Merge branch 'apache:master' into SPARK-42664
LuciferYang e3aeb86
Merge branch 'upmaster' into SPARK-42664
LuciferYang 1fdc5c0
Merge branch 'apache:master' into SPARK-42664
LuciferYang 8861190
Merge branch 'apache:master' into SPARK-42664
LuciferYang efcc1b5
Merge branch 'upmaster' into SPARK-42664
LuciferYang 5134264
Merge branch 'upmaster' into SPARK-42664
LuciferYang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,15 @@ | |
| package org.apache.spark.sql | ||
|
|
||
| import java.{lang => jl, util => ju} | ||
| import java.io.ByteArrayInputStream | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.spark.connect.proto.{Relation, StatSampleBy} | ||
| import org.apache.spark.sql.DataFrameStatFunctions.approxQuantileResultEncoder | ||
| import org.apache.spark.sql.catalyst.encoders.AgnosticEncoders.{ArrayEncoder, BinaryEncoder, PrimitiveDoubleEncoder} | ||
| import org.apache.spark.sql.functions.lit | ||
| import org.apache.spark.util.sketch.CountMinSketch | ||
| import org.apache.spark.util.sketch.{BloomFilter, CountMinSketch} | ||
|
|
||
| /** | ||
| * Statistic functions for `DataFrame`s. | ||
|
|
@@ -584,6 +585,86 @@ final class DataFrameStatFunctions private[sql] (sparkSession: SparkSession, roo | |
| } | ||
| CountMinSketch.readFrom(ds.head()) | ||
| } | ||
|
|
||
| /** | ||
| * 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 3.5.0 | ||
| */ | ||
| def bloomFilter(colName: String, expectedNumItems: Long, fpp: Double): BloomFilter = { | ||
| buildBloomFilter(Column(colName), expectedNumItems, -1L, 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 3.5.0 | ||
| */ | ||
| def bloomFilter(col: Column, expectedNumItems: Long, fpp: Double): BloomFilter = { | ||
| buildBloomFilter(col, expectedNumItems, -1L, 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 3.5.0 | ||
| */ | ||
| def bloomFilter(colName: String, expectedNumItems: Long, numBits: Long): BloomFilter = { | ||
| buildBloomFilter(Column(colName), expectedNumItems, numBits, Double.NaN) | ||
| } | ||
|
|
||
| /** | ||
| * 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 3.5.0 | ||
| */ | ||
| def bloomFilter(col: Column, expectedNumItems: Long, numBits: Long): BloomFilter = { | ||
| buildBloomFilter(col, expectedNumItems, numBits, Double.NaN) | ||
| } | ||
|
|
||
| private def buildBloomFilter( | ||
| col: Column, | ||
| expectedNumItems: Long, | ||
| numBits: Long, | ||
| fpp: Double): BloomFilter = { | ||
|
|
||
| val agg = if (!fpp.isNaN) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before chanage to always pass 3 parameters, always pass all 4 parameters. Now change to pass ( |
||
| Column.fn("bloom_filter_agg", col, lit(expectedNumItems), lit(fpp)) | ||
| } else { | ||
| Column.fn("bloom_filter_agg", col, lit(expectedNumItems), lit(numBits)) | ||
| } | ||
|
|
||
| val ds = sparkSession.newDataset(BinaryEncoder) { builder => | ||
| builder.getProjectBuilder | ||
| .setInput(root) | ||
| .addExpressions(agg.expr) | ||
| } | ||
| BloomFilter.readFrom(new ByteArrayInputStream(ds.head())) | ||
| } | ||
| } | ||
|
|
||
| private object DataFrameStatFunctions { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
connector/connect/server/src/main/scala/org/apache/spark/util/sketch/BloomFilterHelper.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.util.sketch | ||
|
|
||
| /** | ||
| * `BloomFilterHelper` is used to bridge helper methods in BloomFilter` | ||
| */ | ||
| private[spark] object BloomFilterHelper { | ||
| def optimalNumOfBits(expectedNumItems: Long, fpp: Double): Long = | ||
| BloomFilter.optimalNumOfBits(expectedNumItems, fpp) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.