You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Parquet文件体积远超JSON问题及Blob存储合理性咨询

问题描述

使用的依赖:

<dependency>
    <groupId>org.apache.parquet</groupId>
    <artifactId>parquet-avro</artifactId>
    <version>1.10.1</version>
</dependency>

AVRO Schema:

{
  "type": "record",
  "name": "ProfileAuditSchema",
  "doc": "Profile Audit Records",
  "fields":
  [{
    "name": "profileId",
    "type": "string"
  },
    {
      "name": "entityType",
      "type": "string"
    },
    {
      "name": "entityId",
      "type": "string"
    },
    {
      "name": "changesInPII",
      "type": "string"
    },
    {
      "name": "changesInNonPII",
      "type": "string"
    },
    {
      "name": "createdBy",
      "type": "string"
    },
    {
      "name": "createdAt",
      "type": "string"
    },
    {
      "name": "version",
      "type": "string"
    },
    {
      "name": "payload",
      "type": "string"
    },
    {
      "name": "operation",
      "type": "string"
    }
  ]
}

其中changesInPII和payload是通过自定义工具加密后的Blob字段。原本2KB的JSON数据转换为Parquet文件后体积变为19KB,接近原大小的9倍,这是未预期的异常情况。请问Parquet是否支持Blob格式,以及是否推荐将Blob存储在string字段中?


解答

1. Parquet对Blob格式的支持

Parquet原生支持二进制数据存储,对应AVRO中的bytes类型,而非string类型。Blob本质是无结构的二进制字节流,Parquet的二进制类型可以直接适配这种数据,不需要额外的编码转换。

2. 不推荐将Blob存储在string字段中的原因

  • 体积暴涨:加密后的Blob是二进制数据,若要存储为string,通常需要先转成Base64等文本编码,这会直接让数据体积增加约33%。再加上Parquet对string类型的存储优化(如字典编码)对加密后的随机字符串完全失效,甚至会因为额外的元数据开销进一步增大体积,这就是你遇到文件体积异常膨胀的核心原因。
  • 性能损耗:二进制与string之间的编码、解码过程会额外消耗CPU资源,降低读写效率。
  • 类型不匹配风险:string类型是为UTF-8文本设计的,强行存储二进制数据可能引发编码兼容问题,比如部分字节序列无法被解析为合法UTF-8字符,导致数据损坏。

3. 正确的处理方式

修改AVRO Schema,将changesInPII和payload的类型从string改为bytes:

{
  "type": "record",
  "name": "ProfileAuditSchema",
  "doc": "Profile Audit Records",
  "fields":
  [{
    "name": "profileId",
    "type": "string"
  },
    {
      "name": "entityType",
      "type": "string"
    },
    {
      "name": "entityId",
      "type": "string"
    },
    {
      "name": "changesInPII",
      "type": "bytes"
    },
    {
      "name": "changesInNonPII",
      "type": "string"
    },
    {
      "name": "createdBy",
      "type": "string"
    },
    {
      "name": "createdAt",
      "type": "string"
    },
    {
      "name": "version",
      "type": "string"
    },
    {
      "name": "payload",
      "type": "bytes"
    },
    {
      "name": "operation",
      "type": "string"
    }
  ]
}

这样Parquet会直接存储原始加密二进制数据,避免编码转换带来的体积膨胀,同时压缩算法(如Snappy、Gzip)也能正常作用(虽然加密后数据随机性高,压缩率可能有限,但不会出现反向膨胀的情况)。


内容的提问来源于stack exchange,提问作者MrWayne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 10:35:12