[GitHub] [spark] wangyum commented on a diff in pull request #37697: [SPARK-40248][SQL] Use larger number of bits to build Bloom filter

2022-09-01 Thread GitBox


wangyum commented on code in PR #37697:
URL: https://github.com/apache/spark/pull/37697#discussion_r960736515


##
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/BloomFilterAggregate.scala:
##
@@ -55,6 +55,13 @@ case class BloomFilterAggregate(
   Multiply(estimatedNumItemsExpression, Literal(8L)))
   }
 
+  def this(child: Expression, estimatedNumItems: Long) = {
+this(child, Literal(estimatedNumItems),
+  Literal(math.min(
+BloomFilter.optimalNumOfBits(estimatedNumItems, estimatedNumItems / 
30L.toDouble),
+SQLConf.get.getConf(SQLConf.RUNTIME_BLOOM_FILTER_MAX_NUM_BITS
+  }

Review Comment:
   How about?
   ```scala
   this(child, Literal(estimatedNumItems),
 Literal(math.min(
   BloomFilter.optimalNumOfBits(estimatedNumItems,
 estimatedNumItems / 
(SQLConf.get.getConf(SQLConf.RUNTIME_BLOOM_FILTER_MAX_NUM_ITEMS) /
   BloomFilter.DEFAULT_FPP)),
   SQLConf.get.getConf(SQLConf.RUNTIME_BLOOM_FILTER_MAX_NUM_BITS
   ```
   The smaller `estimatedNumItems`, the smaller the `FPP`.
   
   
   estimatedNumItems | FPP | numBits
   -- | -- | --
   RUNTIME_BLOOM_FILTER_MAX_NUM_ITEMS | DEFAULT_FPP | 29193763
   200 | 0.015 | 17482271
   100 | 0.0075 | 10183830
   10 | 7.50E-04 | 1497636
   1 | 7.50E-05 | 197688
   1000 | 7.50E-06 | 24561
   100 | 7.50E-07 | 2935
   10 | 7.50E-08 | 341
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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



[GitHub] [spark] wangyum commented on a diff in pull request #37697: [SPARK-40248][SQL] Use larger number of bits to build Bloom filter

2022-08-30 Thread GitBox


wangyum commented on code in PR #37697:
URL: https://github.com/apache/spark/pull/37697#discussion_r959142316


##
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/BloomFilterAggregate.scala:
##
@@ -55,6 +55,13 @@ case class BloomFilterAggregate(
   Multiply(estimatedNumItemsExpression, Literal(8L)))
   }
 
+  def this(child: Expression, estimatedNumItems: Long) = {
+this(child, Literal(estimatedNumItems),
+  Literal(math.min(
+BloomFilter.optimalNumOfBits(estimatedNumItems, estimatedNumItems / 
30L.toDouble),

Review Comment:
   It can benefit all queries if `estimatedNumItems` < 9000. Especially the 
number of creationSide rows is small. For example:
   ```scala
   spark.range(1000).selectExpr("id as a", "id as b", "id as 
c").write.saveAsTable("t1")
   spark.range(10).selectExpr("id as x", "id as y", "id as 
z").write.saveAsTable("t2")
   
   spark.sql("set spark.sql.cbo.enabled=true")
   spark.sql("ANALYZE TABLE t1 COMPUTE STATISTICS FOR COLUMNS a, b, c")
   
   spark.sql("select * from t1 left join (select distinct * from t2) t on t1.a 
= t.y where t1.b > 0").collect()
   ```
   Before this PR | After this PR
   -- | --
   
![image](https://user-images.githubusercontent.com/5399861/187590018-214711c0-80f2-4c4c-9e80-4443a703bb25.png)
 | 
![image](https://user-images.githubusercontent.com/5399861/187589973-941aa3a2-2888-4bd8-9942-2709ed9bf056.png)
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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



[GitHub] [spark] wangyum commented on a diff in pull request #37697: [SPARK-40248][SQL] Use larger number of bits to build Bloom filter

2022-08-30 Thread GitBox


wangyum commented on code in PR #37697:
URL: https://github.com/apache/spark/pull/37697#discussion_r958264454


##
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/BloomFilterAggregate.scala:
##
@@ -55,6 +55,13 @@ case class BloomFilterAggregate(
   Multiply(estimatedNumItemsExpression, Literal(8L)))
   }
 
+  def this(child: Expression, estimatedNumItems: Long) = {
+this(child, Literal(estimatedNumItems),
+  Literal(math.min(
+BloomFilter.optimalNumOfBits(estimatedNumItems, estimatedNumItems / 
30L.toDouble),

Review Comment:
   This is used to reduce the false positive probability if `estimatedNumItems` 
is small.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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