从 Azure Blob 容器读取 parquet 数据,无需在本地下载

我正在使用 azure SDK、avro-parquet 和 hadoop 库从 Blob Container 中读取 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 有这样的方式(从 AWS s3 存储桶读取镶木地板数据),但是 Azure 是否存在这种可能性?


白衣非少年
浏览 177回答 1
1回答

慕森王

了解如何做到这一点。&nbsp;StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountName, accountKey);&nbsp;CloudStorageAccount connection = new CloudStorageAccount(credentials, true);&nbsp;CloudBlobClient blobClient = connection.createCloudBlobClient();&nbsp;CloudBlobContainer container = blobClient.getContainerReference(containerName);&nbsp;CloudBlob blob = container.getBlockBlobReference(fileName);&nbsp;Configuration config = new Configuration();&nbsp;config.set("fs.azure", "org.apache.hadoop.fs.azure.NativeAzureFileSystem");&nbsp;config.set("fs.azure.sas.<containerName>.<accountName>.blob.core.windows.net", token);&nbsp;URI uri = new URI("wasbs://<containerName>@<accountName>.blob.core.windows.net/" + blob.getName());&nbsp;InputFile file = HadoopInputFile.fromPath(new org.apache.hadoop.fs.Path(uri),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; config);&nbsp;ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord> builder(file).build();&nbsp;GenericRecord record;&nbsp;while ((record = reader.read()) != null) {&nbsp; &nbsp; &nbsp;System.out.println(record);&nbsp;}&nbsp;reader.close();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java