dongjoon-hyun opened a new pull request, #530:
URL: https://github.com/apache/spark-connect-swift/pull/530
### What changes were proposed in this pull request?
This PR aims to support the AES and HMAC functions.
| Function | Since |
| -------- | ----- |
| `aes_encrypt(input, key, mode, padding, iv, aad)` | 3.5.0 |
| `aes_decrypt(input, key, mode, padding, aad)` | 3.5.0 |
| `try_aes_decrypt(input, key, mode, padding, aad)` | 3.5.0 |
| `hmac(key, message, algorithm)` | 4.3.0 |
The new functions live in a new `CryptoFunctions.swift` file. The existing
`HashFunctions.swift` holds one-way digests, while these functions take a
secret
key and perform symmetric encryption or message authentication.
Optional arguments follow the upstream PySpark implementations exactly:
- The AES functions fill omitted arguments with their default literals, so
`aes_encrypt` always sends 6 arguments and `aes_decrypt` /
`try_aes_decrypt`
always send 5. Note that `aes_encrypt` has an `iv` argument while the two
decrypt functions do not.
- `hmac` omits the optional `algorithm` argument instead of filling it, so it
sends 2 or 3 arguments. Since a Swift default argument value cannot change
the
argument count, this is expressed as two overloads, matching the two Scala
`hmac` overloads.
Since these functions are evaluated by the server and a key passed as a
literal
becomes part of the query plan, the doc comments note that a literal key can
be
exposed through server logs and plan output.
### Why are the changes needed?
To improve the API coverage. These functions are available in PySpark and the
Spark SQL Scala API, but were missing from this Swift client.
### Does this PR introduce _any_ user-facing change?
No, this is a new feature.
```swift
let key = lit("0000000000000000")
let df = try await spark.sql("SELECT 'Spark' AS a")
try await df.select(
aes_decrypt(aes_encrypt(col("a"), key), key).cast("STRING")
).show()
```
```
+-------------------------------------------------------------+
|CAST(aes_decrypt(aes_encrypt(a, 0000000000000000, GCM, ...)...|
+-------------------------------------------------------------+
|Spark |
+-------------------------------------------------------------+
```
### How was this patch tested?
Pass the CIs with a new test suite, `CryptoFunctionsTests`.
### 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]