[ 
https://issues.apache.org/jira/browse/BEAM-13151?focusedWorklogId=754893&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-754893
 ]

ASF GitHub Bot logged work on BEAM-13151:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Apr/22 05:00
            Start Date: 09/Apr/22 05:00
    Worklog Time Spent: 10m 
      Work Description: apilloud opened a new pull request, #17326:
URL: https://github.com/apache/beam/pull/17326

   This supports AutoValue nesting, including Memoized.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us 
incorporate your contribution quickly and easily:
   
    - [ ] [**Choose 
reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and 
mention them in a comment (`R: @username`).
    - [ ] Format the pull request title like `[BEAM-XXX] Fixes bug in 
ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA 
issue, if applicable. This will automatically link the pull request to the 
issue.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual 
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more 
tips on [how to make review process 
smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
   
   To check the build health, please visit 
[https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   
------------------------------------------------------------------------------------------------
   [![Build python source distribution and 
wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python 
tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java 
tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more 
information about GitHub Actions CI.
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 754893)
    Remaining Estimate: 0h
            Time Spent: 10m

> AutoValue with @Memoized fields unsupported with Schema
> -------------------------------------------------------
>
>                 Key: BEAM-13151
>                 URL: https://issues.apache.org/jira/browse/BEAM-13151
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Luke Cwik
>            Assignee: Andrew Pilloud
>            Priority: P1
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Sourced from: 
> https://lists.apache.org/thread.html/rd0c65fca675451f25a6ec02db5df163d1deb6cd6216144d0dbfb0374%40%3Cdev.beam.apache.org%3E
> Looks like Beam has a little bit of an issue when using AutoValues with 
> Memoized (cached) fields. It's not a big issue, and the workaround is simply 
> not using Memoised fields at the cost of a little performance. (See comment 
> in code snippet) 
> The code further below produces this exception:
> {noformat}
> Exception in thread "main" java.lang.NullPointerException
> at 
> org.apache.beam.sdk.schemas.utils.JavaBeanUtils.createGetter(JavaBeanUtils.java:155)
> at 
> org.apache.beam.sdk.schemas.utils.JavaBeanUtils.lambda$getGetters$1(JavaBeanUtils.java:145)
> at 
> java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
> at 
> java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
> at 
> java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
> at 
> java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
> at 
> java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
> at 
> java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
> at 
> java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
> at 
> org.apache.beam.sdk.schemas.utils.JavaBeanUtils.lambda$getGetters$2(JavaBeanUtils.java:146)
> at 
> java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
> at 
> org.apache.beam.sdk.schemas.utils.JavaBeanUtils.getGetters(JavaBeanUtils.java:140)
> at 
> org.apache.beam.sdk.schemas.AutoValueSchema.fieldValueGetters(AutoValueSchema.java:72)
> at org.apache.beam.sdk.schemas.CachingFactory.create(CachingFactory.java:56)
> at org.apache.beam.sdk.values.RowWithGetters.<init>(RowWithGetters.java:66)
> at org.apache.beam.sdk.values.Row$Builder.withFieldValueGetters(Row.java:835)
> at 
> org.apache.beam.sdk.schemas.GetterBasedSchemaProvider$ToRowWithValueGetters.apply(GetterBasedSchemaProvider.java:64)
> at 
> org.apache.beam.sdk.schemas.GetterBasedSchemaProvider$ToRowWithValueGetters.apply(GetterBasedSchemaProvider.java:49)
> at org.apache.beam.sdk.schemas.SchemaCoder.encode(SchemaCoder.java:124)
> at org.apache.beam.sdk.coders.Coder.encode(Coder.java:136)
> at org.apache.beam.sdk.util.CoderUtils.encodeToSafeStream(CoderUtils.java:85)
> at org.apache.beam.sdk.util.CoderUtils.encodeToByteArray(CoderUtils.java:69)
> at org.apache.beam.sdk.util.CoderUtils.encodeToByteArray(CoderUtils.java:54)
> at 
> org.apache.beam.sdk.transforms.Create$Values$CreateSource.fromIterable(Create.java:413)
> at org.apache.beam.sdk.transforms.Create$Values.expand(Create.java:370)
> at org.apache.beam.sdk.transforms.Create$Values.expand(Create.java:277)
> at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:548)
> at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:482)
> at org.apache.beam.sdk.values.PBegin.apply(PBegin.java:44)
> at org.apache.beam.sdk.Pipeline.apply(Pipeline.java:177)
> at org.whatever.testing.App.main(App.java:24)
> {noformat}
> {code:java}
> package org.whatever.testing;
> import com.google.auto.value.AutoValue;
> import com.google.auto.value.extension.memoized.Memoized;
> import org.apache.beam.sdk.Pipeline;
> import org.apache.beam.sdk.options.PipelineOptionsFactory;
> import org.apache.beam.sdk.schemas.AutoValueSchema;
> import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
> import org.apache.beam.sdk.schemas.annotations.SchemaCreate;
> import org.apache.beam.sdk.schemas.transforms.Convert;
> import org.apache.beam.sdk.transforms.Create;
> import org.apache.beam.sdk.transforms.MapElements;
> import org.apache.beam.sdk.values.TypeDescriptor;
> import java.util.Arrays;
> public class App {
>     public static void main(String[] args) {
>         var options = 
> PipelineOptionsFactory.fromArgs(args).withValidation().create();
>         var p = Pipeline.create(options);
>         p
>                 
> .apply(Create.of(Arrays.asList(FooAutoValue.builder().setDummyProp("dummy").build())))
>                 .apply(Convert.to(FooAutoValue.class))
>                 
> .apply(MapElements.into(TypeDescriptor.of(FooAutoValue.class)).via(i -> {
>                     System.out.println(i.toString());
>                     return i;
>                 }))
>         ;
>         p.run().waitUntilFinish();
>     }
>     @AutoValue
>     @DefaultSchema(AutoValueSchema.class)
>     public static abstract class FooAutoValue {
>         public abstract String getDummyProp();
>         @Memoized // <-- commenting this line makes everything work
>         public String getSomething(){
>             return "sldj";
>         }
>         @SchemaCreate
>         public static FooAutoValue create(String dummyProp) {
>             return builder()
>                     .setDummyProp(dummyProp)
>                     .build();
>         }
>         public static Builder builder() {
>             return new AutoValue_App_FooAutoValue.Builder();
>         }
>         @AutoValue.Builder
>         public abstract static class Builder {
>             public abstract Builder setDummyProp(String newDummyProp);
>             public abstract FooAutoValue build();
>         }
>     }
> }
> {code}
> From what I can see, instead of getting the fields from the abstract class, 
> it's trying to get the fields from the concrete implementation. Given that 
> they are not abstract (as it's custom for AutoValue classes, no fields are 
> fetched). This code is in AutoValueSchema.get method.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to