Search in sources :

Example 1 with DataGridMeta

use of org.pentaho.di.trans.steps.datagrid.DataGridMeta in project pentaho-kettle by pentaho.

the class TransMetaTest method testGetPrevInfoFields.

@Test
public void testGetPrevInfoFields() throws KettleStepException {
    DataGridMeta dgm1 = new DataGridMeta();
    dgm1.setFieldName(new String[] { "id", "colA" });
    dgm1.allocate(2);
    dgm1.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_INTEGER), ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING) });
    List<List<String>> dgm1Data = new ArrayList<>();
    dgm1Data.add(Arrays.asList("1", "A"));
    dgm1Data.add(Arrays.asList("2", "B"));
    dgm1.setDataLines(dgm1Data);
    DataGridMeta dgm2 = new DataGridMeta();
    dgm2.allocate(1);
    dgm2.setFieldName(new String[] { "moreData" });
    dgm2.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING) });
    List<List<String>> dgm2Data = new ArrayList<>();
    dgm2Data.add(Arrays.asList("Some Informational Data"));
    dgm2.setDataLines(dgm2Data);
    StepMeta dg1 = new StepMeta("input1", dgm1);
    StepMeta dg2 = new StepMeta("input2", dgm2);
    final String UDJC_METHOD = "public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { return false; }";
    UserDefinedJavaClassMeta udjcMeta = new UserDefinedJavaClassMeta();
    udjcMeta.getInfoStepDefinitions().add(new StepDefinition(dg2.getName(), dg2.getName(), dg2, "info_data"));
    udjcMeta.replaceDefinitions(Collections.singletonList(new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "MainClass", UDJC_METHOD)));
    StepMeta udjc = new StepMeta("PDI-14910", udjcMeta);
    TransHopMeta hop1 = new TransHopMeta(dg1, udjc, true);
    TransHopMeta hop2 = new TransHopMeta(dg2, udjc, true);
    transMeta.addStep(dg1);
    transMeta.addStep(dg2);
    transMeta.addStep(udjc);
    transMeta.addTransHop(hop1);
    transMeta.addTransHop(hop2);
    RowMetaInterface row = null;
    row = transMeta.getPrevInfoFields(udjc);
    assertNotNull(row);
    assertEquals(1, row.size());
    assertEquals("moreData", row.getValueMeta(0).getName());
    assertEquals(ValueMetaInterface.TYPE_STRING, row.getValueMeta(0).getType());
}
Also used : ArrayList(java.util.ArrayList) StepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) UserDefinedJavaClassMeta(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta) UserDefinedJavaClassDef(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 2 with DataGridMeta

use of org.pentaho.di.trans.steps.datagrid.DataGridMeta in project pentaho-kettle by pentaho.

the class TransMetaTest method testGetPrevStepFields.

@Test
public void testGetPrevStepFields() throws KettleStepException {
    DataGridMeta dgm = new DataGridMeta();
    dgm.allocate(2);
    dgm.setFieldName(new String[] { "id" });
    dgm.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_INTEGER) });
    List<List<String>> dgm1Data = new ArrayList<>();
    dgm1Data.add(Collections.singletonList("1"));
    dgm1Data.add(Collections.singletonList("2"));
    dgm.setDataLines(dgm1Data);
    StepMeta dg = new StepMeta("input1", dgm);
    TextFileOutputMeta textFileOutputMeta = new TextFileOutputMeta();
    StepMeta textFileOutputStep = new StepMeta("BACKLOG-21039", textFileOutputMeta);
    TransHopMeta hop = new TransHopMeta(dg, textFileOutputStep, true);
    transMeta.addStep(dg);
    transMeta.addStep(textFileOutputStep);
    transMeta.addTransHop(hop);
    RowMetaInterface row = transMeta.getPrevStepFields(textFileOutputStep);
    assertNotNull(row);
    assertEquals(1, row.size());
    assertEquals("id", row.getValueMeta(0).getName());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, row.getValueMeta(0).getType());
    dgm.setFieldName(new String[] { "id", "name" });
    dgm.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_INTEGER), ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING) });
    row = transMeta.getPrevStepFields(textFileOutputStep);
    assertNotNull(row);
    assertEquals(2, row.size());
    assertEquals("id", row.getValueMeta(0).getName());
    assertEquals("name", row.getValueMeta(1).getName());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, row.getValueMeta(0).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, row.getValueMeta(1).getType());
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 3 with DataGridMeta

use of org.pentaho.di.trans.steps.datagrid.DataGridMeta in project pentaho-kettle by pentaho.

the class DataGridDialog method preview.

/**
 * Preview the data generated by this step. This generates a transformation using this step & a dummy and previews it.
 */
private void preview() {
    // Create the table input reader step...
    DataGridMeta oneMeta = new DataGridMeta();
    getInfo(oneMeta);
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "DataGridDialog.EnterPreviewSize.Title"), BaseMessages.getString(PKG, "DataGridDialog.EnterPreviewSize.Message"));
    int previewSize = numberDialog.open();
    if (previewSize > 0) {
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
        progressDialog.open();
        Trans trans = progressDialog.getTrans();
        String loggingText = progressDialog.getLoggingText();
        if (!progressDialog.isCancelled()) {
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            }
        }
        PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
        prd.open();
    }
}
Also used : TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans) Point(org.eclipse.swt.graphics.Point)

Example 4 with DataGridMeta

use of org.pentaho.di.trans.steps.datagrid.DataGridMeta in project pentaho-kettle by pentaho.

the class PentahoReportingOutputIT method runTransformation.

private void runTransformation(PentahoReportingOutputMeta.ProcessorType processorType) throws Exception {
    File tmp = File.createTempFile("PentahoReportingOutputTest", "PentahoReportingOutputTest");
    tmp.deleteOnExit();
    StepMeta outputStep = transMeta.findStep("Data Grid");
    DataGridMeta metaGrid = (DataGridMeta) outputStep.getStepMetaInterface();
    metaGrid.getDataLines().clear();
    metaGrid.getDataLines().add(asList("src/it/resources/org/pentaho/di/trans/steps/pentahoreporting/pdi-13434.prpt", tmp.getAbsolutePath()));
    StepMeta reportingStep = transMeta.findStep("Pentaho Reporting Output");
    PentahoReportingOutputMeta reportingMeta = (PentahoReportingOutputMeta) reportingStep.getStepMetaInterface();
    reportingMeta.setOutputProcessorType(processorType);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    trans.startThreads();
    trans.waitUntilFinished();
    Assert.assertEquals(0, trans.getErrors());
    Assert.assertTrue(tmp.length() > 0);
    tmp.delete();
}
Also used : DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) File(java.io.File) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

Aggregations

DataGridMeta (org.pentaho.di.trans.steps.datagrid.DataGridMeta)4 StepMeta (org.pentaho.di.trans.step.StepMeta)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 Trans (org.pentaho.di.trans.Trans)2 NodeList (org.w3c.dom.NodeList)2 File (java.io.File)1 Point (org.eclipse.swt.graphics.Point)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 TransMeta (org.pentaho.di.trans.TransMeta)1 TextFileOutputMeta (org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta)1 StepDefinition (org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition)1 UserDefinedJavaClassDef (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef)1 UserDefinedJavaClassMeta (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta)1 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)1 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)1