-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29026][SQL] Improve error message in schemaFor in trait without companion object constructor
#25736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-29026][SQL] Improve error message in schemaFor in trait without companion object constructor
#25736
Conversation
|
ok to test |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
Outdated
Show resolved
Hide resolved
|
Test build #110374 has finished for PR 25736 at commit
|
|
Test build #110376 has finished for PR 25736 at commit
|
|
cc @JoshRosen |
|
whoops sorry missed the patch here #23062 that caused differing behavior from our local fork. Will make an update |
|
This should be good now. |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
Outdated
Show resolved
Hide resolved
|
Seems fine to me |
ScalaReflection isn't foundschemaFor in trait without companion object constructor
| schemaFor[TraitProductWithoutCompanion] | ||
| } | ||
| e.getMessage.contains("Unable to find constructor") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ Scrolling up, an existing test is for ScroogeLikeExample where it checks that trait with companion object constructor works.
HeartSaVioR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one more case that we might want to test: the case where a trait has a companion but that companion has no constructor / apply method. I believe that the current code will still fall through and error out with the confusing message in that case.
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/ScalaReflectionSuite.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/ScalaReflectionSuite.scala
Outdated
Show resolved
Hide resolved
|
Test build #110383 has finished for PR 25736 at commit
|
|
Test build #110384 has finished for PR 25736 at commit
|
|
Test build #110395 has finished for PR 25736 at commit
|
|
Test build #110392 has finished for PR 25736 at commit
|
|
Test build #110396 has finished for PR 25736 at commit
|
|
Test build #110391 has finished for PR 25736 at commit
|
|
retest this please |
|
let me leave it to @JoshRosen |
JoshRosen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Test build #110405 has finished for PR 25736 at commit
|
|
Merged to master. |
…out companion object constructor ### What changes were proposed in this pull request? - For trait without companion object constructor, currently the method to get constructor parameters `constructParams` in `ScalaReflection` will throw exception. ``` scala.ScalaReflectionException: <none> is not a term at scala.reflect.api.Symbols$SymbolApi.asTerm(Symbols.scala:211) at scala.reflect.api.Symbols$SymbolApi.asTerm$(Symbols.scala:211) at scala.reflect.internal.Symbols$SymbolContextApiImpl.asTerm(Symbols.scala:106) at org.apache.spark.sql.catalyst.ScalaReflection.getCompanionConstructor(ScalaReflection.scala:909) at org.apache.spark.sql.catalyst.ScalaReflection.constructParams(ScalaReflection.scala:914) at org.apache.spark.sql.catalyst.ScalaReflection.constructParams$(ScalaReflection.scala:912) at org.apache.spark.sql.catalyst.ScalaReflection$.constructParams(ScalaReflection.scala:47) at org.apache.spark.sql.catalyst.ScalaReflection.getConstructorParameters(ScalaReflection.scala:890) at org.apache.spark.sql.catalyst.ScalaReflection.getConstructorParameters$(ScalaReflection.scala:886) at org.apache.spark.sql.catalyst.ScalaReflection$.getConstructorParameters(ScalaReflection.scala:47) ``` - Instead this PR would throw exception: ``` Unable to find constructor for type [XXX]. This could happen if [XXX] is an interface or a trait without companion object constructor UnsupportedOperationException: ``` In the normal usage of ExpressionEncoder, this can happen if the type is interface extending `scala.Product`. Also, since this is a protected method, this could have been other arbitrary types without constructor. ### Why are the changes needed? - The error message `<none> is not a term` isn't helpful for users to understand the problem. ### Does this PR introduce any user-facing change? - The exception would be thrown instead of runtime exception from the `scala.ScalaReflectionException`. ### How was this patch tested? - Added a unit test to illustrate the `type` where expression encoder will fail and trigger the proposed error message. Closes apache#25736 from mickjermsurawong-stripe/SPARK-29026. Authored-by: Mick Jermsurawong <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
What changes were proposed in this pull request?
constructParamsinScalaReflectionwill throw exception.In the normal usage of ExpressionEncoder, this can happen if the type is interface extending
scala.Product. Also, since this is a protected method, this could have been other arbitrary types without constructor.Why are the changes needed?
<none> is not a termisn't helpful for users to understand the problem.Does this PR introduce any user-facing change?
scala.ScalaReflectionException.How was this patch tested?
typewhere expression encoder will fail and trigger the proposed error message.