* @param field the Avro field representing a datum
* @param value the field value
*/
private void addOrUpdateField(String key, Field field, Object value) {
Schema schema = field.schema();
Type type = schema.getType();
//LOG.info(field.name() + " " + type.name());
switch (type) {
case STRING:
this.cassandraClient.addColumn(key, field.name(), value);
break;
case INT:
this.cassandraClient.addColumn(key, field.name(), value);
break;
case LONG:
this.cassandraClient.addColumn(key, field.name(), value);
break;
case BYTES:
this.cassandraClient.addColumn(key, field.name(), value);
break;
case FLOAT:
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<?>) {
GenericArray<String> array = (GenericArray<String>) memberValue;
if (array.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<?, ?>) {
//TODO cast to stateful map and only write dirty keys
Map<Utf8, Object> map = (Map<Utf8, Object>) value;
for (Utf8 mapKey: map.keySet()) {
// TODO: hack, do not store empty arrays
Object keyValue = map.get(mapKey);
if (keyValue instanceof GenericArray<?>) {
GenericArray<String> array = (GenericArray<String>) keyValue;
if (array.size() == 0) {
continue;
}
}
this.cassandraClient.addSubColumn(key, field.name(), mapKey.toString(), keyValue);
}
} else {
LOG.info("Map not supported: " + value.toString());
}
}
break;
default:
LOG.info("Type not considered: " + type.name());
}
}