2017-06-29 116 views
1

我有一个模式,我有两个包含对方元素的字段的记录。你如何在Avro中声明一个记录,以便你可以在定义之前使用它的声明。相互记录相关的模式

{ 
"namespace": "mytest", 
"name": "Foo", 
"type": "record", 
"fields": [ 
    {"name" : "bar", "type": ["null", "Bar"]} 
], 

"name": "Bar", 
"type": "record", 
"fields": [ 
    {"name" : "foo", "type": ["null", "Foo"]} 
] 
} 

回答

1

据我所知,你不能像使用的那样在模式中使用记录语句。

我认为你需要这样的模式:

{ 
    "type": "record", 
    "name": "Foo", 
    "namespace": "q44820145", 
    "fields": [ 
    { 
     "name": "bar", 
     "type": { 
     "type": "record", 
     "name": "Bar", 
     "fields": [ 
      { 
      "name": "foo", 
      "type": ["null", "Foo"] 
      } 
     ] 
     } 
    } 
    ] 
} 
+0

我面前,但是我一直在寻找一种方式,所以我可以保持它自己的文件中的每个定义已经看到了这句法。然而,在高音扬声器API上工作,我仍然可以参考其他文件中的内部声明。所以我客人这是我们今天最好的。所以我会将此标记为答案。 – Fabio