0

I am new to Apache Beam and I am trying to connect to google cloud instance of mysql database. When I run the below code snippet, it's throwing the below exception.

    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();

Exception in thread "main" java.lang.IllegalArgumentException: Cannot setCoder(null) at org.apache.beam.sdk.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) at org.apache.beam.sdk.values.PCollection.setCoder(PCollection.java:265) at org.apache.beam.sdk.io.jdbc.JdbcIO$Read.expand(JdbcIO.java:325) at org.apache.beam.sdk.io.jdbc.JdbcIO$Read.expand(JdbcIO.java:272) at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:482) at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:422) at org.apache.beam.sdk.values.PBegin.apply(PBegin.java:44) at org.apache.beam.sdk.Pipeline.apply(Pipeline.java:164) at com.neudesic.com.GoogleSQLPipeline.main(GoogleSQLPipeline.java:24)

Balu
  • 456
  • 8
  • 19

1 Answers1

0

Looks like, i had some issue with the jar files. I have recreated the workspace and the project . Then the same code is running without any issue.

Thanks

Balu
  • 456
  • 8
  • 19