crunch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriel Reid (JIRA)" <>
Subject [jira] [Commented] (CRUNCH-548) getDetachedValue calls to AvroReflectDeepCopier throw InstantiationException on non-concrete types
Date Thu, 23 Jul 2015 12:34:05 GMT


Gabriel Reid commented on CRUNCH-548:

Patch makes sense looks good to me, although the valueClass constructor parameter to AvroDeepCopier
can also be removed now.

I looked around a bit and tried to think of any other spots where a similar change would be
useful, but I can't think of any. I think that Avro reflection is currently the only place
where we've got a potential for a user-specified implementation of a value class.

> getDetachedValue calls to AvroReflectDeepCopier throw InstantiationException on non-concrete
> --------------------------------------------------------------------------------------------------
>                 Key: CRUNCH-548
>                 URL:
>             Project: Crunch
>          Issue Type: Bug
>            Reporter: Adric Eckstein
>         Attachments: CRUNCH-548.patch
> A common use case with avro reflection is to operate on an abstract class or interface
which is serialized using a schema based on a concrete subclass (or union of subclasses).
> @org.apache.avro.reflect.Union({ Foo1.class })
> public interface Foo {
> 	public String getFoo();
> }
> public class Foo1 implements Foo {
> 	private final Double value = 1.0;
> 	@Override
> 	public String getFoo() {
> 		return value.toString();
> 	}
> }
> When trying to operate on this type within crunch, calls to getDetachedValue() will throw
an InstantiationException:
> AvroType<Foo> ptype = Avros.reflects(Foo.class, ReflectData.get().getSchema(Foo.class));
> ptype.initialize(new Configuration());
> Foo copy1 = ptype.getDetachedValue(new Foo1());
> Exception in thread "main" org.apache.crunch.CrunchRuntimeException: java.lang.InstantiationException:$Foo
> 	at org.apache.crunch.types.avro.AvroDeepCopier$AvroReflectDeepCopier.createNewInstance(
> One solution would be to augment the createNewInstance() method in AvroReflectDeepCopier
to create a new instance based on the source object class, rather than the type class.  This
would generally be desirable for any union cases where the source is a subclass of the type

This message was sent by Atlassian JIRA

View raw message