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

如何将AVRO Schema中的枚举字段替换为字符串类型?

将AVRO Schema中的ENUM类型替换为String类型的操作步骤

1. 修改主Schema的字段定义

直接把字段类型里的枚举引用替换成string类型即可。原字段代码:

{
  "name": "anonymizedLanguage",
  "type": [
    "null",
    "com.publicevents.common.LanguageCode"
  ],
  "default": null
}

修改后的代码:

{
  "name": "anonymizedLanguage",
  "type": [
    "null",
    "string"
  ],
  "default": null
}

2. 清理枚举文件

由于不再依赖LanguageCode枚举,直接删除独立的LanguageCode.avsc文件就行。

补充说明

这个修改是向前兼容的:旧数据里存储的枚举符号(比如EN、NL)用新Schema读取时,会自动解析为对应的字符串值,不会出现读取异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 22:50:40