Search in sources :

Example 1 with FilePlayListAll

use of org.pentaho.di.core.playlist.FilePlayListAll in project pentaho-kettle by pentaho.

the class TextFileInputTest method readWrappedInputWithoutHeaders.

@Test
public void readWrappedInputWithoutHeaders() throws Exception {
    final String content = new StringBuilder().append("r1c1").append('\n').append(";r1c2\n").append("r2c1").append('\n').append(";r2c2").toString();
    final String virtualFile = createVirtualFile("pdi-2607.txt", content);
    TextFileInputMeta meta = new TextFileInputMeta();
    meta.setLineWrapped(true);
    meta.setNrWraps(1);
    meta.setInputFields(new TextFileInputField[] { field("col1"), field("col2") });
    meta.setFileCompression("None");
    meta.setFileType("CSV");
    meta.setHeader(false);
    meta.setNrHeaderLines(-1);
    meta.setFooter(false);
    meta.setNrFooterLines(-1);
    TextFileInputData data = new TextFileInputData();
    data.setFiles(new FileInputList());
    data.getFiles().addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = Mockito.mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ";";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    List<Object[]> output = TransTestingUtil.execute(input, meta, data, 2, false);
    TransTestingUtil.assertResult(new Object[] { "r1c1", "r1c2" }, output.get(0));
    TransTestingUtil.assertResult(new Object[] { "r2c1", "r2c2" }, output.get(1));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Example 2 with FilePlayListAll

use of org.pentaho.di.core.playlist.FilePlayListAll in project pentaho-kettle by pentaho.

the class TextFileInputTest method readInputWithDefaultValues.

@Test
public void readInputWithDefaultValues() throws Exception {
    final String virtualFile = createVirtualFile("pdi-14832.txt", "1,\n");
    TextFileInputMeta meta = new TextFileInputMeta();
    TextFileInputField field2 = field("col2");
    field2.setIfNullValue("DEFAULT");
    meta.setInputFields(new TextFileInputField[] { field("col1"), field2 });
    meta.setFileCompression("None");
    meta.setFileType("CSV");
    meta.setHeader(false);
    meta.setNrHeaderLines(-1);
    meta.setFooter(false);
    meta.setNrFooterLines(-1);
    TextFileInputData data = new TextFileInputData();
    data.setFiles(new FileInputList());
    data.getFiles().addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = Mockito.mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    List<Object[]> output = TransTestingUtil.execute(input, meta, data, 1, false);
    TransTestingUtil.assertResult(new Object[] { "1", "DEFAULT" }, output.get(0));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Example 3 with FilePlayListAll

use of org.pentaho.di.core.playlist.FilePlayListAll in project pentaho-kettle by pentaho.

the class TextFileInputTest method readInputWithMissedValues.

@Test
public void readInputWithMissedValues() throws Exception {
    final String virtualFile = createVirtualFile("pdi-14172.txt", "1,1,1\n", "2,,2\n");
    TextFileInputMeta meta = new TextFileInputMeta();
    TextFileInputField field2 = field("col2");
    field2.setRepeated(true);
    meta.setInputFields(new TextFileInputField[] { field("col1"), field2, field("col3") });
    meta.setFileCompression("None");
    meta.setFileType("CSV");
    meta.setHeader(false);
    meta.setNrHeaderLines(-1);
    meta.setFooter(false);
    meta.setNrFooterLines(-1);
    TextFileInputData data = new TextFileInputData();
    data.setFiles(new FileInputList());
    data.getFiles().addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col3"));
    data.dataErrorLineHandler = Mockito.mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    List<Object[]> output = TransTestingUtil.execute(input, meta, data, 2, false);
    TransTestingUtil.assertResult(new Object[] { "1", "1", "1" }, output.get(0));
    TransTestingUtil.assertResult(new Object[] { "2", "1", "2" }, output.get(1));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Example 4 with FilePlayListAll

use of org.pentaho.di.core.playlist.FilePlayListAll in project pentaho-kettle by pentaho.

the class TextFileInputTest method createDataObject.

private TextFileInputData createDataObject(String file, String separator, String... outputFields) throws Exception {
    TextFileInputData data = new TextFileInputData();
    data.files = new FileInputList();
    data.files.addFile(KettleVFS.getFileObject(file));
    data.separator = separator;
    data.outputRowMeta = new RowMeta();
    if (outputFields != null) {
        for (String field : outputFields) {
            data.outputRowMeta.addValueMeta(new ValueMetaString(field));
        }
    }
    data.dataErrorLineHandler = mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables());
    data.filePlayList = new FilePlayListAll();
    return data;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) AbstractFileErrorHandler(org.pentaho.di.trans.step.errorhandling.AbstractFileErrorHandler) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 5 with FilePlayListAll

use of org.pentaho.di.core.playlist.FilePlayListAll in project pentaho-kettle by pentaho.

the class TextFileInputDialogTest method testMinimalWidth_PDI_14253.

@Test
public void testMinimalWidth_PDI_14253() throws Exception {
    final String virtualFile = "ram://pdi-14253.txt";
    KettleVFS.getFileObject(virtualFile).createFile();
    final String content = "r1c1,  r1c2\nr2c1  ,  r2c2  ";
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write(content.getBytes());
    OutputStream os = KettleVFS.getFileObject(virtualFile).getContent().getOutputStream();
    IOUtils.copy(new ByteArrayInputStream(bos.toByteArray()), os);
    os.close();
    TextFileInputMeta meta = new TextFileInputMeta();
    meta.content.lineWrapped = false;
    meta.inputFields = new BaseFileField[] { new BaseFileField("col1", -1, -1), new BaseFileField("col2", -1, -1) };
    meta.content.fileCompression = "None";
    meta.content.fileType = "CSV";
    meta.content.header = false;
    meta.content.nrHeaderLines = -1;
    meta.content.footer = false;
    meta.content.nrFooterLines = -1;
    TextFileInputData data = new TextFileInputData();
    data.files = new FileInputList();
    data.files.addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables() {
    });
    data.filePlayList = new FilePlayListAll();
    TextFileInputDialog dialog = new TextFileInputDialog(mock(Shell.class), meta, mock(TransMeta.class), "TFIMinimalWidthTest");
    TableView tv = mock(TableView.class);
    when(tv.nrNonEmpty()).thenReturn(0);
    // click the Minimal width button
    dialog.setMinimalWidth(tv);
    RowSet output = new BlockingRowSet(5);
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    input.setOutputRowSets(Collections.singletonList(output));
    while (input.processRow(meta, data)) {
    // wait until the step completes executing
    }
    Object[] row1 = output.getRowImmediate();
    assertRow(row1, "r1c1", "r1c2");
    Object[] row2 = output.getRowImmediate();
    assertRow(row2, "r2c1", "r2c2");
    KettleVFS.getFileObject(virtualFile).delete();
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TextFileFilterProcessor(org.pentaho.di.trans.steps.fileinput.text.TextFileFilterProcessor) RowMeta(org.pentaho.di.core.row.RowMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) TextFileFilter(org.pentaho.di.trans.steps.fileinput.text.TextFileFilter) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) TransMeta(org.pentaho.di.trans.TransMeta) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Variables(org.pentaho.di.core.variables.Variables) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) ByteArrayInputStream(java.io.ByteArrayInputStream) TextFileInput(org.pentaho.di.trans.steps.fileinput.text.TextFileInput) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) TextFileInputData(org.pentaho.di.trans.steps.fileinput.text.TextFileInputData) FileInputList(org.pentaho.di.core.fileinput.FileInputList) TableView(org.pentaho.di.ui.core.widget.TableView) Test(org.junit.Test)

Aggregations

FileInputList (org.pentaho.di.core.fileinput.FileInputList)5 FilePlayListAll (org.pentaho.di.core.playlist.FilePlayListAll)5 RowMeta (org.pentaho.di.core.row.RowMeta)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 FileErrorHandler (org.pentaho.di.trans.step.errorhandling.FileErrorHandler)5 Test (org.junit.Test)4 Variables (org.pentaho.di.core.variables.Variables)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Shell (org.eclipse.swt.widgets.Shell)1 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)1 RowSet (org.pentaho.di.core.RowSet)1 TransMeta (org.pentaho.di.trans.TransMeta)1 AbstractFileErrorHandler (org.pentaho.di.trans.step.errorhandling.AbstractFileErrorHandler)1 BaseFileField (org.pentaho.di.trans.steps.file.BaseFileField)1 TextFileFilter (org.pentaho.di.trans.steps.fileinput.text.TextFileFilter)1 TextFileFilterProcessor (org.pentaho.di.trans.steps.fileinput.text.TextFileFilterProcessor)1 TextFileInput (org.pentaho.di.trans.steps.fileinput.text.TextFileInput)1 TextFileInputData (org.pentaho.di.trans.steps.fileinput.text.TextFileInputData)1