无法使用HBaseIO和FlinkRunner为org.apache.hadoop.hbase.client.Mutation提供编码器

时间:2018-11-08 02:50:11

标签: apache-beam apache-beam-io

我遇到一个问题,即“无法为org.apache.hadoop.hbase.client.Mutation提供编码器”。在FlinkRunner中使用HbaseIO。 异常如下:

Exception in thread "main" java.lang.IllegalStateException: Unable to return a default Coder for ParDo(HBaseProfile)/ParMultiDo(HBaseProfile).output [PCollection]. Correct one of the following root causes:
No Coder has been manually specified;  you may do so using .setCoder().

Inferring a Coder from the CoderRegistry failed: Unable to provide a Coder for org.apache.hadoop.hbase.client.Mutation.
  Building a Coder using a registered CoderProvider failed.
  See suppressed exceptions for detailed failures.
  Using the default output Coder from the producing PTransform failed: PTransform.getOutputCoder called.
    at org.apache.beam.repackaged.beam_sdks_java_core.com.google.common.base.Preconditions.checkState(Preconditions.java:444)
    at org.apache.beam.sdk.values.PCollection.getCoder(PCollection.java:278)
    at org.apache.beam.sdk.values.PCollection.finishSpecifying(PCollection.java:115)
    at org.apache.beam.sdk.runners.TransformHierarchy.finishSpecifyingInput(TransformHierarchy.java:190)
    at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:536)
    at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:488)
    at org.apache.beam.sdk.values.PCollection.apply(PCollection.java:370)
    at ac.cn.iie.process.ProfileProcess.process(ProfileProcess.java:91)
    at ac.cn.iie.Bootstrap.main(Bootstrap.java:25)

我已经使用maven-shade-plugin打包了我的jar:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>ac.cn.iie.Bootstrap</mainClass>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>reference.conf</resource>
                            </transformer>
                        </transformers>
                        <relocations>
                            <relocation>
                                <pattern>org.codehaus.plexus.util</pattern>
                                <shadedPattern>org.shaded.plexus.util</shadedPattern>
                                <excludes>
                                    <exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
                                    <exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
                                </excludes>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
        </plugin>

有人知道原因吗?

3 个答案:

答案 0 :(得分:0)

我已经通过手动注册Beam CoderProvider解决了我的问题。代码如下:

CoderRegistry coderRegistry = pipeline.getCoderRegistry();
coderRegistry.registerCoderProvider(
    new HBaseCoderProviderRegistrar().getCoderProviders().get(0));

HBaseCoderProviderRegistrar()通过getCoderProviders()方法提供一个CoderProvider列表,列表的0索引是HBaseMutationCoder。 因为我的代码使用HBaseIO.write(),所以只需注册Mutation Coder。

答案 1 :(得分:0)

请注意,HBaseCoderProviderRegistrar已经为 Mutation 类型自动注册了 HBaseMutationCoder

使用maven-shade插件而不处理输出jar中 META-INF / 中包含的 service 文件是用户的常见陷阱。您想将ServicesResourceTransformer添加到您的转换器列表中,如下所示:

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

有关更多详细信息,请参见Apache documentationServiceLoader javadoc。在StackOverflow上还有很多其他类似问题。

答案 2 :(得分:0)

使 POJO 类可序列化。 公共类 CustomerEntity 实现了 Serializable {

private String id;

private String name;