dongjoon-hyun opened a new pull request, #546:
URL: https://github.com/apache/spark-connect-swift/pull/546
### What changes were proposed in this pull request?
This PR aims to support `colRegex` in `DataFrame`.
```swift
public nonisolated func colRegex(_ colName: String) -> Column
```
It returns a `Column` wrapping the `UnresolvedRegex` expression. The
required protobuf definition (`Expression.UnresolvedRegex`) already exists, so
no code generation is involved.
Example:
```swift
let df = try await spark.sql("SELECT 1 a1, 2 a2, 3 b1")
// Select the columns whose names start with `a`, i.e., `a1` and `a2`.
try await df.select(df.colRegex("`a.*`")).show()
```
As with the other Spark clients, only a column name enclosed in backticks is
interpreted as a Java regular expression, and its case sensitivity follows
`spark.sql.caseSensitive`. A column name without backticks is resolved as a
regular column reference.
Note that this client does not assign plan IDs to relations, so the
`plan_id` field is not set. The server ignores `plan_id` for backtick-quoted
regexes, so the regex behavior is identical to PySpark. The only difference is
that a column name without backticks cannot be disambiguated when both sides of
a self-join have it. This limitation is documented in the API doc.
### Why are the changes needed?
To let users select multiple columns by a regex on column names, closing a
gap with the other Spark clients.
`Dataset.colRegex` was added in Apache Spark 2.3.0 via SPARK-12139, PySpark
exposes `DataFrame.colRegex` since 2.3.0 via SPARK-23081, and Spark Connect
supports it since 3.4.0 via SPARK-41438. No version gating is needed for the
supported Apache Spark 4.x servers.
### Does this PR introduce _any_ user-facing change?
Yes, this adds a new public API, `DataFrame.colRegex`.
### How was this patch tested?
Pass the CIs with newly added test cases.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5
--
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]