简体   繁体   English

Avro 架构对象 - 递归

[英]Avro schema object - recursion

Is this possible to make class in avro schema that have one of his parameter as themself?这是否可以在 avro 模式中创建具有他的参数之一作为自己的类?

Example in java: java中的例子:

public class Example {

private Integer value;
private Example example;

}

Avro schema is not defined in java, but in a json file usually with .avsc file extension. Avro 模式不是在 java 中定义的,而是在一个 json 文件中定义的,通常带有.avsc文件扩展名。 Here's an example of a recursive avro schema that represents a tree:这是表示树的递归 avro 模式的示例:

{
  "type": "record",
  "name": "Node",
  "fields": [
    {
      "name": "value",
      "type": "long"
    },
    {
      "name": "children",
      "type": { "type": "array", "items": "Node" }
    }
  ]
}

So yes, it is perfectly possible to create recursive schemas.所以是的,创建递归模式是完全可能的。

See also this issue , where even a shorter schema is defined:另请参阅此问题,其中定义了更短的架构:

{
  "type": "record",
  "name": "RecursiveRecord",
  "fields": [{"name": "child", "type": "RecursiveRecord"}]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM