Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/9937#discussion_r45959263
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
---
@@ -539,29 +571,25 @@ object ScalaReflection extends ScalaReflection {
Invoke(inputObject, "booleanValue", BooleanType)
case other =>
- throw new UnsupportedOperationException(
- s"No Encoder found for $tpe\n" + walkedTypePath.mkString("\n"))
+ val fields = getJavaBeanFields(other)
+ if (fields.length > 0) {
+ CreateNamedStruct(fields.flatMap { f =>
+ val fieldName = f.getName
+ val fieldType = classToType(f.getType)
+ val fieldValue = Invoke(inputObject, getterAndSetter(f)._1,
dataTypeFor(fieldType))
+ val clsName = getClassNameFromType(fieldType)
+ val newPath = s"""- java bean field (class: "$clsName",
name: "$fieldName")""" +:
+ walkedTypePath
+
+ expressions.Literal(fieldName) :: extractorFor(fieldValue,
fieldType, newPath) :: Nil
+ })
+ } else {
+ throw new UnsupportedOperationException(
+ s"No Encoder found for $tpe\n" +
walkedTypePath.mkString("\n"))
+ }
}
}
}
-}
-
-/**
- * Support for generating catalyst schemas for scala objects. Note that
unlike its companion
- * object, this trait able to work in both the runtime and the compile
time (macro) universe.
- */
-trait ScalaReflection {
--- End diff --
I moved the `schemaFor` stuff to `object ScalaReflection`, because of the
need of `mirror.runtimeClass` in `getJavaBeanFields`
---
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]