in src/main/java/com/aws/logaggregator/logparser/BaseLogParser.java [93:248]
public Row call(Row row) throws Exception {
if (initializationBean.schema == null || null == initializationBean.schema.getDeriveby()) {
return parse(row);
}
Object[] values = new Object[initializationBean.schema.getAttributes().size() + 2];
int index = 0;
for (LogSchema.Attributes attr : initializationBean.schema.getAttributes()) {
String data = "";
if ("Name".equalsIgnoreCase(initializationBean.schema.getDeriveby())) {
Object dataObj = row.getAs(attr.getName());
if (dataObj != null) {
data = String.valueOf(dataObj);
}
} else if ("Index".equalsIgnoreCase(initializationBean.schema.getDeriveby())) {
if (row.get(attr.getIndex()) != null) {
data = String.valueOf(row.get(attr.getIndex()));
}
}
index = attr.getIndex();
if ((data == null || "".equals(data.trim())) && (attr.getDefaultvalue() != null)) {
data = String.valueOf(attr.getDefaultvalue());
}
try {
switch (attr.getType().toLowerCase()) {
case "string":
if (attr.isEncryption()) {
values[index] = baseUtils.encrypt(data);
} else if (attr.isDecryption()) {
values[index] = baseUtils.decrypt(data);
} else {
values[index] = data;
}
break;
case "integer":
if (data != null && !"".equals(data.trim())) {
values[index] = Integer.valueOf(data);
} else {
values[index] = null;
}
break;
case "int":
if (data != null && !"".equals(data.trim())) {
values[index] = Integer.valueOf(data);
} else {
values[index] = null;
}
break;
case "decimal":
if (data != null && !"".equals(data.trim())) {
values[index] = baseUtils.basicDecimaltranformation(data, attr);
} else {
values[index] = null;
}
break;
case "bigdecimal":
if (data != null && !"".equals(data.trim())) {
values[index] = baseUtils.basicDecimaltranformation(data, attr);
} else {
values[index] = null;
}
break;
case "biginteger":
if (data != null && !"".equals(data.trim())) {
values[index] = new BigInteger(data);
} else {
values[index] = null;
}
break;
case "bigint":
if (data != null && !"".equals(data.trim())) {
values[index] = new BigInteger(data);
} else {
values[index] = null;
}
break;
case "double":
if (attr.getScale() > 0) {
if (data != null && !"".equals(data.trim())) {
values[index] = (Double.parseDouble(data) / Math.pow(10, attr.getScale()));
} else {
values[index] = null;
}
} else {
if (data != null && !"".equals(data.trim())) {
values[index] = Double.parseDouble(data);
} else {
values[index] = null;
}
}
break;
case "long":
if (data != null && !"".equals(data.trim())) {
values[index] = Long.valueOf(data);
} else {
values[index] = null;
}
break;
case "boolean":
if (data != null && !"".equals(data.trim())) {
values[index] = Boolean.valueOf(data);
} else {
values[index] = null;
}
break;
case "date":
if (data != null && !"".equalsIgnoreCase(data.trim())) {
values[index] = new java.sql.Date(new SimpleDateFormat(attr.getFormat()).parse(data).getTime());
} else {
values[index] = null;
}
break;
case "timestamp":
if (data != null && !"".equalsIgnoreCase(data.trim())) {
values[index] = new Timestamp(new SimpleDateFormat(attr.getFormat()).parse(data).getTime());
} else {
values[index] = null;
}
break;
default:
values[index] = data;
break;
}
} catch (Exception e) {
e.printStackTrace();
values[index] = data;
}
}
index = index + 1;
values[index] = create_timestamp;
return parse(RowFactory.create(values));
}