You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "yaooqinn (via GitHub)" <gi...@apache.org> on 2026/05/26 08:09:21 UTC
[PR] [SPARK-57055][SQL][DOCS] Document non-binary collation gap in DataFrameStatFunctions.bloomFilter [spark]
yaooqinn opened a new pull request, #56114:
URL: https://github.com/apache/spark/pull/56114
### What changes were proposed in this pull request?
Add `@note` Scaladoc to all four `DataFrameStatFunctions.bloomFilter`
overloads and a Migration Guide entry stating that bloom filters built
over string columns use raw UTF-8 byte equality and are collation-blind
for non-binary collations (UTF8_LCASE, ICU). For collation-consistent
membership, the docs recommend using a UTF8_BINARY-collated column, or
normalizing values manually (e.g. `lower(col)` for ASCII data under
UTF8_LCASE).
### Why are the changes needed?
Since Spark 4.0, columns may carry non-binary collations. The bloom
filter path does not collation-normalize values, so users get silent
inconsistent `mightContain` results without any documented warning.
See [SPARK-57055](https://issues.apache.org/jira/browse/SPARK-57055).
### Does this PR introduce _any_ user-facing change?
Documentation only.
### How was this patch tested?
Scaladoc renders cleanly via `build/sbt "sql-api/doc"` (49s, no new
warnings).
Behavior reproduced on master via `spark-shell`:
```scala
// Sample 1: UTF8_BINARY (default) — collation-consistent
val df1 = Seq("Alice", "Bob", "Carol").toDF("name")
val bf1 = df1.stat.bloomFilter("name", 100L, 0.01)
bf1.mightContain("Alice") // true
bf1.mightContain("alice") // false
// Sample 2: UTF8_LCASE raw — silent gap documented by this PR
val df2 = spark.sql(
"SELECT 'Alice' COLLATE UTF8_LCASE AS name UNION ALL " +
"SELECT 'Bob' COLLATE UTF8_LCASE UNION ALL " +
"SELECT 'Carol' COLLATE UTF8_LCASE")
val bf2 = df2.stat.bloomFilter("name", 100L, 0.01)
bf2.mightContain("Alice") // true
bf2.mightContain("alice") // false <-- silent gap
// Sample 3: UTF8_LCASE + lower() ASCII work-around recommended by this PR
import org.apache.spark.sql.functions.lower
val bf3 = df2.stat.bloomFilter(lower(df2("name")), 100L, 0.01)
bf3.mightContain("alice") // true (user must wrap probe side too)
bf3.mightContain("Alice") // false
```
No new unit tests — this is a documentation-only change with no
behavior to assert.
### Scope note
PySpark / R / Connect docstring synchronization is intentionally
deferred to a follow-up PR to keep this change docs-only and minimal.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57055][SQL][DOCS] Document non-binary collation gap in DataFrameStatFunctions.bloomFilter [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on code in PR #56114:
URL: https://github.com/apache/spark/pull/56114#discussion_r3452595611
##########
docs/sql-migration-guide.md:
##########
@@ -80,6 +80,7 @@ license: |
- Since Spark 4.0, The Storage-Partitioned Join feature flag `spark.sql.sources.v2.bucketing.pushPartValues.enabled` is set to `true`. To restore the previous behavior, set `spark.sql.sources.v2.bucketing.pushPartValues.enabled` to `false`.
- Since Spark 4.0, the `sentences` function uses `Locale(language)` instead of `Locale.US` when `language` parameter is not `NULL` and `country` parameter is `NULL`.
- Since Spark 4.0, reading from a file source table will correctly respect query options, e.g. delimiters. Previously, the first query plan was cached and subsequent option changes ignored. To restore the previous behavior, set `spark.sql.legacy.readFileSourceTableCacheIgnoreOptions` to `true`.
+- Since Spark 4.0, string columns may carry a non-binary collation (`UTF8_LCASE`, `UTF8_LCASE_TRIM`, or any ICU collation). `DataFrameStatFunctions.bloomFilter` builds the underlying sketch using raw UTF-8 byte equality and is therefore collation-blind: two values that compare equal under the column's collation will occupy distinct slots and `mightContain` may return inconsistent results. For collation-consistent membership, build the filter over a column declared with the default `UTF8_BINARY` collation, or normalize the values yourself before building and querying. For ASCII data under `UTF8_LCASE`, `lower(col)` is sufficient; for `UTF8_LCASE_TRIM`, use `lower(trim(col))`. Note that `lower()` does not correctly handle certain non-ASCII Unicode cases (for example Turkish dotted/dotless 'I'/'i' or German 'ß'/'SS'); see [SPARK-57055](https://issues.apache.org/jira/browse/SPARK-57055) for a discussion of adding a public canonical-form helper for ICU collations.
Review Comment:
Two related factual errors in the trim-collation guidance here:
1. **Collation name.** `UTF8_LCASE_TRIM` is not a valid collation. The actual name is `UTF8_LCASE_RTRIM` (`CollationFactory` defines an `RTRIM` / right-trim modifier, not a both-sides `TRIM`). Both occurrences in this bullet should be `UTF8_LCASE_RTRIM`.
2. **Workaround.** `lower(trim(col))` is wrong for an RTRIM collation. RTRIM ignores only *trailing* spaces, so the normalization that mirrors the collation is `lower(rtrim(col))`. `trim()` is both-sides (`StringTrim`) while `rtrim()` is trailing-only (`StringTrimRight`), so `lower(trim(col))` also strips *leading* spaces -- collapsing values the collation treats as distinct (e.g. `" a"` vs `"a"`) into the same bloom slot. That makes `mightContain` *more* lenient than the collation, reintroducing the inconsistency this bullet is warning about.
Suggested: `UTF8_LCASE_TRIM` -> `UTF8_LCASE_RTRIM`, and `lower(trim(col))` -> `lower(rtrim(col))`. (The `@note` Scaladoc doesn't mention trim collations, so it's unaffected.)
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57055][SQL][DOCS] Document non-binary collation gap in DataFrameStatFunctions.bloomFilter [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #56114: [SPARK-57055][SQL][DOCS] Document non-binary collation gap in DataFrameStatFunctions.bloomFilter
URL: https://github.com/apache/spark/pull/56114
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57055][SQL][DOCS] Document non-binary collation gap in DataFrameStatFunctions.bloomFilter [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #56114:
URL: https://github.com/apache/spark/pull/56114#issuecomment-5922504096
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org