Some day I may take the time to turn this into a full fledged how to, but until then, it is a dumping ground of tips and stuff I have learned.
<?xml version="1.0" encoding="UTF-8"?> <plugin id="ESRIGeocoderPlugin" iconfile="globe32.png" description="ESRI Online Geocoder Plugin" tooltip="Use this step to geocode addresses using ESRI's online geocoder" category="Transform" classname="net.timbert.geocoder.kettle.ESRIGeocoderPluginMeta"> <libraries> <library name="ESRIGeocoderPlugin.jar"/> <!-- this is the jar that contains the 4 classes --> <library name="ESRIGeocoder.jar"/> <!-- the rest are supporting libraries --> <library name="axis.jar"/> <library name="commons-discovery-0.2.jar"/> </libraries> <localized_category> <category locale="en_US">Transform</category> </localized_category> <localized_description> <description locale="en_US">ESRI Online Geocoder Plugin</description> </localized_description> <localized_tooltip> <tooltip locale="en_US">Use this step to geocode addresses using ESRI's online geocoder</tooltip> </localized_tooltip> </plugin>
public boolean init(StepMetaInterface smi, StepDataInterface sdi) { if (super.init(smi, sdi)) { logBasic("Initializing my plugin"); meta = (MyPluginMeta)smi; data = (MyPluginData)sdi; try { // do your init stuff here } catch (Exception e) { this.logError("Error initializing the plugin", e); return false; } return true; } return false; }
public void dispose(StepMetaInterface smi, StepDataInterface sdi) { logBasic("Disposing my plugin"); meta = (MyPluginMeta)smi; data = (MyPluginData)sdi; try { // do your disposing here } catch (Exception e) { logError("Error disposing my plugin", e); } finally{ super.dispose(smi, sdi); } }
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { data = (YourPluginClassData)sdi; data.outputRowMeta.size(); Object[] r=getRow(); }
if (first) { logRowlevel("Processing first row"); first = false; data.outputRowMeta = (RowMetaInterface)getInputRowMeta().clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this); }
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) throws KettleStepException { // add in dynamic fields if (some condition) { addOutputField(r, origin, "fieldA", ValueMetaInterface.TYPE_NUMBER, 18, 15, new Double(0), "###.###############"); } else { addOutputField(r, origin, "fieldB", ValueMetaInterface.TYPE_STRING, 25, 0, "", null); } } private void addOutputField(RowMetaInterface r, String origin, String fieldName, int fieldType, int length, int precision, Object defaultValue, String conversionMask) { ValueMetaAndData newField; ValueMetaInterface v; newField = new ValueMetaAndData(new ValueMeta(fieldName, fieldType), defaultValue); newField.getValueMeta().setLength(length); newField.getValueMeta().setPrecision(precision); if (conversionMask != null) { newField.getValueMeta().setConversionMask(conversionMask); } v = newField.getValueMeta(); v.setOrigin(origin); r.addValueMeta(v); }
If you have a component where you let the user select steps to send data to i.e. true/false filter style, you can make the hops appear in red/green. Do the following:
public boolean chosesTargetSteps() { if (getTrueStep() == null || "".equals(getTrueStep())) { return false; } return true; } public String[] getTargetSteps() { if (chosesTargetSteps()) { return new String[] { getTrueStep(), getFalseStep() }; } return null; }