[英]Java: read excel file stored in a bucket using apache beam pipeline
[英]“IllegalStateException” error for Apache Beam pipeline to read from csv file, split, groupbyKey and write to text file. Why?
我的輸入數據如下:
id,vin,url,exteriorColor,interiorColor,design,transmission,lastcrawled,mileage,price,certified,dealerId,historyType,MSRP
114722309,19XVC2F35PR012846,http://www.pohankaacura.com/auto/used-2017-acura-ilx-chantilly-va-near-buckeystown-md/24742881/,Modern Steel,graystone,0,8-Speed Dual-Clutch,2018-02-05 01:49:47 UTC,1646,22550,0,28453
我想建立一個Beam管道,該管道將從csv文件中讀取此數據,獲取vin並計算vin在文件中出現的次數。 所以我想按vin分組並計算計數。 我希望最終輸出在一個平面文件中。 我錯過了注釋,所以現在添加了注釋,但是出現了另一個錯誤,也無法在此處找到解決方案。 下面是我的代碼。
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.io.TextIO;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.transforms.*;
import org.apache.beam.sdk.values.KV;
public class p1 {
public static void main(String[] args) {
PipelineOptions options = PipelineOptionsFactory.create();
Pipeline p = Pipeline.create(options);
p.apply(TextIO.read().from("~/slow_storage_drive/beam_test_files/one_vin.csv"))
.apply("Parse&ConvertToKV", MapElements.via(
new SimpleFunction<String, KV<String, Integer>>() {
public KV<String, Integer> apply(String input){
String[] split = input.split(",");
String key = split[1];
Integer value = 1;
return KV.of(key, value);
}
}
))
.apply(GroupByKey.<String, Integer>create())
.apply("SumOfValuesByKey", ParDo.of(new DoFn<KV<String, Iterable<Integer>>, String>() {
@ProcessElement
public void processElement(ProcessContext context) {
Integer crawlCount = 0;
String vin = context.element().getKey();
Iterable<Integer> counts = context.element().getValue();
for (Integer count : counts){
crawlCount += count;
}
context.output(vin + ": " + crawlCount);
}
}))
.apply(TextIO.write().to("~/slow_storage_drive/beam_example_files/emr_beam_test/final_output").withoutSharding());
p.run().waitUntilFinish();
}
}
我嘗試使用以下命令運行程序:
mvn compile -X exec:java -Dexec.mainClass=p1 -Pdirect-runner
我收到以下錯誤:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project emr_beam_test: An exception occured while executing the Java class. java.lang.IllegalStateException: Invisible parameter type of p1$2 arg0 for public p1$2$DoFnInvoker(p1$2) -> [Help 1]
我無法理解我在做什么錯。 誰能幫幫我嗎?
您必須使用@ProcessElement批注對匿名類方法processElement進行批注。
有關注釋的更多信息,請參閱https://beam.apache.org/releases/javadoc/2.5.0/org/apache/beam/sdk/transforms/DoFn.ProcessElement.html
似乎我收到了不可見的參數類型異常,因為Apache Beam還不支持Java 10。 我將JAVA_HOME更改為指向Java 8,該程序正常工作。 我從這個線程得到了這個主意: Apache Beam:不可見的參數類型異常
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.