【问题标题】:Azure Function in Python get schema of parquet filePython中的Azure函数获取镶木地板文件的架构
【发布时间】:2021-02-19 18:03:38
【问题描述】:

是否可以在 Python 中使用 Azure 函数获取 parquet 文件的架构,而无需从 datalake 下载文件?我使用 BlobStorageClient 连接到数据湖并获取文件和容器,但我不知道如何使用例如 pyarrow 调度命令。

关于pyarrow:https://arrow.apache.org/docs/python/parquet.html

BlobStorageClient:https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python-legacy

【问题讨论】:

  • 你介意用stream来实现吗?

标签: function azure-data-lake pyarrow


【解决方案1】:

关于问题,请参考以下脚本

import pyarrow.parquet as pq
import io
from azure.storage.blob import BlobServiceClient

blob_service_client = BlobServiceClient.from_connection_string(conn_str)
container_client = blob_service_client.get_container_client('test')
blob_client = container_client.get_blob_client('test.parquet')

with io.BytesIO() as f:
    download_stream = blob_client.download_blob(0)
    download_stream.readinto(f)
    schema = pq.read_schema(f)
    print(schema)

【讨论】:

【解决方案2】:

使用read_schemaread_metadata可以在不读取文件内容的情况下同时读取parquet模式和parquet元数据:

import pyarrow.parquet as pq

fname = 'filename.parquet'
meta = pq.read_metadata(fname)
schema = pq.read_schema(fname)

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2021-01-12
    • 2019-08-04
    相关资源
    最近更新 更多