Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/9565#discussion_r44850557
--- 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 --
This seems a bug to me if the field type is `StructType` but value type is
`Product`. We use `schemaFor` to get the catalyst type, which is the field type
for `InternalRow`. However, for the external `Row`, we will/should use
`dataTypeFor`, which will return `ObjectType` for `Product`. And for
`ObjectType`, we should use `Row.getAs[T]` to get the field.
---
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]