【问题标题】:Azure Synapse Serverless -- Unexpected end of stream loading parquet in Azure Synapse Serverless poolAzure Synapse 无服务器 - Azure Synapse 无服务器池中的流加载镶木地板意外结束
【发布时间】:2021-10-31 09:02:52
【问题描述】:

尝试加载以下 parquet 文件会导致 Unexpected end of stream 错误。或许 parquet 文件已损坏?

预期查询

SELECT * FROM OPENROWSET(
        BULK N'/path/to/my.parquet',
        DATA_SOURCE='my_blob_datasource',
        FORMAT='PARQUET'
) as somehow_necessary_alias

错误说明

Statement ID: {1F956C7F-FA37-4D34-AC0D-D4BDF8336160}
Query hash: 0x729ED47717032037
Distributed request ID: {5815A501-2179-4968-BE71-3B7AACFE717C}.
Total size of data scanned is 27 megabytes,
total size of data moved is 290 megabytes,
total size of data written is 0 megabytes.

Msg 15813, Level 16, State 1, Line 1 Error handling external file: 
'Unexpected end of stream'. File/External table name:
https://mystorageaccount.blob.core.windows.net/mycontainer/path/to/my.parquet

【问题讨论】:

  • 你能把文件也附上吗?
  • @maya-msft 没有文件,但我至少提供了一个解释!

标签: tsql parquet azure-synapse


【解决方案1】:

所以我们找到了答案,但我无法制作一个我可以分享的可重现的例子,但我会尽可能多地给出解释。 parquet 文件由pandas.to_parquet() 使用pyarrow 引擎创建。当前存在一个箭头错误,其中尚未诊断的 pandas 索引快速转换为在末尾添加一个名为 "__index_level_0__" 的额外列。我想这就是出现Unexpected end of stream 错误的原因。

此问题最初被标记为 pandas issue,但随后移至具有可重现示例的 Arrow Jira ticket

但是,我们的场景不同,因为我们没有使用pandas.to_parquet()partition_cols 参数,所以发生了一些奇怪的事情。幸运的是,pandas docs 提出了以下建议:

如果您使用,下面的代码会创建一个包含三列的 parquet 文件 pyarrow 用于序列化:a、b 和 __index_level_0__。如果你是 使用fastparquet,索引可能会或可能不会写入文件。

python df.to_parquet("test.parquet", engine="pyarrow")

这个意外的额外列会导致一些数据库,如 Amazon Redshift 拒绝该文件,因为该列不存在于 目标表。

如果你想在写的时候省略dataframe的索引,通过 index=Falseto_parquet()

附言如果您使用pandas 创建parquet 文件以上传到Synapse,请务必将use_deprecated_int96_timestamps=True 传递给to_parquet(),以便Synapse 正确解析您的日期时间列。相关信息见this question

【讨论】:

    【解决方案2】:

    我的问题是我使用的parquet.net 版本错误地写入了Int16 数据(请参阅此处的问题:https://github.com/aloneguid/parquet-dotnet/issues/16)。我将属性更改为 Int32 并且错误消失了。

    【讨论】:

      【解决方案3】:

      我重现了该场景,并能够在 Azure Synapse Serverless SQL 池中成功运行查询。

      注意:确保您有权访问该文件并确保您使用的是 UTF-8 数据库排序规则。

      您可以通过此document 了解更多详情。

      【讨论】:

        猜你喜欢
        • 2021-12-20
        • 2021-05-22
        • 2021-06-06
        • 2021-05-28
        • 2021-05-27
        • 2023-02-17
        • 2022-01-23
        • 2021-05-09
        • 2022-06-16
        相关资源
        最近更新 更多