Apache Beam,BigQueryIO.WriteTableRows() 上的 NoSuchMethodError?
Apache Beam, NoSuchMethodError on BigQueryIO.WriteTableRows()?
我最近将现有管道从数据流 1.x 升级到数据流 2.x,但我看到一个对我来说没有意义的错误。我将把相关代码放在下面,然后包括我看到的错误。
// This is essentially the final step in our pipeline, where we write
// one of the side outputs from the pipeline to a BigQuery table
results.get(matchedTag)
.apply("CountBackfill", Count.<String>perElement())
.apply("ToReportRow", ParDo.of(new ToReportRow()))
// at this point, there is now a PCollection<TableRow>
.apply("WriteReport", BigQueryIO.writeTableRows()
.to(reportingDataset + ".AttributeBackfill_" + dayStr)
.withSchema(ReportSchema.get())
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
/*
* Create a TableRow from a key/value pair
*/
public static class ToReportRow extends DoFn<KV<String, Long>, TableRow> {
private static final long serialVersionUID = 1L;
@ProcessElement
public void processElement(ProcessContext c) throws InterruptedException {
KV<String, Long> row = c.element();
c.output(new TableRow()
.set(ReportSchema.ID, row.getKey())
.set(ReportSchema.COUNT, row.getValue()));
}
}
这是我看到的错误:
Exception in thread "main" java.lang.NoSuchMethodError:
com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
at
org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:1426)
at
org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:989)
at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:525) at
org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:479) at
org.apache.beam.sdk.values.PCollection.apply(PCollection.java:297) at
com.prod.merge.DailyUniqueProfiles.buildPipeline(DUP.java:106)
at com.prod.merge.MergePipeline.main(MergePipeline.java:91)
行 .apply("WriteReport", BigQueryIO.writeTableRows()
是 DUP.java
中的第 106 行,所以我怀疑那行是错误的。
对可能出现的问题有什么想法吗?
这个问题的解决方案最终在 maven 依赖项中。添加以下依赖项并使用 mvn
重新编译后,错误消失了。
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
看起来旧版本的番石榴被传递依赖引入。以下对依赖项的更改对我有用。
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-bigquery</artifactId>
<version>v2-rev295-1.22.0</version>
<exclusions>
<!-- Exclude an old version of guava that is being pulled in by a transitive dependency of google-api-client -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>
我最近将现有管道从数据流 1.x 升级到数据流 2.x,但我看到一个对我来说没有意义的错误。我将把相关代码放在下面,然后包括我看到的错误。
// This is essentially the final step in our pipeline, where we write
// one of the side outputs from the pipeline to a BigQuery table
results.get(matchedTag)
.apply("CountBackfill", Count.<String>perElement())
.apply("ToReportRow", ParDo.of(new ToReportRow()))
// at this point, there is now a PCollection<TableRow>
.apply("WriteReport", BigQueryIO.writeTableRows()
.to(reportingDataset + ".AttributeBackfill_" + dayStr)
.withSchema(ReportSchema.get())
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
/*
* Create a TableRow from a key/value pair
*/
public static class ToReportRow extends DoFn<KV<String, Long>, TableRow> {
private static final long serialVersionUID = 1L;
@ProcessElement
public void processElement(ProcessContext c) throws InterruptedException {
KV<String, Long> row = c.element();
c.output(new TableRow()
.set(ReportSchema.ID, row.getKey())
.set(ReportSchema.COUNT, row.getValue()));
}
}
这是我看到的错误:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V at org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:1426) at org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:989) at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:525) at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:479) at org.apache.beam.sdk.values.PCollection.apply(PCollection.java:297) at com.prod.merge.DailyUniqueProfiles.buildPipeline(DUP.java:106) at com.prod.merge.MergePipeline.main(MergePipeline.java:91)
行 .apply("WriteReport", BigQueryIO.writeTableRows()
是 DUP.java
中的第 106 行,所以我怀疑那行是错误的。
对可能出现的问题有什么想法吗?
这个问题的解决方案最终在 maven 依赖项中。添加以下依赖项并使用 mvn
重新编译后,错误消失了。
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
看起来旧版本的番石榴被传递依赖引入。以下对依赖项的更改对我有用。
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-bigquery</artifactId>
<version>v2-rev295-1.22.0</version>
<exclusions>
<!-- Exclude an old version of guava that is being pulled in by a transitive dependency of google-api-client -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>