Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/9565#discussion_r44509246
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala ---
@@ -306,7 +306,15 @@ trait Row extends Serializable {
*
* @throws ClassCastException when data type does not match.
*/
- def getStruct(i: Int): Row = getAs[Row](i)
+ def getStruct(i: Int): Row = {
+ // Product and Row both are recoginized as StructType in a Row
+ val t = get(i)
+ if (t.isInstanceOf[Product]) {
+ Row.fromTuple(t.asInstanceOf[Product])
+ } else {
+ t.asInstanceOf[Row]
+ }
+ }
--- End diff --
We use `schemaFor` to get a catalyst DataType for udf's return type. For
`Product` type, we return a `StructType` now. That causes problem in
`RowEncoder` because `RowEncoder` will try to get a `Row` not a `Product` for a
field of `StructType`. You will get a casting exception if your udf returns
something like `(1, 2)`.
The problem is a field of `StructType` in a `Row` can be a `Product` or a
`Row`. I modified the `getStruct` method in `Row` to turn a `Row` for a
`Product`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]