avro 模式中的默认值为 null,它应该是 "null" 还是 null?
Default values to null in an avro schema, should it be "null" or null?
我是 Avro 的新手,正在尝试定义模式。想知道我是否试图将一个值默认为 null,它应该是:
一个。 "default": 空
b。 "default": "null"
数据类型是什么重要吗?像 int 那么默认值将是 "default": null,但是当它是一个字符串时,默认值应该是 "default":"null"?或者没关系?
要将值默认为 null,您必须指定 "default": null
。有关每种类型的示例值,请参阅规范 Complex Types 部分中的 table。
Does it matter what the data type is?
是的,类型很重要。正如您在规范的 Primitive Types 部分中看到的,null
是它自己的类型。您不能将 int
、string
或任何其他基本类型设置为 null
。
如果您想要一个“可为空”的字段,请使用 Unions。例如:
{ "type": ["null", "int"], "default": null }
这表明此数据可能是 int
,也可能是 null
。它默认为 null
。为联合指定默认值时,请记住默认值必须与联合中的第一个类型匹配。
(Note that when a default value is specified for a record field whose type is a union, the type of the default value must match the first element of the union. Thus, for unions containing "null", the "null" is usually listed first, since the default value of such unions is typically null.)
我是 Avro 的新手,正在尝试定义模式。想知道我是否试图将一个值默认为 null,它应该是:
一个。 "default": 空
b。 "default": "null"
数据类型是什么重要吗?像 int 那么默认值将是 "default": null,但是当它是一个字符串时,默认值应该是 "default":"null"?或者没关系?
要将值默认为 null,您必须指定 "default": null
。有关每种类型的示例值,请参阅规范 Complex Types 部分中的 table。
Does it matter what the data type is?
是的,类型很重要。正如您在规范的 Primitive Types 部分中看到的,null
是它自己的类型。您不能将 int
、string
或任何其他基本类型设置为 null
。
如果您想要一个“可为空”的字段,请使用 Unions。例如:
{ "type": ["null", "int"], "default": null }
这表明此数据可能是 int
,也可能是 null
。它默认为 null
。为联合指定默认值时,请记住默认值必须与联合中的第一个类型匹配。
(Note that when a default value is specified for a record field whose type is a union, the type of the default value must match the first element of the union. Thus, for unions containing "null", the "null" is usually listed first, since the default value of such unions is typically null.)