简体   繁体   English

在Java中为avro模式字段设置默认值

[英]set default value for avro schema field in java

how do we set default value of a field in avro schema by using java. 我们如何通过使用Java在avro模式中设置字段的默认值。 By using Schema object we can extract the schema and get Fields retrieves all the fields in a list. 通过使用架构对象,我们可以提取架构并获取字段,以检索列表中的所有字段。

List fields = schema.getFields(); 列表字段= schema.getFields();

by iterating over the fields we can set and get all the attributes of the field except default. 通过遍历这些字段,我们可以设置并获取除默认值以外的所有字段属性。 DefaultValue() can only be retreived. DefaultValue()只能检索。 Do anyone know how to set default value for a field.is their any workaround for this? 有谁知道如何为字段设置默认值。他们对此有任何解决方法吗? thanks 谢谢

通过avro api找到了解决方案。

We need to set the default value while creating the field 我们需要在创建字段时设置默认值

https://avro.apache.org/docs/1.5.4/api/java/org/apache/avro/Schema.Field.html https://avro.apache.org/docs/1.5.4/api/java/org/apache/avro/Schema.Field.html

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

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