我正在尝试学习 avro 并且有一个模式问题。
有些文件说
{
"name": "userid",
"type" : "string",
"logicalType" : "uuid"
},
Run Code Online (Sandbox Code Playgroud)
还有人说
{
"name": "userid",
"type" : {
"type" : "string",
"logicalType" : "uuid"
}
},
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的?或者它们是相同的吗?
谢谢你!
我使用avro 工具“随机”命令(别名avro如下)运行了您的模式的变体。它尝试为模式生成随机值。
仅具有此类型且使用嵌套类型语法指定的模式logicalType将被拒绝:
\n\n\n
avro random --schema \'{ "name": "userid", "type" : { "type": "string", "logicalType" : "uuid" } }\' -[...]无类型:{“名称”:“用户ID”,“类型”:{“类型”:“字符串”,“逻辑类型”:“uuid”}}
\n
logicalType但是,当将next 放在以下位置时它会起作用type:
\n\n\n
avro random --schema \' { "type" : "string", "logicalType" : "uuid" }\' -[...] Objavro.schemaL{"类型":"字符串","逻辑类型":"uuid"}avro.codecdeflate}\xef\xbf\xbdj\xef\xbf\xbdU\xef\xbf\xbd.\xef \xbf\xbd\\\xef\xbf\xbdo\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd
\n
现在,当我们在记录中使用它时,在将其放在logicalTypetype 旁边时会收到警告:
\n\n\n
avro random --schema \'{ "type": "record", "fields": [ { "type" : "string", "logicalType" : "uuid", "name": "f"} ] , "name": "rec"}\' -[...] 警告avro.Schema:忽略了rec.f.逻辑类型属性(“uuid”)。它可能应该嵌套在字段的“类型”内。\nObjavro.schema\xef\xbf\xbd{"type":"record","name":"rec","fields":[{"name" :"f","类型":"字符串","逻辑类型":"uuid"}]}avro.codecdeflate\xef\xbf\xbd\xef\xbf\xbdw\xef\xbf\xbd9\xef\xbf\xbd9 \xef\xbf\xbdn\xef\xbf\xbds\xef\xbf\xbd
\n
接受嵌套语法而不发出警告:
\n\n\n\n
avro random --schema \'{ "type": "record", "fields": [ { "type" : { "type": "string", "logicalType" : "uuid" } , "name": "f"} ] , "name": "rec"}\' -\xef\xbf\xbdw<\xef\xbf\xbd\xef\xbf\xbdqcord","名称":"rec","字段":[{"名称":"f","类型":{"类型":"字符串","逻辑类型":"uuid"}}]}avro.codecdeflate8\xef\xbf\xbd\xef\xbf\xbdt
\n
此外,如果我们查看数组内的逻辑类型:
\n\n\n\n
avro random --count 1 --schema \' { "type": "array", "items": { "type" : "string", "logicalType" : "uuid" , "name": "f"} , "name": "farr" } \' -[...随机位]
\n
当嵌套版本失败时:
\n\n\n\n
avro random --count 1 --schema \' { "type": "array", "items": {"type": { "type" : "string", "logicalType" : "uuid" , "name": "f"} } , "name": "farr" } \' -[...] 无类型:{“type”:{“type”:“string”,“逻辑类型”:“uuid”,“name”:“f”}}
\n
看起来,如果逻辑类型是记录中字段的类型,则需要使用嵌套语法。\n否则,需要使用非嵌套语法。
\n| 归档时间: |
|
| 查看次数: |
2881 次 |
| 最近记录: |