dongjoon-hyun opened a new pull request, #532: URL: https://github.com/apache/spark-connect-swift/pull/532
### What changes were proposed in this pull request? This PR aims to support 7 vector functions (11 overloads). | Function | Since | Signature | | --- | --- | --- | | `vector_cosine_similarity` | 4.3.0 | `(Column, Column)` | | `vector_inner_product` | 4.3.0 | `(Column, Column)` | | `vector_l2_distance` | 4.3.0 | `(Column, Column)` | | `vector_norm` | 4.3.0 | `(Column)`, `(Column, Float \| Column)` | | `vector_normalize` | 4.3.0 | `(Column)`, `(Column, Float \| Column)` | | `vector_avg` | 4.3.0 | `(Column)` | | `vector_sum` | 4.3.0 | `(Column)` | The five scalar functions live in a new `VectorFunctions.swift`. The two aggregate functions, `vector_avg` and `vector_sum`, are added to the existing `AggregateFunctions.swift`, following the `schema_of_variant_agg` precedent, while their tests stay with the rest of the family in `VectorFunctionsTests.swift`. Despite the name, these functions take no dedicated `VECTOR` type. They operate on `ARRAY<FLOAT>` columns, and all the vectors involved must have the same dimension. The optional `degree` of `vector_norm` and `vector_normalize` is expressed as a Swift overload, mirroring the two Scala overloads. In addition to the `Column` overload, a `Float` overload is provided because the server requires exactly a `FLOAT` for this argument: ``` SELECT vector_norm(ARRAY(3.0f, 4.0f), CAST(1.0 AS DOUBLE)) [DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE] ... The second parameter requires the "FLOAT" type, however "CAST(1.0 AS DOUBLE)" has the type "DOUBLE". ``` Since `lit(Double)` produces a `double` literal in this client, a `Double` overload would compile and then fail at analysis time on the server. The `Float` overload keeps `vector_norm(v, 2.0)` correct by construction, the same reasoning behind the `Int32` srid of `st_setsrid`. ### Why are the changes needed? To support the vector functions of Apache Spark 4.3.0 and improve the API coverage. ### Does this PR introduce _any_ user-facing change? No, this PR only adds new functions. ### How was this patch tested? Pass the CIs with the newly added test suite, `VectorFunctionsTests`. ### 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]
