我正在使用java和spark,并有以下代码
JavaRDD<String> uploadedFiles = resultJavaRDD.map( rdd -> {
String localFilePath = "tmp/myfirst.parquet";
Path dataFile = new Path(filePath);
// Write as Parquet file.
try (ParquetWriter<MyData> writer = AvroParquetWriter.<MyData>builder(dataFile)
.withSchema(ReflectData.AllowNull.get().getSchema(MyData.class))
.withDataModel(ReflectData.get())
.withConf(new Configuration())
.withCompressionCodec(SNAPPY)
.withWriteMode(OVERWRITE)
.build()) { // this build statment throw exception
for (MyData d : rdd.getDataList()) {
writer.write(d);
}
} catch (Exception e) {
System.err.println("Failed to write to the file. \n" + e.getMessage());
}
......
s3Service.uploadFile(s3FilePath, localFlePath); // my own service to upload file to S3
return s3FilePath;
});
但是,我在parquetwriter构建步骤中出错。下面是错误。
java.lang.NoSuchMethodError: org.apache.parquet.hadoop.ParquetWriter.<init>(Lorg/apache/hadoop/fs/Path;Lorg/apache/parquet/hadoop/ParquetFileWriter$Mode;Lorg/apache/parquet/hadoop/api/WriteSupport;Lorg/apache/parquet/hadoop/metadata/CompressionCodecName;IIIZZLorg/apache/parquet/column/ParquetProperties$WriterVersion;Lorg/apache/hadoop/conf/Configuration;I)V
at org.apache.parquet.hadoop.ParquetWriter$Builder.build(ParquetWriter.java:489)
at com.aktana.api.command.DSESparkDriverCommand.lambda$run$3005c09$1(DSESparkDriverCommand.java:590)
at org.apache.spark.api.java.JavaPairRDD$$anonfun$toScalaFunction$1.apply(JavaPairRDD.scala:1015)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.rdd.RDD$$anonfun$collect$1$$anonfun$12.apply(RDD.scala:927)
at org.apache.spark.rdd.RDD$$anonfun$collect$1$$anonfun$12.apply(RDD.scala:927)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:89)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:227)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我的毕业典礼就像
compile 'com.amazonaws:aws-java-sdk:1.11.747'
compile 'org.apache.parquet:parquet-avro:1.8.1'
问题是,如果我不使用spark,而是在纯java中使用相同的代码,那么一切看起来都很正常。请帮忙。谢谢。
1条答案
按热度按时间yc0p9oo01#
似乎有一个错误的参考我使用的类。我使用relocate重新定位org.apache的lib依赖项。parquet:parquet-avro and 现在可以了。