![](/img/trans.png)
[英]How to Generate Parquet File Using Pure Java (Including Date & Decimal Types) And Upload to S3 [Windows] (No HDFS)
[英]How to generate parquet file with large amount of data using Java and upload to aws s3 bucket
我正在使用頁面上描述的設置: 如何使用純 Java(包括日期和十進制類型)生成 Parquet 文件並上傳到 S3 [Windows](無 HDFS)
public void writeToParquet(List<GenericData.Record> recordsToWrite, String fileToWrite) throws IOException {
Configuration conf = new Configuration();
conf.set("fs.s3.awsAccessKeyId", "<access_key>");
conf.set("fs.s3.awsSecretAccessKey", "<secret_key>");
Path path = new Path(filePath);//filePath = "s3://bucket/folder/data.parquet"
try (ParquetWriter<GenericData.Record> writer = AvroParquetWriter
.<GenericData.Record>builder(path)
.withSchema(avroSchema)
.withConf(conf).withRowGroupSize(16 * 1024 * 1024).withPageSize(4 * 1024 * 1024)
.build()) {
for (GenericData.Record record : recordsToWrite) {
writer.write(record);
}
writer.close();
}
catch(Exception ex) {
ex.printStackTrace();
LOGGER.info("ParquetWriter Exception " + ex);
}
}
與上面@Sal 提到的相同版本的庫。 當我使用具有大約 5 條記錄的小文件時,它們都可以正常轉換,但我有一大塊大約 800k 的記錄(源文件大小 5GB+)。 我需要將它們轉換為鑲木地板。
問題 1:當我嘗試將其存儲在本地驅動器上並明確上傳時,它幾乎沒有 10 條記錄,output 文件大小約為 5MB。
問題 2:當我嘗試如上所述將其直接上傳到 S3 時,我遇到了有線問題,我總是在第一次運行后遇到異常
java.io.IOException: File already exists: s3://mybucket/output/folder/path/myfile.parquet
但有趣的是文件在該路徑不存在/可見,仍然是這個錯誤。
問題 3:面臨以下異常
java.lang.NoSuchFieldError: workaroundNonThreadSafePasswdCalls
at org.apache.hadoop.io.nativeio.NativeIO.initNative(Native Method)
at org.apache.hadoop.io.nativeio.NativeIO.<clinit>(NativeIO.java:89)
at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:655)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:514)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:290)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:385)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:364)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:555)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:536)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:443)
at org.apache.parquet.hadoop.ParquetFileWriter.<init>(ParquetFileWriter.java:244)
at org.apache.parquet.hadoop.ParquetWriter.<init>(ParquetWriter.java:273)
at org.apache.parquet.hadoop.ParquetWriter$Builder.build(ParquetWriter.java:494)
請幫助提前致謝
我能夠修復java.io.IOException: File already exists:...
添加錯誤
writer = AvroParquetWriter
.withWriteMode(Mode.OVERWRITE)...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.