// creating initial k-v pair
System.out.println("Creating initial Key and Value");
String keySchemaJson = "{ \"name\": \"key\", \"type\": \"record\", \"fields\": [{ \"name\": \"user_id\", \"type\": \"int\" }] }";
Schema keySchema = Schema.parse(keySchemaJson);
GenericRecord key = new GenericData.Record(keySchema);
key.put("user_id", 123);
String valueSchemaJson = "{\n" +
" \"name\": \"value\",\n" +
" \"type\": \"record\",\n" +
" \"fields\": [{ \n" +
" \"name\": \"user_id\",\n" +
" \"type\": \"int\"\n" +
" }, {\n" +
" \"name\": \"gender\",\n" +
" \"type\": \"string\"\n" +
" }, {\n" +
" \"name\": \"age\",\n" +
" \"type\": \"int\",\n" +
" \"optional\": true\n" +
" }]\n" +
" }";
Schema valueSchema = Schema.parse(valueSchemaJson);
GenericRecord value = new GenericData.Record(valueSchema);
value.put("user_id", 123);
value.put("gender", "male");
value.put("age", 23);