zhengruifeng opened a new pull request, #58194:
URL: https://github.com/apache/spark/pull/58194

   ### What changes were proposed in this pull request?
   
   This PR adds an ML-specific `vector_posexplode` generator function for MLlib 
vector columns.
   
   The new expression explodes `org.apache.spark.ml.linalg.VectorUDT` and
   `org.apache.spark.mllib.linalg.VectorUDT` columns into `(index, value)` rows 
using the shared
   four-field VectorUDT SQL representation:
   
   * sparse vectors emit the stored active `indices`/`values` pairs
   * dense vectors emit all `(position, value)` pairs
   
   ### Why are the changes needed?
   
   Spark SQL generator functions such as `posexplode` only accept arrays and 
maps. ML vector columns
   are UDTs, so users currently need to densify vectors with `vector_to_array` 
or manually unwrap the
   UDT struct and zip the internal sparse arrays.
   
   This provides a direct vector-aware generator that preserves sparse active 
elements without
   densifying first.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. It adds a new Scala ML function:
   
   ```scala
   org.apache.spark.ml.functions.vector_posexplode
   ```
   
   For dense vectors, it returns all vector positions and values. For sparse 
vectors, it returns the
   stored active index-value pairs.
   
   ### How was this patch tested?
   
   Added coverage in `FunctionsSuite` for both `spark.ml` and `spark.mllib` 
dense and sparse vectors.
   
   `build/sbt mllib/Test/compile` was started and the new mllib main sources 
compiled, but the task was
   canceled during mllib test compilation so this draft PR could be pushed 
first.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Codex (GPT-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]

Reply via email to