我正在尝试使用 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>
Does anyone have any idea how to address this?
最佳答案
从错误消息来看,您的 S3 存储桶区域似乎使用 Signature Version 4 (v4) 签名协议(protocol),并且不支持旧版本 (v2)。
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
在这种情况下,您必须设置属性
fs.s3a.endpoint
在 core-site.xml
或在作业配置中。此属性的值可在 Amazon S3 Endpoints 下找到。 .此外,
s3a
客户端而不是 s3
. fs.s3a.access.key
和 fs.s3a.secret.key
.可用于 S3 身份验证的完整属性列表可在 here 中找到。 . 关于java - 如何解决 S3 错误 : org. jets3t.service.S3ServiceException : S3 GET failed? Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61160689/