vtlim commented on code in PR #17658: URL: https://github.com/apache/druid/pull/17658#discussion_r1932866736
########## docs/querying/sql-functions.md: ########## @@ -1282,21 +1282,74 @@ Returns the following: ## BLOOM_FILTER -Computes a Bloom filter from values produced by the specified expression. +Computes a [bloom filter](../development/extensions-core/bloom-filter.md) from values provided in an expression. -* **Syntax**: `BLOOM_FILTER(expr, <NUMERIC>)` +`numEntries` specifies the maximum number of distinct values before the false positive rate increases. + +* **Syntax:** `BLOOM_FILTER(expr, numEntries)` * **Function type:** Aggregation +<details><summary>Example</summary> + +The following example returns a Base64-encoded bloom filter string for entries in `agent_category`: + +```sql +SELECT + agent_category, + BLOOM_FILTER(agent_category, 10) as bloom +FROM "kttm" + GROUP BY agent_category +``` + +Returns the following: + +| `agent_keys` | `bloom` | +| -- | -- | +| `empty` | `"BAAAAAgAAAAAABAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEABAAAAAA"` | +| `Game console` | `"BAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAQAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgBAAAAAAAAAAAAAAAA"` | +| `Personal computer` | `"BAAAAAgAAAAAAEAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA"` | +| `Smart TV` | `"BAAAAAgAAAAAAAAAAAAAgAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAA"` | +| `Smartphone` | `"BAAAAAgAAACAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAA"` | +| `Tablet` | `"BAAAAAgAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAIA"` | + +</details> + [Learn more](sql-aggregations.md) ## BLOOM_FILTER_TEST -Returns true if the expression is contained in a Base64-serialized Bloom filter. +Returns true if an expression is contained in a Base64-encoded [bloom filter](../development/extensions-core/bloom-filter.md) string. -* **Syntax**: `BLOOM_FILTER_TEST(expr, <STRING>)` +* **Syntax:** `BLOOM_FILTER_TEST(expr, <STRING>)` * **Function type:** Scalar, other -[Learn more](sql-scalar.md#other-scalar-functions) +<details><summary>Example</summary> + +The following example returns `true` for the bloom filter string associated with `agent_filter` entry `Game console`: + +```sql +SELECT + agent_category, + BLOOM_FILTER_TEST(agent_category, 'BAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAQAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgBAAAAAAAAAAAAAAAA') as bloom +FROM "kttm" +GROUP BY agent_category +``` + +Returns the following: + +| `agent_keys` | `bloom` | +| -- | -- | +| `empty` | `false` | +| `Game console` | `true` | +| `Personal computer` | `false` | +| `Smart TV` | `false` | +| `Smartphone` | `false` | +| `Tablet` | `false` | + +</details> + +[Learn more](sql-aggregations.md) Review Comment: Need to fix this link to scalar as well -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
