Search in sources :

Example 11 with TextFileInputField

use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.

the class CsvInputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        // Start with a clean slate, eats the input
        rowMeta.clear();
        for (int i = 0; i < inputFields.length; i++) {
            TextFileInputField field = inputFields[i];
            ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(field.getName(), field.getType());
            valueMeta.setConversionMask(field.getFormat());
            valueMeta.setLength(field.getLength());
            valueMeta.setPrecision(field.getPrecision());
            valueMeta.setConversionMask(field.getFormat());
            valueMeta.setDecimalSymbol(field.getDecimalSymbol());
            valueMeta.setGroupingSymbol(field.getGroupSymbol());
            valueMeta.setCurrencySymbol(field.getCurrencySymbol());
            valueMeta.setTrimType(field.getTrimType());
            if (lazyConversionActive) {
                valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            }
            valueMeta.setStringEncoding(space.environmentSubstitute(encoding));
            // In case we want to convert Strings...
            // Using a copy of the valueMeta object means that the inner and outer representation format is the same.
            // Preview will show the data the same way as we read it.
            // This layout is then taken further down the road by the metadata through the transformation.
            // 
            ValueMetaInterface storageMetadata = ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING);
            storageMetadata.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
            // we don't really know the lengths of the strings read in advance.
            storageMetadata.setLength(-1, -1);
            valueMeta.setStorageMetadata(storageMetadata);
            valueMeta.setOrigin(origin);
            rowMeta.addValueMeta(valueMeta);
        }
        if (!Utils.isEmpty(filenameField) && includingFilename) {
            ValueMetaInterface filenameMeta = new ValueMetaString(filenameField);
            filenameMeta.setOrigin(origin);
            if (lazyConversionActive) {
                filenameMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
                filenameMeta.setStorageMetadata(new ValueMetaString(filenameField));
            }
            rowMeta.addValueMeta(filenameMeta);
        }
        if (!Utils.isEmpty(rowNumField)) {
            ValueMetaInterface rowNumMeta = new ValueMetaInteger(rowNumField);
            rowNumMeta.setLength(10);
            rowNumMeta.setOrigin(origin);
            rowMeta.addValueMeta(rowNumMeta);
        }
    } catch (Exception e) {
        throw new KettleStepException(e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 12 with TextFileInputField

use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.

the class TextFileInputFieldValidator method getTestObject.

@Override
public TextFileInputField getTestObject() {
    TextFileInputField rtn = new TextFileInputField(UUID.randomUUID().toString(), rand.nextInt(), rand.nextInt());
    rtn.setType(rand.nextInt(7));
    rtn.setCurrencySymbol(UUID.randomUUID().toString());
    rtn.setDecimalSymbol(UUID.randomUUID().toString());
    rtn.setFormat(UUID.randomUUID().toString());
    rtn.setGroupSymbol(UUID.randomUUID().toString());
    rtn.setIfNullValue(UUID.randomUUID().toString());
    rtn.setIgnored(rand.nextBoolean());
    rtn.setNullString(UUID.randomUUID().toString());
    rtn.setPrecision(rand.nextInt(9));
    rtn.setRepeated(rand.nextBoolean());
    rtn.setTrimType(rand.nextInt(ValueMetaString.trimTypeDesc.length));
    return rtn;
}
Also used : TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField)

Example 13 with TextFileInputField

use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.

the class CsvInputContentParsingTest method testDefaultOptions.

@Test
public void testDefaultOptions() throws Exception {
    init("default.csv");
    setFields(new TextFileInputField("Field 1", -1, -1), new TextFileInputField("Field 2", -1, -1), new TextFileInputField("Field 3", -1, -1));
    process();
    check(new Object[][] { { "first", "1", "1.1" }, { "second", "2", "2.2" }, { "third", "3", "3.3" } });
}
Also used : TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) Test(org.junit.Test)

Example 14 with TextFileInputField

use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.

the class CsvInputContentParsingTest method testMultiCharDelimOptions.

@Test
public void testMultiCharDelimOptions() throws Exception {
    meta.setDelimiter("|||");
    init("multi_delim.csv");
    setFields(new TextFileInputField("Field 1", -1, -1), new TextFileInputField("Field 2", -1, -1), new TextFileInputField("Field 3", -1, -1));
    process();
    check(new Object[][] { { "first", "1", "1.1" }, { "second", "2", "2.2" }, { "third", "3", "3.3" }, { "\u043d\u0435-\u043b\u0430\u0446\u0456\u043d\u043a\u0430(non-latin)", "4", "4" } });
}
Also used : TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) Test(org.junit.Test)

Example 15 with TextFileInputField

use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.

the class CsvInputContentParsingTest method testNoHeaderOptions.

@Test(expected = KettleStepException.class)
public void testNoHeaderOptions() throws Exception {
    meta.setHeaderPresent(false);
    init("default.csv");
    setFields(new TextFileInputField(), new TextFileInputField(), new TextFileInputField());
    process();
}
Also used : TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) Test(org.junit.Test)

Aggregations

TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)47 KettleException (org.pentaho.di.core.exception.KettleException)13 KettleStepException (org.pentaho.di.core.exception.KettleStepException)11 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)11 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 TableItem (org.eclipse.swt.widgets.TableItem)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 S3ServiceException (org.jets3t.service.S3ServiceException)3 Node (org.w3c.dom.Node)3 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 TextFileInputFieldInterface (org.pentaho.di.core.gui.TextFileInputFieldInterface)2 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1