Apache Beam throws不能setCoder(null):java

时间:2017-06-19 04:19:53

标签: google-cloud-dataflow apache-beam apache-beam-io

我是Apache Beam的新手,我正在尝试连接到mysql数据库的谷歌云实例。当我运行下面的代码片段时,它会抛出以下异常。

    Logger logger = LoggerFactory.getLogger(GoogleSQLPipeline.class);

    PipelineOptions options = PipelineOptionsFactory.create();

    Pipeline dataflowPipeline = Pipeline.create();

    dataflowPipeline.apply(JdbcIO.<KV<Integer, String>>read().withCoder(KvCoder.of(VarIntCoder.of(), StringUtf8Coder.of()))
            .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration
                    .create("com.mysql.jdbc.Driver", "jdbc:mysql://<ip from google instance>:3306/foodmart")
                    .withUsername("root").withPassword("root"))
            .withQuery("select accouont_id,account_description  from account")
            .withRowMapper(new JdbcIO.RowMapper<KV<Integer, String>>() {
                @Override
                public KV<Integer, String> mapRow(ResultSet resultSet) throws Exception {
                    // TODO Auto-generated method stub
                    return KV.of(resultSet.getInt(1), resultSet.getString(2));
                }
            }));

    dataflowPipeline.run();

线程“main”中的异常java.lang.IllegalArgumentException:无法setCoder(null)     在org.apache.beam.sdk.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)     在org.apache.beam.sdk.values.PCollection.setCoder(PCollection.java:265)     在org.apache.beam.sdk.io.jdbc.JdbcIO $ Read.expand(JdbcIO.java:325)     在org.apache.beam.sdk.io.jdbc.JdbcIO $ Read.expand(JdbcIO.java:272)     在org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:482)     在org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:422)     在org.apache.beam.sdk.values.PBegin.apply(PBegin.java:44)     在org.apache.beam.sdk.Pipeline.apply(Pipeline.java:164)     在com.neudesic.com.GoogleSQLPipeline.main(GoogleSQLPipeline.java:24)

1 个答案:

答案 0 :(得分:0)

看起来,我有一些jar文件的问题。我重新创建了工作区和项目。然后相同的代码运行没有任何问题。

由于