My Lookup
Updated: Aug 12, 2023
This example shows a customizable Lookup component, allowing you to modify the default behavior of looking up data. By leveraging the given class, you can implement your own specialized data-lookup logic tailored to specific use cases and requirements.
Lookup searches for data in another source to merge with each record passing through this lookup's transformer -- the streaming version of a join.
More information about the usage of MyLookup can be found in Write My Own Lookup.
Java Code Listing
package com.northconcepts.datapipeline.examples.cookbook.customization;
import com.northconcepts.datapipeline.core.Field;
import com.northconcepts.datapipeline.core.Record;
import com.northconcepts.datapipeline.core.RecordList;
import com.northconcepts.datapipeline.transform.lookup.Lookup;
public class MyLookup extends Lookup {
public RecordList get(Object ... keys) {
if (keys == null || keys.length != 1) {
return null;
}
Record record = new Record();
Field ratingClass = record.addField().setName("ratingClass");
char rating = keys[0].toString().charAt(0);
switch (rating) {
case 'A': ratingClass.setValue("Class A"); break;
case 'B': ratingClass.setValue("Class B"); break;
case 'C': ratingClass.setValue("Class C"); break;
default: return null;
}
RecordList list = new RecordList();
list.add(record);
return list;
}
}
Code Walkthrough
- This class extends the abstract class Lookup.
- The abstract method
get(Object... keys)should be overridden to implement custom logic for looking up data. - In the given example, the
Ratingcolumn is given as an input lookup field and based on its values, a newratingClassfield is added to each record.
