Skip to content

[SPARK-55696][SQL] Add explicit error to Encoders.bean for interface class#54494

Open
szehon-ho wants to merge 4 commits intoapache:masterfrom
szehon-ho:encoder_interface
Open

[SPARK-55696][SQL] Add explicit error to Encoders.bean for interface class#54494
szehon-ho wants to merge 4 commits intoapache:masterfrom
szehon-ho:encoder_interface

Conversation

@szehon-ho
Copy link
Member

@szehon-ho szehon-ho commented Feb 25, 2026

What changes were proposed in this pull request?

Add explicit error message to Encoders.bean against interfaces

Why are the changes needed?

For bean Encoders, the de-serializer uses the constructor inferred from the bean Encoder. ie, we get the bytes back, the Dataset deserialization will use the Encoder's interface class to try to construct , and fail.

Code ref:

val newInstance = NewInstance(cls, Nil, ObjectType(cls), propagateNull = false)

Does this PR introduce any user-facing change?

No, it already fails today with another message:

java.lang.IllegalStateException: found an unhandled type: null
      at org.apache.commons.lang3.reflect.TypeUtils.getTypeArguments(TypeUtils.java:915)
      at org.apache.commons.lang3.reflect.TypeUtils.getTypeArguments(TypeUtils.java:791)
      at org.apache.commons.lang3.reflect.TypeUtils.getTypeArguments(TypeUtils.java:886)
      at org.apache.commons.lang3.reflect.TypeUtils.getTypeArguments(TypeUtils.java:873)
      at org.apache.spark.sql.catalyst.JavaTypeInference$.encoderFor(JavaTypeInference.scala:159)
      at org.apache.spark.sql.catalyst.JavaTypeInference$.encoderFor(JavaTypeInference.scala:63)
      at org.apache.spark.sql.catalyst.JavaTypeInference$.encoderFor(JavaTypeInference.scala:56)
      at org.apache.spark.sql.Encoders$.bean(Encoders.scala:211)
      at org.apache.spark.sql.Encoders.bean(Encoders.scala)

it will now fail more explicitly.

How was this patch tested?

Added unit test in JavaDatasetSuite

Was this patch authored or co-authored using generative AI tooling?

Yes, cursor

messageParameters = Map("name" -> name))
}

def beanEncoderDoesNotSupportInterfaceError(className: String):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's only used once we can inline it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"Primitive types are not supported."
]
},
"_LEGACY_ERROR_TEMP_2231" : {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... why add a LEGACY error condition?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants