gpt4 book ai didi

avro - 逻辑类型的架构

转载 作者:行者123 更新时间:2023-12-04 15:03:40 24 4
gpt4 key购买 nike

我正在尝试学习 avro 并在架构中有一个问题。
一些文件说

{
"name": "userid",
"type" : "string",
"logicalType" : "uuid"
},
还有人说
{
"name": "userid",
"type" : {
"type" : "string",
"logicalType" : "uuid"
}
},
哪一个是对的?或者他们是一样的?
谢谢!

最佳答案

我用 avro tools "random" command 运行了你的模式的变体(以下别名为 avro)。它尝试为模式生成随机值。
仅具有此类型的模式使用嵌套类型语法指定 logicalType被拒绝:

avro random --schema '{ "name": "userid", "type" : { "type": "string", "logicalType" : "uuid" } }' -

[...] No type: {"name":"userid","type":{"type":"string","logicalType":"uuid"}}


但是,它在放置 logicalType 时有效旁边 type :

avro random --schema ' { "type" : "string", "logicalType" : "uuid" }' -

[...] Objavro.schemaL{"type":"string","logicalType":"uuid"}avro.codecdeflate}�j�U�.�\�o���


现在,当我们在记录中使用它时,我们会在放置 logicalType 时收到警告。旁边键入:

avro random --schema '{ "type": "record", "fields": [ { "type" : "string", "logicalType" : "uuid", "name": "f"} ] , "name": "rec"}' -

[...] WARN avro.Schema: Ignored the rec.f.logicalType property ("uuid"). It should probably be nested inside the "type" for the field.Objavro.schema�{"type":"record","name":"rec","fields":[{"name":"f","type":"string","logicalType":"uuid"}]}avro.codecdeflate��w�9�9�n�s�


接受嵌套语法而不发出警告:

avro random --schema '{ "type": "record", "fields": [ { "type" : { "type": "string", "logicalType" : "uuid" } , "name": "f"} ] , "name": "rec"}' -

�w<��qcord","name":"rec","fields":[{"name":"f","type":{"type":"string","logicalType":"uuid"}}]}avro.codecdeflate8��t


此外,如果我们查看数组中的逻辑类型:

avro random --count 1 --schema ' { "type": "array", "items": { "type" : "string", "logicalType" : "uuid" , "name": "f"} , "name": "farr" } ' -

[... random bits]


虽然嵌套版本失败:

avro random --count 1 --schema ' { "type": "array", "items": {"type": { "type" : "string", "logicalType" : "uuid" , "name": "f"} } , "name": "farr" } ' -

[...] No type: {"type":{"type":"string","logicalType":"uuid","name":"f"}}


看来,如果logicalType 是记录中字段的类型,则需要使用嵌套语法。
否则,您需要使用非嵌套语法。

关于avro - 逻辑类型的架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66540633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com