我正在尝试使用Apache Parquet Reader在S3上获取和读取Parquet文件,我的代码如下所示:

ParquetReader<GenericData.Record> reader = null;
Path internalPath = new Path("s3://S3AccessID:S3SecretKey@bucketName/tmp0.parquet");
try {
            InputFile inputFile = HadoopInputFile.fromPath(internalPath, new Configuration());
            reader = AvroParquetReader.<GenericData.Record>builder(inputFile).build();
            GenericData.Record record;
            while ((record = reader.read()) != null) {
                System.out.println(record);
            }
}

但是,当我构建并运行程序时,这是错误屏幕:
        at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.get(Jets3tFileSystemStore.java:156)
        at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.retrieveINode(Jets3tFileSystemStore.java:195)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:85)
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:62)
        at com.sun.proxy.$Proxy12.retrieveINode(Unknown Source)
        at org.apache.hadoop.fs.s3.S3FileSystem.getFileStatus(S3FileSystem.java:332)
        at org.apache.parquet.hadoop.util.HadoopInputFile.fromPath(HadoopInputFile.java:39)
        at read.read.readParquetFile(read.java:153)
        at read.read.main(read.java:80)
Caused by: org.jets3t.service.S3ServiceException: S3 GET failed for '/%2Ftmp0.parquet' XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.</Message><RequestId>1A66095653EBAD50</RequestId><HostId>jNzbaMmKmszHiLvzA4NsqILRxF+qJFxJLTWvKVwqHoggB0MnYy1ESoajHaa/Ufs5RE8ghs31Jaw=</HostId>

最佳答案

从错误消息中,您的S3存储桶区域似乎使用了签名版本4(v4)签名协议(protocol),并且不支持旧版本(v2)。



在这种情况下,必须在fs.s3a.endpoint或“作业”配置中设置属性core-site.xml。可以在Amazon S3 Endpoints下找到此属性的值。

另外,

  • 使用hadoop的s3a客户端代替s3
  • 使用这些属性fs.s3a.access.keyfs.s3a.secret.key,而不是将access_key和secret_access_key嵌入s3a URL中。可用于S3身份验证的属性的完整列表可以在here中找到。
  • 关于java - 如何解决S3错误:org.jets3t.service.S3ServiceException:S3 GET失败? java ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61160689/

    10-16 10:07