Apache Beam: Invisible parameter type exception

一个人想着一个人 提交于 2019-12-24 20:31:38

问题


I have built a small function in Apache Beam to perform a lookup/join: given a collection mapping A to B, and another collection mapping B to C, return a collection mapping A to C.

class Main {
    private static <A,B,C> PCollection<KV<A,C>> lookup(
            PCollection<KV<A,B>> collection,
            PCollection<KV<B,C>> lookup
    ){
        var leftTag = new TupleTag<A>();
        var rightTag = new TupleTag<C>();

        return KeyedPCollectionTuple.of(leftTag, collection.apply(KvSwap.create()))
                .and(rightTag, lookup)
                .apply(CoGroupByKey.create())
                .apply(ParDo.of(new DoFn<KV<B, CoGbkResult>, KV<A, C>>() {
                    @ProcessElement
                    public void processElement(ProcessContext c) {
                        var value = c.element().getValue();
                        var right = value.getOnly(rightTag);

                        for (var i : value.getAll(leftTag)) {
                            c.output(KV.of(i, right));
                        }
                    }
                }));
    }

    public static void main(String[] args) {

        PipelineOptions options = PipelineOptionsFactory.create();
        Pipeline p = Pipeline.create(options);

        PCollection<KV<String, Long>> test = p.apply(Create.of(KV.of("a", 1L), KV.of("b", 2L)))
                .setTypeDescriptor(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.longs()));

        PCollection<KV<Long, String>> test2 = p.apply(Create.of(KV.of(1L, "a"), KV.of(2L, "b")))
                .setTypeDescriptor(TypeDescriptors.kvs(TypeDescriptors.longs(), TypeDescriptors.strings()));

        var c = lookup(test, test2)
                .setTypeDescriptor(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.strings()));

        p.run().waitUntilFinish();
    }
}

Unfortunately, I get the following error when running the pipeline:

Exception in thread "main" org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Invisible parameter type of Main$1 arg0 for public Main$1$DoFnInvoker(Main$1)
    at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2214)
    at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.cache.LocalCache.get(LocalCache.java:4053)
    at org.apache.beam.repackaged.beam_runners_direct_java.com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4057)
    ...
Caused by: java.lang.IllegalStateException: Invisible parameter type of Main$1 arg0 for public Main$1$DoFnInvoker(Main$1)
    at org.apache.beam.repackaged.beam_sdks_java_core.net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:925)
    at org.apache.beam.repackaged.beam_sdks_java_core.net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:465)
    at org.apache.beam.repackaged.beam_sdks_java_core.net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:170)
    ...

I cant seem to find much documentation of what this exception means. I assumed this had something to do with type erasure and tried peppering the code liberally with TypeDescriptors, but with no success. What can I do to fix this error?


回答1:


Turns out that this was caused by using JDK 10, which is not supported by Beam as of writing. Switching to JDK 8 solved the problem.



来源:https://stackoverflow.com/questions/51650074/apache-beam-invisible-parameter-type-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!