我正在为Avro使用.Net库我有C#的下一课
namespace Test.Avro.Model
{
[DataContract(Name = "SensorDataValue", Namespace = "Sensors")]
public class TestNm
{
[DataMember(Name = "name")]
public string name { get; set; }
[DataMember(Name = "surname", IsRequired = true)] //test to see if IsRequired works
public string surname { get; set; }
[DataMember(Name = "country", IsRequired = false)] //test to see if IsRequired works
public string country { get; set; }
}
}
当我使用SequentialWriter将类编写为avro文件时使用对象容器文件和使用反射(http://azure.microsoft.com/en-us/documentation/articles/hdinsight-dotnet-avro-serialization/的序列化)保留在序列化中时,我在avro文件中获得以下json
Objavro.codecdeflateavro.schemaÆ{
"type": "record",
"name": "Sensors.SensorDataValue",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "surname",
"type": "string"
},
{
"name": "country",
"type": "string"
}
]
} ...
我想拥有的是
Objavro.codecdeflateavro.schemaÆ{
"type": "record",
"name": "Sensors.SensorDataValue",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "surname",
"type": [
"string",
"null"
]
},
{
"name": "country",
"type": [
"string",
"null"
]
}
]
}...
非常感谢你的帮助。 PS:我能找到的唯一相关信息是https://hadoopsdk.codeplex.com/workitem/53
答案 0 :(得分:1)
您可以通过添加属性[NullableSchema]
(在Avro库中定义)使属性可为空。 Avro库会忽略IsRequired
中的DataMember
值。