是否可以使用pyarrow从S3访问点读取镶木地板文件



可以从S3读取镶木地板文件,如这里或这里所示。

我正在使用S3接入点。有了S3接入点ARN,是否可以从中读取镶木地板文件?

我正在尝试以下示例代码:

import s3fs
import pyarrow.parquet as pq
S3_ACCESS_POINT_ARN = "..."
s3_filesystem = s3fs.S3FileSystem()
s3_file_uri = f"{S3_ACCESS_POINT_ARN}/examples/example1.parquet"
example1_df = pq.ParquetDataset(s3_file_uri, s3_filesystem).read_pandas().to_pandas()

执行它的结果是:

ParamValidationError: Parameter validation failed:
Invalid bucket name S3_ACCESS_POINT_ARN: Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:s3:[a-z-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9-]{1,63}$"

我还尝试在S3_ACCESS_POINT_ARN中用:替换/,结果是:

PermissionError: AccessDenied

最后我尝试使用:

pq.read_table(S3_ACCESS_POINT_ARN, s3_filesystem).to_pandas()

导致:

OsError: Passed non-file path: S3_ACCESS_POINT_ARN

值得一提的是,从这个访问点读取文件没有访问问题,下面的代码可以工作:

import boto3
S3_ACCESS_POINT_ARN = "..."
s3 = boto3.resource('s3')
bucket = s3.bucket(S3_ACCESS_POINT_ARN)
bucket.download_file(f"{S3_ACCESS_POINT_ARN}/examples/example1.parquet", "/tmp/examples/example1.parquet")
example1_df = pq.read_table("/tmp/examples/example1.parquet").to_pandas()

更新:S3接入点不允许非顶级列表对象操作:

An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

但我看不到任何允许pyarrow将镶木地板文件视为单个文件的参数,这可能会避免出现此问题。

您必须使用S3接入点别名,而不是S3接入点ARN。

相关内容

最新更新