use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class FilterRowsMetaTest method testClone.
@Test
public void testClone() {
FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
filterRowsMeta.setCondition(new Condition());
filterRowsMeta.setTrueStepname("true");
filterRowsMeta.setFalseStepname("false");
FilterRowsMeta clone = (FilterRowsMeta) filterRowsMeta.clone();
assertNotNull(clone.getCondition());
assertEquals("true", clone.getTrueStepname());
assertEquals("false", clone.getFalseStepname());
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class FilterRowsIT method testFilterConditionRefersToNonExistingFields.
@Test
public void testFilterConditionRefersToNonExistingFields() throws Exception {
KettleEnvironment.init();
// Create a new transformation...
TransMeta transMeta = new TransMeta();
transMeta.setName("filterrowstest");
PluginRegistry registry = PluginRegistry.getInstance();
// create an injector step...
String injectorStepname = "injector step";
InjectorMeta im = new InjectorMeta();
// Set the information of the injector.
String injectorPid = registry.getPluginId(StepPluginType.class, im);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
transMeta.addStep(injectorStep);
// Create a filter rows step
String filterStepName = "filter rows step";
FilterRowsMeta frm = new FilterRowsMeta();
Condition condition = new Condition();
String nonExistingFieldName = "non-existing-field";
condition.setLeftValuename(nonExistingFieldName);
// IS NOT
condition.setFunction(8);
condition.setRightValuename(null);
condition.setOperator(0);
frm.setCondition(condition);
String filterRowsStepPid = registry.getPluginId(StepPluginType.class, frm);
StepMeta filterRowsStep = new StepMeta(filterRowsStepPid, filterStepName, frm);
transMeta.addStep(filterRowsStep);
TransHopMeta hi = new TransHopMeta(injectorStep, filterRowsStep);
transMeta.addTransHop(hi);
// Now execute the transformation
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
// add rows
List<RowMetaAndData> inputList = createIntegerData();
for (RowMetaAndData rm : inputList) {
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.startThreads();
trans.waitUntilFinished();
// expect errors
assertEquals(1, trans.getErrors());
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class TransDebugDialog method showStepDebugInformation.
private void showStepDebugInformation() {
//
for (Control control : wComposite.getChildren()) {
control.dispose();
}
wComposite.layout(true, true);
int[] selectionIndices = wSteps.table.getSelectionIndices();
if (selectionIndices == null || selectionIndices.length != 1) {
return;
}
previousIndex = selectionIndices[0];
// What step did we click on?
//
final StepMeta stepMeta = transDebugMeta.getTransMeta().getStep(selectionIndices[0]);
// What is the step debugging metadata?
// --> This can be null (most likely scenario)
//
final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
// At the top we'll put a few common items like first[x], etc.
//
// The row count (e.g. number of rows to keep)
//
wRowCount = new LabelText(wComposite, BaseMessages.getString(PKG, "TransDebugDialog.RowCount.Label"), BaseMessages.getString(PKG, "TransDebugDialog.RowCount.ToolTip"));
FormData fdRowCount = new FormData();
fdRowCount.left = new FormAttachment(0, 0);
fdRowCount.right = new FormAttachment(100, 0);
fdRowCount.top = new FormAttachment(0, 0);
wRowCount.setLayoutData(fdRowCount);
wRowCount.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
ok(false);
}
});
// Do we retrieve the first rows passing?
//
wFirstRows = new Button(wComposite, SWT.CHECK);
props.setLook(wFirstRows);
wFirstRows.setText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.Label"));
wFirstRows.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.ToolTip"));
FormData fdFirstRows = new FormData();
fdFirstRows.left = new FormAttachment(middle, 0);
fdFirstRows.right = new FormAttachment(100, 0);
fdFirstRows.top = new FormAttachment(wRowCount, margin);
wFirstRows.setLayoutData(fdFirstRows);
// Do we pause on break point, when the condition is met?
//
wPauseBreakPoint = new Button(wComposite, SWT.CHECK);
props.setLook(wPauseBreakPoint);
wPauseBreakPoint.setText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.Label"));
wPauseBreakPoint.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.ToolTip"));
FormData fdPauseBreakPoint = new FormData();
fdPauseBreakPoint.left = new FormAttachment(middle, 0);
fdPauseBreakPoint.right = new FormAttachment(100, 0);
fdPauseBreakPoint.top = new FormAttachment(wFirstRows, margin);
wPauseBreakPoint.setLayoutData(fdPauseBreakPoint);
// The condition to pause for...
//
condition = null;
if (stepDebugMeta != null) {
condition = stepDebugMeta.getCondition();
}
if (condition == null) {
condition = new Condition();
}
// The input fields...
try {
stepInputFields = transDebugMeta.getTransMeta().getStepFields(stepMeta);
} catch (KettleStepException e) {
stepInputFields = new RowMeta();
}
wlCondition = new Label(wComposite, SWT.RIGHT);
props.setLook(wlCondition);
wlCondition.setText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.Label"));
wlCondition.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.ToolTip"));
FormData fdlCondition = new FormData();
fdlCondition.left = new FormAttachment(0, 0);
fdlCondition.right = new FormAttachment(middle, -margin);
fdlCondition.top = new FormAttachment(wPauseBreakPoint, margin);
wlCondition.setLayoutData(fdlCondition);
wCondition = new ConditionEditor(wComposite, SWT.BORDER, condition, stepInputFields);
FormData fdCondition = new FormData();
fdCondition.left = new FormAttachment(middle, 0);
fdCondition.right = new FormAttachment(100, 0);
fdCondition.top = new FormAttachment(wPauseBreakPoint, margin);
fdCondition.bottom = new FormAttachment(100, 0);
wCondition.setLayoutData(fdCondition);
getStepDebugData(stepDebugMeta);
// Add a "clear" button at the bottom on the left...
//
Button wClear = new Button(wComposite, SWT.PUSH);
props.setLook(wClear);
wClear.setText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.Label"));
wClear.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.ToolTip"));
FormData fdClear = new FormData();
fdClear.left = new FormAttachment(0, 0);
fdClear.bottom = new FormAttachment(100, 0);
wClear.setLayoutData(fdClear);
wClear.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
// Clear the preview step information for this step...
//
stepDebugMetaMap.remove(stepMeta);
wSteps.table.setSelection(new int[] {});
previousIndex = -1;
// refresh the steps list...
//
refreshStepList();
showStepDebugInformation();
}
});
wComposite.layout(true, true);
}
use of org.pentaho.di.core.Condition in project pentaho-metaverse by pentaho.
the class FilterRowsStepAnalyzer method getUsedFields.
@Override
protected Set<StepField> getUsedFields(FilterRowsMeta meta) {
// add uses links to all of the fields that are part of the filter condition
Set<StepField> usedFields = new HashSet<>();
final Condition condition = meta.getCondition();
if (condition != null) {
for (String usedField : condition.getUsedFields()) {
usedFields.addAll(createStepFields(usedField, getInputs()));
}
}
return usedFields;
}
use of org.pentaho.di.core.Condition in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGeneration method convertCondition.
protected void convertCondition(Condition condition, StringBuilder builder, RowMeta paramsMeta, List<Object> params) throws PushDownOptimizationException {
// Condition is composite: Recursively add children
if (condition.isNegated()) {
builder.append("NOT ");
}
if (condition.isComposite()) {
builder.append("( ");
for (Condition child : condition.getChildren()) {
if (child.getOperator() == Condition.OPERATOR_AND) {
builder.append(" AND ");
} else if (child.getOperator() == Condition.OPERATOR_OR) {
builder.append(" OR ");
}
convertCondition(child, builder, paramsMeta, params);
}
builder.append(" )");
} else {
builder.append(convertAtomicCondition(condition, paramsMeta, params));
}
}
Aggregations