Search in sources :

Example 1 with FilePlayListAll

use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.

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(HopVfs.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = Mockito.mock(IFileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
    List<Object[]> output = PipelineTestingUtil.execute(input, 1, false);
    PipelineTestingUtil.assertResult(new Object[] { "1", "DEFAULT" }, output.get(0));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) FilePlayListAll(org.apache.hop.core.playlist.FilePlayListAll) TextFileInputField(org.apache.hop.core.file.TextFileInputField) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) IFileErrorHandler(org.apache.hop.pipeline.transform.errorhandling.IFileErrorHandler) FileInputList(org.apache.hop.core.fileinput.FileInputList) Test(org.junit.Test)

Example 2 with FilePlayListAll

use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.

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(HopVfs.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(IFileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
    List<Object[]> output = PipelineTestingUtil.execute(input, 2, false);
    PipelineTestingUtil.assertResult(new Object[] { "1", "1", "1" }, output.get(0));
    PipelineTestingUtil.assertResult(new Object[] { "2", "1", "2" }, output.get(1));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) FilePlayListAll(org.apache.hop.core.playlist.FilePlayListAll) TextFileInputField(org.apache.hop.core.file.TextFileInputField) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) IFileErrorHandler(org.apache.hop.pipeline.transform.errorhandling.IFileErrorHandler) FileInputList(org.apache.hop.core.fileinput.FileInputList) Test(org.junit.Test)

Example 3 with FilePlayListAll

use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.

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(HopVfs.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(IFileErrorHandler.class);
    data.fileFormatType = TextFileLineUtil.FILE_FORMAT_UNIX;
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables());
    data.filePlayList = new FilePlayListAll();
    return data;
}
Also used : IFileErrorHandler(org.apache.hop.pipeline.transform.errorhandling.IFileErrorHandler) Variables(org.apache.hop.core.variables.Variables) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) FilePlayListAll(org.apache.hop.core.playlist.FilePlayListAll) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) FileInputList(org.apache.hop.core.fileinput.FileInputList)

Example 4 with FilePlayListAll

use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.

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(HopVfs.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = Mockito.mock(IFileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ";";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
    List<Object[]> output = PipelineTestingUtil.execute(input, 2, false);
    PipelineTestingUtil.assertResult(new Object[] { "r1c1", "r1c2" }, output.get(0));
    PipelineTestingUtil.assertResult(new Object[] { "r2c1", "r2c2" }, output.get(1));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) FilePlayListAll(org.apache.hop.core.playlist.FilePlayListAll) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) IFileErrorHandler(org.apache.hop.pipeline.transform.errorhandling.IFileErrorHandler) FileInputList(org.apache.hop.core.fileinput.FileInputList) Test(org.junit.Test)

Aggregations

FileInputList (org.apache.hop.core.fileinput.FileInputList)4 FilePlayListAll (org.apache.hop.core.playlist.FilePlayListAll)4 IRowMeta (org.apache.hop.core.row.IRowMeta)4 RowMeta (org.apache.hop.core.row.RowMeta)4 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)4 IFileErrorHandler (org.apache.hop.pipeline.transform.errorhandling.IFileErrorHandler)4 Test (org.junit.Test)3 TextFileInputField (org.apache.hop.core.file.TextFileInputField)2 Variables (org.apache.hop.core.variables.Variables)1