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);
}
}
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;
}
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" } });
}
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" } });
}
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();
}
Aggregations