In the CSV file that I use for loading ActivePivot, I have 2 fields that need to be multiplied together to compute my record's value: price * quantity.
I am using the CSV source with topics and channels. Where can I perform this computation?
In the CSV file that I use for loading ActivePivot, I have 2 fields that need to be multiplied together to compute my record's value: price * quantity.
I am using the CSV source with topics and channels. Where can I perform this computation?
you should override the compute method of the ColumnParser, see below. In the following example we get the QuantitySold and the SellingPricePerUnit and we add the result in the Sales column, do not forget to add the Sales column in your store definition:
@Bean
@DependsOn(value="csvSource")
public CSVMessageChannelFactory csvChannelFactory() {
CSVMessageChannelFactory channelFactory = new CSVMessageChannelFactory(csvSource(), datastore);
channelFactory.setCalculatedColumns(ORDERS_TOPIC, DatastoreConfig.ORDERS, Arrays.<IColumnCalculator>asList(
//derive new fields
new ColumnParser("Sales", "double"){
@Override
public Object compute(IColumnCalculationContext context) {
Long qty = (Long) context.getValue("QuantitySold");
Double price = (Double) context.getValue("SellingPricePerUnit");
return (qty == null || price == null) ? null: qty*price;
}
}
));
return channelFactory; }