[PS:我已经在相同的错误下经历了所有可能的问题,并试图修复我的Json模式]我有以下Avro模式(使用http://json-schema-validator.herokuapp.com/avro.jsp转换为JSON):
{
"definitions" : {
"record:parentTest.test.MyPlatformData" : {
"description" : "representsthetestevent",
"type" : "object",
"required" : [ "event", "subjects" ],
"additionalProperties" : false,
"properties" : {
"event" : {
"$ref" : "#/definitions/record:parentTest.test.event_record"
},
"subjects" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/record:parentTest.test.TESTEVENT_record"
}
}
}
},
"record:parentTest.test.event_record" : {
"type" : "object",
"required" : [ "created_at", "id", "event_at", "subject", "action", "up_event_id", "up_source" ],
"additionalProperties" : false,
"properties" : {
"created_at" : {
"type" : "string"
},
"id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
},
"event_at" : {
"type" : "string"
},
"subject" : {
"type" : "string"
},
"action" : {
"type" : "string"
},
"up_event_id" : {
"default" : "null",
"oneOf" : [ {
"type" : "string"
}, {
"type" : "null"
} ]
},
"up_source" : {
"default" : "null",
"oneOf" : [ {
"type" : "string"
}, {
"type" : "null"
} ]
}
}
},
"record:parentTest.test.TESTEVENT_record" : {
"type" : "object",
"required" : [ "mydata", "id", "user_id", "data_id", "place_id", "my_object" ],
"additionalProperties" : false,
"properties" : {
"mydata" : {
"$ref" : "#/definitions/record:parentTest.test.mydata_record"
},
"id" : {
"type" : "integer",
"minimum" : -9223372036854775808,
"maximum" : 9223372036854775807
},
"user_id" : {
"type" : "integer",
"minimum" : -9223372036854775808,
"maximum" : 9223372036854775807
},
"data_id" : {
"type" : "integer",
"minimum" : -9223372036854775808,
"maximum" : 9223372036854775807
},
"place_id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
},
"my_object" : {
"$ref" : "#/definitions/record:parentTest.test.my_object_record"
}
}
},
"record:parentTest.test.mydata_record" : {
"type" : "object",
"required" : [ "id", "del" ],
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "integer",
"minimum" : -9223372036854775808,
"maximum" : 9223372036854775807
},
"del" : {
"$ref" : "#/definitions/record:parentTest.test.del_record"
}
}
},
"record:parentTest.test.del_record" : {
"type" : "object",
"required" : [ "status", "track_details", "cr", "service_level" ],
"additionalProperties" : false,
"properties" : {
"status" : {
"$ref" : "#/definitions/record:parentTest.test.status_record"
},
"tracking_details" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/record:parentTest.test.tracking_number_detail_record"
}
},
"cr" : {
"$ref" : "#/definitions/record:parentTest.test.cr_record"
},
"service_level" : {
"$ref" : "#/definitions/record:parentTest.test.service_level_record"
}
}
},
"record:parentTest.test.status_record" : {
"type" : "object",
"required" : [ "name", "status_at" ],
"additionalProperties" : false,
"properties" : {
"name" : {
"type" : "string"
},
"status_at" : {
"type" : "string"
}
}
},
"record:parentTest.test.tracking_number_detail_record" : {
"type" : "object",
"required" : [ "id", "cr", "status" ],
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "string"
},
"cr" : {
"$ref" : "#/definitions/record:parentTest.test.tracking_cr_record"
},
"status" : {
"$ref" : "#/definitions/record:parentTest.test.trac_status_record"
}
}
},
"record:parentTest.test.tracking_cr_record" : {
"type" : "object",
"required" : [ "id" ],
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
}
}
},
"record:parentTest.test.tracking_status_record" : {
"type" : "object",
"required" : [ "name", "status_at" ],
"additionalProperties" : false,
"properties" : {
"name" : {
"oneOf" : [ {
"type" : "string"
}, {
"type" : "null"
} ]
},
"status_at" : {
"oneOf" : [ {
"type" : "string"
}, {
"type" : "null"
} ]
}
}
},
"record:parentTest.test.cr_record" : {
"type" : "object",
"required" : [ "id" ],
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
}
}
},
"record:parentTest.test.service_level_record" : {
"type" : "object",
"required" : [ "sc_id", "ss_id", "ss_class" ],
"additionalProperties" : false,
"properties" : {
"sc_id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
},
"ss_id" : {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
},
"ss_class" : {
"type" : "string"
}
}
},
"record:parentTest.test.mydata_record" : {
"type" : "object",
"required" : [ "s_id" ],
"additionalProperties" : false,
"properties" : {
"s_id" : {
"oneOf" : [ {
"type" : "integer",
"minimum" : -2147483648,
"maximum" : 2147483647
}, {
"type" : "null"
} ]
}
}
}
},
"$ref" : "#/definitions/record:parentTest.test.MyPlatformData"
}
然而,在插入以下数据时,我得到以下错误
输入数据
{
"event": {
"action": "TESTEVENT",
"created_at": "2021-01-21T14:16:23+00:00",
"event_at": "2021-01-21T14:16:23.747",
"id": 28001755,
"subject": "TEST_ITEM",
"up_source": {
"string": "TEST_W"
},
"up_event_id": {
"string": "59c7eec8-9bf6-4907-9df9-628d92abd278"
}
},
"subjects": [
{
"id": 12345678,
"user_id": 5197509841,
"data_id": 3497218791,
"place_id": 49,
"mydata": {
"s_id": {
"int": 29489
}
},
"my_object": {
"id": 5417499011,
"del": {
"status": {
"name": "TESTEVENT",
"status_at": "2021-01-21T09:09:00"
},
"tracking_details": [
{
"id": "CS303755237",
"cr": {
"id": 961
},
"status": {
"name": {
"string": "TESTEVENT"
},
"status_at": {
"string": "2021-01-21T09:09:00"
}
}
}
],
"cr": {
"id": 961
},
"service_level": {
"sc_id": 2,
"ss_id": 5,
"ss_class": "MY_TEST_SS"
}
}
}
}
]
}
误差
Caused by: org.apache.avro.AvroTypeException: Expected start-union. Got VALUE_NUMBER_INT
我终于找到了问题。作为一个初学者,我当时无法理解。
对于遇到类似问题的人:
规则:当字段被标记为"数据类型"one_answers";null"两者都是如果值不为空,提及数据类型是很重要的。
例如:
For Avro schema, field definition :
"up_source" : {
"default" : "null",
"oneOf" : [ {
"type" : "string"
}, {
"type" : "null"
} ]
}
Possible declarations :
"up_source": {
"string": "TEST_123"
},
OR
"up_source": null,
我的一个字段缺少这个。