use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class Spoon method generateFieldMapping.
/**
* Create a new SelectValues step in between this step and the previous. If the previous fields are not there, no
* mapping can be made, same with the required fields.
*
* @param stepMeta
* The target step to map against.
*/
// retry of required fields acquisition
public void generateFieldMapping(TransMeta transMeta, StepMeta stepMeta) {
try {
if (stepMeta != null) {
StepMetaInterface smi = stepMeta.getStepMetaInterface();
RowMetaInterface targetFields = smi.getRequiredFields(transMeta);
RowMetaInterface sourceFields = transMeta.getPrevStepFields(stepMeta);
// Build the mapping: let the user decide!!
String[] source = sourceFields.getFieldNames();
for (int i = 0; i < source.length; i++) {
ValueMetaInterface v = sourceFields.getValueMeta(i);
source[i] += EnterMappingDialog.STRING_ORIGIN_SEPARATOR + v.getOrigin() + ")";
}
String[] target = targetFields.getFieldNames();
EnterMappingDialog dialog = new EnterMappingDialog(shell, source, target);
List<SourceToTargetMapping> mappings = dialog.open();
if (mappings != null) {
// OK, so we now know which field maps where.
// This allows us to generate the mapping using a
// SelectValues Step...
SelectValuesMeta svm = new SelectValuesMeta();
svm.allocate(mappings.size(), 0, 0);
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
svm.getSelectFields()[i].setName(sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
svm.getSelectFields()[i].setRename(target[mapping.getTargetPosition()]);
svm.getSelectFields()[i].setLength(-1);
svm.getSelectFields()[i].setPrecision(-1);
}
// a new comment. Sincerely yours CO ;)
// Now that we have the meta-data, create a new step info object
String stepName = stepMeta.getName() + " Mapping";
// if
stepName = transMeta.getAlternativeStepname(stepName);
// it's already there, rename it.
StepMeta newStep = new StepMeta("SelectValues", stepName, svm);
newStep.setLocation(stepMeta.getLocation().x + 20, stepMeta.getLocation().y + 20);
newStep.setDraw(true);
transMeta.addStep(newStep);
addUndoNew(transMeta, new StepMeta[] { newStep }, new int[] { transMeta.indexOfStep(newStep) });
// Redraw stuff...
refreshTree();
refreshGraph();
}
} else {
throw new KettleException("There is no target to do a field mapping against!");
}
} catch (KettleException e) {
new ErrorDialog(shell, "Error creating mapping", "There was an error when Kettle tried to generate a field mapping against the target step", e);
}
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.
the class TransMetaJsonSerializer method getBaseStepMetaFromStepMeta.
protected BaseStepMeta getBaseStepMetaFromStepMeta(StepMeta stepMeta) {
// Attempt to discover a BaseStepMeta from the given StepMeta
BaseStepMeta baseStepMeta = new BaseStepMeta();
baseStepMeta.setParentStepMeta(stepMeta);
if (stepMeta != null) {
StepMetaInterface smi = stepMeta.getStepMetaInterface();
if (smi instanceof BaseStepMeta) {
baseStepMeta = (BaseStepMeta) smi;
}
}
return baseStepMeta;
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.
the class StepExternalConsumerRowListenerTest method testStepExternalConsumerRowListener.
@Test
public void testStepExternalConsumerRowListener() throws Exception {
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
BaseStep mockStep = mock(BaseStep.class, withSettings().extraInterfaces(StepInterface.class));
StepMeta mockStepMeta = mock(StepMeta.class);
BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
StepMetaInterface stepMetaInterface = (StepMetaInterface) bsm;
when(mockStep.getStepMeta()).thenReturn(mockStepMeta);
when(mockStepMeta.getStepMetaInterface()).thenReturn(stepMetaInterface);
Trans mockTrans = mock(Trans.class);
when(mockStep.getTrans()).thenReturn(mockTrans);
IExecutionProfile executionProfile = mock(IExecutionProfile.class);
IExecutionData executionData = mock(IExecutionData.class);
when(executionProfile.getExecutionData()).thenReturn(executionData);
LineageHolder holder = new LineageHolder();
holder.setExecutionProfile(executionProfile);
TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
StepExternalConsumerRowListener listener = new StepExternalConsumerRowListener(consumer, mockStep);
RowMetaInterface rmi = mock(RowMetaInterface.class);
Object[] row = new Object[0];
listener.rowReadEvent(rmi, row);
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.
the class StepExternalResourceConsumerListenerTest method testCallStepExtensionPoint.
@Test
public void testCallStepExtensionPoint() throws Exception {
StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
stepExtensionPoint.setStepExternalResourceConsumerProvider(MetaverseTestUtils.getStepExternalResourceConsumerProvider());
StepMetaDataCombi stepCombi = mock(StepMetaDataCombi.class);
BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
stepCombi.meta = (StepMetaInterface) bsm;
stepCombi.step = mock(StepInterface.class);
stepCombi.stepMeta = mock(StepMeta.class);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
Map<Class<? extends BaseStepMeta>, Set<IStepExternalResourceConsumer>> stepConsumerMap = new StepExternalResourceConsumerProvider().getStepConsumerMap();
Set<IStepExternalResourceConsumer> consumers = new HashSet<IStepExternalResourceConsumer>();
stepConsumerMap.put(bsm.getClass(), consumers);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
consumers.add(consumer);
Trans mockTrans = mock(Trans.class);
when(stepCombi.step.getTrans()).thenReturn(mockTrans);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGenerator method generateIifStep.
/**
* This method generates a 4 steps for every IIF clause... TODO: replace with one step...
*
* @param iifField
* @param lastStep
* @param transMeta
* @return steps
*/
private StepMeta generateIifStep(SQLField iifField, TransMeta transMeta, StepMeta lastStep) {
IifFunction iif = iifField.getIif();
// The Filter condition...
//
FilterRowsMeta filterMeta = new FilterRowsMeta();
filterMeta.setCondition(iifField.getIif().getSqlCondition().getCondition());
StepMeta filterStep = new StepMeta(iifField.getExpression(), filterMeta);
filterStep.setLocation(xLocation, 50);
xLocation += 100;
filterStep.setDraw(true);
lastStep = addToTrans(filterStep, transMeta, lastStep);
// The True and false steps...
//
StepMetaInterface trueMetaInterface;
ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta();
if (iif.isTrueField()) {
CalculatorMeta trueMeta = new CalculatorMeta();
trueMetaInterface = trueMeta;
trueMeta.allocate(1);
CalculatorMetaFunction function = new CalculatorMetaFunction();
function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
function.setValueType(valueMeta.getType());
function.setValueLength(valueMeta.getLength());
function.setValuePrecision(valueMeta.getPrecision());
function.setFieldA(iif.getTrueValueString());
function.setConversionMask(valueMeta.getConversionMask());
// CHECKSTYLE:Indentation:OFF
trueMeta.getCalculation()[0] = function;
} else {
ConstantMeta trueMeta = new ConstantMeta();
trueMetaInterface = trueMeta;
trueMeta.allocate(1);
// CHECKSTYLE:Indentation:OFF
trueMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc();
trueMeta.getValue()[0] = iif.getTrueValue().toString();
trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
}
StepMeta trueStep = new StepMeta("TRUE: " + iifField.getExpression(), trueMetaInterface);
trueStep.setLocation(xLocation, 50);
trueStep.setDraw(true);
lastStep = addToTrans(trueStep, transMeta, filterStep);
StepMetaInterface falseMetaInterface;
valueMeta = iif.getFalseValue().getValueMeta();
if (iif.isFalseField()) {
CalculatorMeta falseMeta = new CalculatorMeta();
falseMetaInterface = falseMeta;
falseMeta.allocate(1);
CalculatorMetaFunction function = new CalculatorMetaFunction();
function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
function.setValueType(valueMeta.getType());
function.setValueLength(valueMeta.getLength());
function.setValuePrecision(valueMeta.getPrecision());
function.setFieldA(iif.getFalseValueString());
function.setConversionMask(valueMeta.getConversionMask());
falseMeta.getCalculation()[0] = function;
} else {
ConstantMeta falseMeta = new ConstantMeta();
falseMetaInterface = falseMeta;
falseMeta.allocate(1);
falseMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc();
falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
falseMeta.getValue()[0] = iif.getFalseValue().toString();
}
StepMeta falseStep = new StepMeta("FALSE: " + iifField.getExpression(), falseMetaInterface);
falseStep.setLocation(xLocation, 150);
xLocation += 100;
falseStep.setDraw(true);
lastStep = addToTrans(falseStep, transMeta, filterStep);
// specify true/false targets
List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams();
targetStreams.get(0).setSubject(trueStep.getName());
targetStreams.get(1).setSubject(falseStep.getName());
filterMeta.searchInfoAndTargetSteps(transMeta.getSteps());
DummyTransMeta dummyMeta = new DummyTransMeta();
StepMeta dummyStep = new StepMeta("Collect: " + iifField.getExpression(), dummyMeta);
dummyStep.setLocation(xLocation, 50);
xLocation += 100;
dummyStep.setDraw(true);
lastStep = addToTrans(dummyStep, transMeta, trueStep);
transMeta.addTransHop(new TransHopMeta(falseStep, dummyStep));
return lastStep;
}
Aggregations