* @param field the Avro field representing a datum
* @param value the field value
*/
private void addOrUpdateField(K key, Field field, Object value) {
Schema schema = field.schema();
Type type = schema.getType();
switch (type) {
case STRING:
case BOOLEAN:
case INT:
case LONG:
case BYTES:
case FLOAT:
case DOUBLE:
case FIXED:
this.cassandraClient.addColumn(key, field.name(), value);
break;
case RECORD:
if (value != null) {
if (value instanceof PersistentBase) {
PersistentBase persistentBase = (PersistentBase) value;
for (Field member: schema.getFields()) {
// TODO: hack, do not store empty arrays
Object memberValue = persistentBase.get(member.pos());
if (memberValue instanceof GenericArray<?>) {
if (((GenericArray)memberValue).size() == 0) {
continue;
}
} else if (memberValue instanceof StatefulHashMap<?,?>) {
if (((StatefulHashMap)memberValue).size() == 0) {
continue;
}
}
this.cassandraClient.addSubColumn(key, field.name(), member.name(), memberValue);
}
} else {
LOG.info("Record not supported: " + value.toString());
}
}
break;
case MAP:
if (value != null) {
if (value instanceof StatefulHashMap<?, ?>) {
this.cassandraClient.addStatefulHashMap(key, field.name(), (StatefulHashMap<Utf8,Object>)value);
} else {
LOG.info("Map not supported: " + value.toString());
}
}
break;
case ARRAY:
if (value != null) {
if (value instanceof GenericArray<?>) {
this.cassandraClient.addGenericArray(key, field.name(), (GenericArray)value);
} else {
LOG.info("Array not supported: " + value.toString());
}
}
break;
default:
LOG.info("Type not considered: " + type.name());
}
}