use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class RedisPOJOOutputOperator method convertObjectToMap.
private Map<String, String> convertObjectToMap(Object tuple) {
Map<String, String> mappedObject = new HashMap<String, String>();
for (int i = 0; i < dataColumns.size(); i++) {
final SupportType type = dataColumns.get(i).getType();
final String columnName = dataColumns.get(i).getColumnName();
if (i < getters.size()) {
Getter<Object, Object> obj = (Getter<Object, Object>) (getters.get(i));
Object value = obj.get(tuple);
mappedObject.put(columnName, value.toString());
}
}
return mappedObject;
}
use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class AvroToPojo method getPOJOFromGenericRecord.
/**
* Returns a POJO from a Generic Record
*
* @return Object
*/
@SuppressWarnings("unchecked")
private Object getPOJOFromGenericRecord(GenericRecord tuple) throws InstantiationException, IllegalAccessException {
Object newObj = getPojoClass().newInstance();
try {
for (int i = 0; i < columnFieldSetters.size(); i++) {
AvroToPojo.ActiveFieldInfo afi = columnFieldSetters.get(i);
SupportType st = afi.fieldInfo.getType();
Object val = null;
try {
val = tuple.get(afi.fieldInfo.getColumnName());
} catch (Exception e) {
LOG.error("Could not find field -" + afi.fieldInfo.getColumnName() + "- in the generic record", e);
val = null;
fieldErrorCount++;
}
if (val == null) {
continue;
}
try {
switch(st) {
case BOOLEAN:
((PojoUtils.SetterBoolean<Object>) afi.setterOrGetter).set(newObj, (boolean) tuple.get(afi.fieldInfo.getColumnName()));
break;
case DOUBLE:
((PojoUtils.SetterDouble<Object>) afi.setterOrGetter).set(newObj, (double) tuple.get(afi.fieldInfo.getColumnName()));
break;
case FLOAT:
((PojoUtils.SetterFloat<Object>) afi.setterOrGetter).set(newObj, (float) tuple.get(afi.fieldInfo.getColumnName()));
break;
case INTEGER:
((PojoUtils.SetterInt<Object>) afi.setterOrGetter).set(newObj, (int) tuple.get(afi.fieldInfo.getColumnName()));
break;
case STRING:
((PojoUtils.Setter<Object, String>) afi.setterOrGetter).set(newObj, new String(tuple.get(afi.fieldInfo.getColumnName()).toString()));
break;
case LONG:
((PojoUtils.SetterLong<Object>) afi.setterOrGetter).set(newObj, (long) tuple.get(afi.fieldInfo.getColumnName()));
break;
default:
throw new AvroRuntimeException("Invalid Support Type");
}
} catch (AvroRuntimeException e) {
LOG.error("Exception in setting value", e);
fieldErrorCount++;
}
}
} catch (Exception ex) {
LOG.error("Generic Exception in setting value" + ex.getMessage());
errorCount++;
newObj = null;
}
return newObj;
}
use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class RedisPOJOInputOperator method processFirstTuple.
public void processFirstTuple(Map<String, String> value) throws ClassNotFoundException {
objectClass = Class.forName(getOutputClass());
final int size = dataColumns.size();
for (int i = 0; i < size; i++) {
final SupportType type = dataColumns.get(i).getType();
final String getterExpression = dataColumns.get(i).getPojoFieldExpression();
final Object setter;
switch(type) {
case STRING:
setter = PojoUtils.createSetter(objectClass, getterExpression, String.class);
break;
case BOOLEAN:
setter = PojoUtils.createSetterBoolean(objectClass, getterExpression);
break;
case SHORT:
setter = PojoUtils.createSetterShort(objectClass, getterExpression);
break;
case INTEGER:
setter = PojoUtils.createSetterInt(objectClass, getterExpression);
break;
case LONG:
setter = PojoUtils.createSetterLong(objectClass, getterExpression);
break;
case FLOAT:
setter = PojoUtils.createSetterFloat(objectClass, getterExpression);
break;
case DOUBLE:
setter = PojoUtils.createSetterDouble(objectClass, getterExpression);
break;
default:
setter = PojoUtils.createSetter(objectClass, getterExpression, Object.class);
break;
}
setters.add(setter);
}
}
Aggregations