tkaymak commented on code in PR #38271:
URL: https://github.com/apache/beam/pull/38271#discussion_r3139740375
##########
runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/helpers/EncoderFactory.java:
##########
@@ -31,15 +31,29 @@
import scala.reflect.ClassTag;
public class EncoderFactory {
- // default constructor to reflectively create static invoke expressions
+ // Resolve the Scala case-class primary constructor (the one with the most
parameters).
+ // Constructor ordering returned by Class.getConstructors() is JVM-defined
and not stable
+ // across Spark versions, so we pick the widest constructor explicitly and
then dispatch on
+ // parameter count below to pick the right argument shape per Spark version.
private static final Constructor<StaticInvoke> STATIC_INVOKE_CONSTRUCTOR =
- (Constructor<StaticInvoke>) StaticInvoke.class.getConstructors()[0];
+ primaryConstructor(StaticInvoke.class);
- private static final Constructor<Invoke> INVOKE_CONSTRUCTOR =
- (Constructor<Invoke>) Invoke.class.getConstructors()[0];
+ private static final Constructor<Invoke> INVOKE_CONSTRUCTOR =
primaryConstructor(Invoke.class);
private static final Constructor<NewInstance> NEW_INSTANCE_CONSTRUCTOR =
- (Constructor<NewInstance>) NewInstance.class.getConstructors()[0];
+ primaryConstructor(NewInstance.class);
+
+ @SuppressWarnings("unchecked")
+ private static <T> Constructor<T> primaryConstructor(Class<T> cls) {
+ Constructor<?>[] ctors = cls.getConstructors();
+ Constructor<?> widest = ctors[0];
Review Comment:
Addressed in 0621ce5.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]