gpt4 book ai didi

java - 从 Azure Blob 容器读取 Parquet 数据,而无需在本地下载

转载 作者:行者123 更新时间:2023-12-02 06:29:19 24 4
gpt4 key购买 nike

我正在使用 azure SDK、avro-parquet 和 hadoop 库从 Blob 容器读取 parquet 文件。目前,我正在将文件下载到临时文件,然后创建一个 ParquetReader。

try (InputStream input = blob.openInputStream()) {
Path tmp = Files.createTempFile("tempFile", ".parquet");

Files.copy(input, tmp, StandardCopyOption.REPLACE_EXISTING);
IOUtils.closeQuietly(input);
InputFile file = HadoopInputFile.fromPath(new org.apache.hadoop.fs.Path(tmp.toFile().getPath()),
new Configuration());
ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord> builder(file).build();

GenericRecord record;
while ((record = reader.read()) != null) {
recordList.add(record);
}
} catch (IOException | StorageException e) {
log.error(e.getMessage(), e);
}

我想使用来自 azure blob 项目的 inputStream 读取此文件,而不将其下载到我的计算机上。 S3(Read parquet data from AWS s3 bucket)有这样的方法,但是Azure是否存在这种可能性?

最佳答案

了解如何做到这一点。

 StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountName, accountKey);
CloudStorageAccount connection = new CloudStorageAccount(credentials, true);
CloudBlobClient blobClient = connection.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);

CloudBlob blob = container.getBlockBlobReference(fileName);

Configuration config = new Configuration();
config.set("fs.azure", "org.apache.hadoop.fs.azure.NativeAzureFileSystem");
config.set("fs.azure.sas.<containerName>.<accountName>.blob.core.windows.net", token);
URI uri = new URI("wasbs://<containerName>@<accountName>.blob.core.windows.net/" + blob.getName());
InputFile file = HadoopInputFile.fromPath(new org.apache.hadoop.fs.Path(uri),
config);
ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord> builder(file).build();

GenericRecord record;
while ((record = reader.read()) != null) {
System.out.println(record);
}
reader.close();

关于java - 从 Azure Blob 容器读取 Parquet 数据,而无需在本地下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56026462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com