使用Beam从Oracle进行JDBC提取 [英] JDBC Fetch from oracle with Beam
问题描述
以下程序用于连接到Oracle 11g并获取记录。
The below program is to connect to Oracle 11g and fetch the records. How ever it is giving me NullPointerException for the coder at pipeline.apply().
我已将ojdbc14.jar添加到项目依赖项中。
I have added the ojdbc14.jar to the project dependencies.
public static void main(String[] args) {
Pipeline p = Pipeline.create(PipelineOptionsFactory.create());
p.apply(JdbcIO.<KV<Integer, String>>read()
.withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(
"oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@hostdnsname:port/servicename")
.withUsername("uname")
.withPassword("pwd"))
.withQuery("select EMPID,NAME from EMPLOYEE1")
.withRowMapper(new JdbcIO.RowMapper<KV<Integer, String>>() {
public KV<Integer, String> mapRow(ResultSet resultSet) throws Exception {
return KV.of(resultSet.getInt(1), resultSet.getString(2));
}
}));
p.run();
}
给出以下错误。有任何线索吗?
is giving the below error.Any clue?
Exception in thread "main" java.lang.NullPointerException: coder
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:228)
at org.apache.beam.sdk.io.jdbc.JdbcIO$Read.validate(JdbcIO.java:283)
at org.apache.beam.sdk.io.jdbc.JdbcIO$Read.validate(JdbcIO.java:216)
at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:399)
at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:307)
at org.apache.beam.sdk.values.PBegin.apply(PBegin.java:47)
at org.apache.beam.sdk.Pipeline.apply(Pipeline.java:158)
at org.apache.beam.examples.v030.JdbcUtil.main(JdbcUtil.java:21)
推荐答案
嗨!
对不起该错误消息不是很有帮助,但实际上这是一个验证步骤。我已经提交了 BEAM-959 来改善这一点。
Sorry the error message is not very helpful, but in fact it is a validation step. I have filed BEAM-959 to improve this.
您需要提供一个编码器,例如via
You are required to provide a coder such as via
.withCoder(KvCoder.of(VarIntCoder.of(), StringUtf8Coder.of())`
I已提交 BEAM-960 来提高该编码器的自动化程度,就像我们在Beam中其他大多数地方。
I have filed BEAM-960 to improve automation of this coder, like we have in most other places in Beam.
这篇关于使用Beam从Oracle进行JDBC提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!