I am now working on a task which requires me to write Apache Ignite cache-stored data to Avro.
Unfortunately I do not have an access to initial Java classes used for cache-stored objects creation.
The only source I have is Apache Ignite (it's Java API). Cache Itself is presented as IgniteCache<Object, Object>
. Actually each cache entry is a key-value pair where key is realized as an AffinityKey and value contains a project-related object.
Cache entry looks as follows when converting it to JSON:
{
"AffinityKey [key=1, affKey=1f1a11b-ba1e-1cd1-1c11-c11111ab1111]": {
"version": null,
"name": "Name 1",
"description": "Description 1",
"interests": [
"int1",
"int2",
"int3",
"int4"
],
"hobbies": [
"hobby1",
"hobby2",
"hobby3"
],
"classId": 11111,
"creator": "5b90fb41e0eb212c4736d186",
"editorId": null,
"logoConfigurationId": 85,
"editTimeout": null,
"active": false,
"lastActionTime": {
"year": 2020,
"month": "MAY",
"nano": 143000000,
"monthValue": 5,
"dayOfMonth": 18,
"hour": 14,
"minute": 1,
"second": 4,
"dayOfYear": 139,
"dayOfWeek": "MONDAY",
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"status": "Attention required",
"lastJobId": null
}
}
Can somebody please advise on how can I serialize my Ignite cache entries to Avro? As I know Avro-schema is required for avro-serialization. For this I will need to know both name and type for each field captured in my cache entry. The only way I see for schema creation is to get both entry-key and entry-value represented as BinaryObject and then collect all field names and types. Having all the name-type pairs for object's fields it may be possible to manually construct some kind of json for further storing it in .asvc file.
Perhaps somebody can advise on a bit more 'elegant' solution?
Having an Ignite Cache Entry represented as a Map<BinaryObject, BinaryObject>
(.withKeepBinary()
should be used when requesting cache from Ignite) it is possible to extract the definition for each BinaryObject's field (field name + field type). Avro SchemaBuilder can be used further for avro schema generation.