我是 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();
线程“主”java.lang.IllegalArgumentException 中的异常:无法在 org.apache.beam.sdk.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)处设置编码器(null)在 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)