You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Reuven Lax <re...@google.com> on 2019/01/08 20:00:24 UTC

AutoValue objects can now be used in Beam!

Thanks to help from Jeff Klukas, I just merged PR/7334 which adds schema
support to AutoValue objects.

in particular, since Beam knows how to encode any type with a schema, this
means that AutoValue objects can now be used inside of PCollections, which
has been a long-requested feature.

The simplest way to use this is to use the DefaultSchema annotation. For
example:

@DefaultSchema(AutoValueSchema.class)
@AutoValue
abstract class MyAutoValue {
  public abstract String getName();
  public abstract MyOtherAutoValue getOtherValue();
       ...
}

This will automatically register this AutoValue class in the SchemaRegistry.

If you can't add the attribute (possibly because you don't own the source
code containing the AutoValue class), you can manually register it as
follows:

pipeline.getSchemaRegistry().registerSchemaProvider(
    MyAutoValue.class, new AutoValueSchema());

Let me know if you have questions or issues with this feature!

Reuven

Re: AutoValue objects can now be used in Beam!

Posted by Kenneth Knowles <ke...@apache.org>.
Nice! This has been requested many times for years. Great to finally have
it so we can encourage good Java practices.

Kenn

On Tue, Jan 8, 2019 at 1:35 PM Pablo Estrada <pa...@google.com> wrote:

> Very cool. Thanks Jeff & Reuven : )
>
> On Tue, Jan 8, 2019 at 12:00 PM Reuven Lax <re...@google.com> wrote:
>
>> Thanks to help from Jeff Klukas, I just merged PR/7334 which adds schema
>> support to AutoValue objects.
>>
>> in particular, since Beam knows how to encode any type with a schema,
>> this means that AutoValue objects can now be used inside of PCollections,
>> which has been a long-requested feature.
>>
>> The simplest way to use this is to use the DefaultSchema annotation. For
>> example:
>>
>> @DefaultSchema(AutoValueSchema.class)
>> @AutoValue
>> abstract class MyAutoValue {
>>   public abstract String getName();
>>   public abstract MyOtherAutoValue getOtherValue();
>>        ...
>> }
>>
>> This will automatically register this AutoValue class in the
>> SchemaRegistry.
>>
>> If you can't add the attribute (possibly because you don't own the source
>> code containing the AutoValue class), you can manually register it as
>> follows:
>>
>> pipeline.getSchemaRegistry().registerSchemaProvider(
>>     MyAutoValue.class, new AutoValueSchema());
>>
>> Let me know if you have questions or issues with this feature!
>>
>> Reuven
>>
>

Re: AutoValue objects can now be used in Beam!

Posted by Pablo Estrada <pa...@google.com>.
Very cool. Thanks Jeff & Reuven : )

On Tue, Jan 8, 2019 at 12:00 PM Reuven Lax <re...@google.com> wrote:

> Thanks to help from Jeff Klukas, I just merged PR/7334 which adds schema
> support to AutoValue objects.
>
> in particular, since Beam knows how to encode any type with a schema, this
> means that AutoValue objects can now be used inside of PCollections, which
> has been a long-requested feature.
>
> The simplest way to use this is to use the DefaultSchema annotation. For
> example:
>
> @DefaultSchema(AutoValueSchema.class)
> @AutoValue
> abstract class MyAutoValue {
>   public abstract String getName();
>   public abstract MyOtherAutoValue getOtherValue();
>        ...
> }
>
> This will automatically register this AutoValue class in the
> SchemaRegistry.
>
> If you can't add the attribute (possibly because you don't own the source
> code containing the AutoValue class), you can manually register it as
> follows:
>
> pipeline.getSchemaRegistry().registerSchemaProvider(
>     MyAutoValue.class, new AutoValueSchema());
>
> Let me know if you have questions or issues with this feature!
>
> Reuven
>