Search in sources :

Example 41 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class JobHistoryDelegate method displayHistoryData.

private void displayHistoryData(final int index) {
    JobHistoryLogTab model = models[index];
    ColumnInfo[] colinf = model.logDisplayTableView.getColumns();
    // 
    if (model.logDisplayTableView == null || model.logDisplayTableView.isDisposed()) {
        return;
    }
    int selectionIndex = model.logDisplayTableView.getSelectionIndex();
    model.logDisplayTableView.table.clearAll();
    List<Object[]> rows = model.rows;
    if (rows != null && rows.size() > 0) {
        // 
        for (Object[] rowData : rows) {
            TableItem item = new TableItem(model.logDisplayTableView.table, SWT.NONE);
            for (int c = 0; c < colinf.length; c++) {
                ColumnInfo column = colinf[c];
                ValueMetaInterface valueMeta = column.getValueMeta();
                String string = null;
                try {
                    string = valueMeta.getString(rowData[c]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                item.setText(c + 1, Const.NVL(string, ""));
            }
            // Add some color
            // 
            Long errors = null;
            LogStatus status = null;
            LogTableField errorsField = model.logTable.getErrorsField();
            if (errorsField != null) {
                int index1 = model.logTableFields.indexOf(errorsField);
                try {
                    errors = colinf[index1].getValueMeta().getInteger(rowData[index1]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
            }
            LogTableField statusField = model.logTable.getStatusField();
            if (statusField != null) {
                int index1 = model.logTableFields.indexOf(statusField);
                String statusString = null;
                try {
                    statusString = colinf[index1].getValueMeta().getString(rowData[index1]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                if (statusString != null) {
                    status = LogStatus.findStatus(statusString);
                }
            }
            if (errors != null && errors > 0L) {
                item.setBackground(GUIResource.getInstance().getColorRed());
            } else if (status != null && LogStatus.STOP.equals(status)) {
                item.setBackground(GUIResource.getInstance().getColorYellow());
            }
        }
        model.logDisplayTableView.removeEmptyRows();
        model.logDisplayTableView.setRowNums();
        model.logDisplayTableView.optWidth(true);
    } else {
        model.logDisplayTableView.clearAll(false);
    // new TableItem(wFields.get(tabIndex).table, SWT.NONE); // Give it an item to prevent errors on various
    // platforms.
    }
    if (selectionIndex >= 0 && selectionIndex < model.logDisplayTableView.getItemCount()) {
        model.logDisplayTableView.table.select(selectionIndex);
        showLogEntry();
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) LogStatus(org.pentaho.di.core.logging.LogStatus) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 42 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class TransDataLineage method calculateLineage.

/**
 * Using the transformation, we will calculate the data lineage for each field in each step.
 *
 * @throws KettleStepException
 *           In case there is an exception calculating the lineage. This is usually caused by unavailable data sources
 *           etc.
 */
public void calculateLineage() throws KettleStepException {
    // After sorting the steps we get a map of all the previous steps of a certain step.
    // 
    final Map<StepMeta, Map<StepMeta, Boolean>> stepMap = transMeta.sortStepsNatural();
    // However, the we need a sorted list of previous steps per step, not a map.
    // So lets sort the maps, turn them into lists...
    // 
    Map<StepMeta, List<StepMeta>> previousStepListMap = new HashMap<StepMeta, List<StepMeta>>();
    for (StepMeta stepMeta : stepMap.keySet()) {
        List<StepMeta> previousSteps = new ArrayList<StepMeta>();
        previousStepListMap.put(stepMeta, previousSteps);
        previousSteps.addAll(stepMap.get(stepMeta).keySet());
        // Sort this list...
        // 
        Collections.sort(previousSteps, new Comparator<StepMeta>() {

            public int compare(StepMeta o1, StepMeta o2) {
                Map<StepMeta, Boolean> beforeMap = stepMap.get(o1);
                if (beforeMap != null) {
                    if (beforeMap.get(o2) == null) {
                        return -1;
                    } else {
                        return 1;
                    }
                } else {
                    return o1.getName().compareToIgnoreCase(o2.getName());
                }
            }
        });
        System.out.println("Step considered: " + stepMeta.getName());
        for (StepMeta prev : previousSteps) {
            System.out.println("      --> previous step: " + prev.getName());
        }
    }
    fieldStepsMap = new HashMap<ValueMetaInterface, List<StepMeta>>();
    List<StepMeta> usedSteps = transMeta.getUsedSteps();
    for (StepMeta stepMeta : usedSteps) {
        calculateLineage(stepMeta);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) Map(java.util.Map) HashMap(java.util.HashMap) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 43 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class GetXMLDataStepAnalyzerTest method testGetInputRowMetaInterfaces_isNotInField.

@Test
public void testGetInputRowMetaInterfaces_isNotInField() throws Exception {
    Map<String, RowMetaInterface> inputs = new HashMap<>();
    RowMetaInterface inputRmi = mock(RowMetaInterface.class);
    List<ValueMetaInterface> vmis = new ArrayList<>();
    ValueMetaInterface vmi = new ValueMeta("filename");
    vmis.add(vmi);
    when(inputRmi.getValueMetaList()).thenReturn(vmis);
    inputs.put("test", inputRmi);
    doReturn(inputs).when(analyzer).getInputFields(meta);
    when(parentTransMeta.getPrevStepNames(parentStepMeta)).thenReturn(null);
    RowMetaInterface rowMetaInterface = new RowMeta();
    rowMetaInterface.addValueMeta(vmi);
    ValueMetaInterface vmi2 = new ValueMeta("otherField");
    rowMetaInterface.addValueMeta(vmi2);
    doReturn(rowMetaInterface).when(analyzer).getOutputFields(meta);
    when(meta.isInFields()).thenReturn(false);
    when(meta.getIsAFile()).thenReturn(false);
    when(meta.isReadUrl()).thenReturn(false);
    Map<String, RowMetaInterface> rowMetaInterfaces = analyzer.getInputRowMetaInterfaces(meta);
    assertNotNull(rowMetaInterfaces);
    assertEquals(2, rowMetaInterfaces.size());
    RowMetaInterface metaInterface = rowMetaInterfaces.get(ExternalResourceStepAnalyzer.RESOURCE);
    // the row meta interface should only have 1 value meta in it, and it should NOT be filename
    assertEquals(1, metaInterface.size());
    assertEquals("otherField", metaInterface.getFieldNames()[0]);
}
Also used : HashMap(java.util.HashMap) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 44 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class GetXMLDataTest method createResultRowMetaInterface.

public RowMetaInterface createResultRowMetaInterface() {
    RowMetaInterface rm = new RowMeta();
    ValueMetaInterface[] valuesMeta = { new ValueMeta("field1", ValueMeta.TYPE_STRING), new ValueMeta("objectid", ValueMeta.TYPE_STRING), new ValueMeta("sapident", ValueMeta.TYPE_STRING), new ValueMeta("quantity", ValueMeta.TYPE_STRING), new ValueMeta("merkmalname", ValueMeta.TYPE_STRING), new ValueMeta("merkmalswert", ValueMeta.TYPE_STRING) };
    for (int i = 0; i < valuesMeta.length; i++) {
        rm.addValueMeta(valuesMeta[i]);
    }
    return rm;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 45 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class XMLOutputMetaTest method testGetRequiredFields.

@Test
public void testGetRequiredFields() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    XMLField xmlField = new XMLField();
    xmlField.setFieldName("aField");
    xmlField.setType(1);
    xmlField.setLength(10);
    xmlField.setPrecision(3);
    XMLField xmlField2 = new XMLField();
    xmlField2.setFieldName("bField");
    xmlField2.setType(3);
    xmlField2.setLength(4);
    xmlField2.setPrecision(5);
    xmlOutputMeta.setOutputFields(new XMLField[] { xmlField, xmlField2 });
    RowMetaInterface requiredFields = xmlOutputMeta.getRequiredFields(new Variables());
    List<ValueMetaInterface> valueMetaList = requiredFields.getValueMetaList();
    assertEquals(2, valueMetaList.size());
    assertEquals("aField", valueMetaList.get(0).getName());
    assertEquals(1, valueMetaList.get(0).getType());
    assertEquals(10, valueMetaList.get(0).getLength());
    assertEquals(3, valueMetaList.get(0).getPrecision());
    assertEquals("bField", valueMetaList.get(1).getName());
    assertEquals(3, valueMetaList.get(1).getType());
    assertEquals(4, valueMetaList.get(1).getLength());
    assertEquals(5, valueMetaList.get(1).getPrecision());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)796 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)327 KettleException (org.pentaho.di.core.exception.KettleException)262 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)219 RowMeta (org.pentaho.di.core.row.RowMeta)208 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)130 Test (org.junit.Test)123 KettleStepException (org.pentaho.di.core.exception.KettleStepException)117 ArrayList (java.util.ArrayList)94 TableItem (org.eclipse.swt.widgets.TableItem)77 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)76 KettleValueException (org.pentaho.di.core.exception.KettleValueException)54 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)47 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)46 StepMeta (org.pentaho.di.trans.step.StepMeta)46 Database (org.pentaho.di.core.database.Database)45 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)40 FileObject (org.apache.commons.vfs2.FileObject)39 ValueMeta (org.pentaho.di.core.row.ValueMeta)39