static String[] fieldNames( CsvInputMeta csvInputMeta ) { TextFileInputField[] fields = csvInputMeta.getInputFields(); String[] fieldNames = new String[fields.length]; for ( int i = 0; i < fields.length; i++ ) { // We need to sanitize field names because existing ktr files may contain field names with leading BOM fieldNames[i] = EncodingType.removeBOMIfPresent( fields[i].getName() ); } return fieldNames; }
FieldsMapping createFieldMapping( String fileName, CsvInputMeta csvInputMeta ) throws KettleException { FieldsMapping mapping = null; if ( csvInputMeta.isHeaderPresent() ) { String[] fieldNames = readFieldNamesFromFile( fileName, csvInputMeta ); mapping = NamedFieldsMapping.mapping( fieldNames, fieldNames( csvInputMeta ) ); } else { int fieldsCount = csvInputMeta.getInputFields() == null ? 0 : csvInputMeta.getInputFields().length; mapping = UnnamedFieldsMapping.mapping( fieldsCount ); } return mapping; }
TableItem item = wFields.getNonEmpty( i ); inputMeta.getInputFields()[i] = new TextFileInputField(); inputMeta.getInputFields()[i].setName( item.getText( colnr++ ) ); inputMeta.getInputFields()[i].setType( ValueMetaFactory.getIdForValueMeta( item.getText( colnr++ ) ) ); inputMeta.getInputFields()[i].setFormat( item.getText( colnr++ ) ); inputMeta.getInputFields()[i].setLength( Const.toInt( item.getText( colnr++ ), -1 ) ); inputMeta.getInputFields()[i].setPrecision( Const.toInt( item.getText( colnr++ ), -1 ) ); inputMeta.getInputFields()[i].setCurrencySymbol( item.getText( colnr++ ) ); inputMeta.getInputFields()[i].setDecimalSymbol( item.getText( colnr++ ) ); inputMeta.getInputFields()[i].setGroupSymbol( item.getText( colnr++ ) ); inputMeta.getInputFields()[i].setTrimType( ValueMetaString.getTrimTypeByDesc( item.getText( colnr++ ) ) );
@Test public void testClone() { final CsvInputMeta original = new CsvInputMeta(); original.setDelimiter( ";" ); original.setEnclosure( "'" ); final TextFileInputField[] originalFields = new TextFileInputField[ 1 ]; final TextFileInputField originalField = new TextFileInputField(); originalField.setName( "field" ); originalFields[ 0 ] = originalField; original.setInputFields( originalFields ); final CsvInputMeta clone = (CsvInputMeta) original.clone(); // verify that the clone and its input fields are "equal" to the originals, but not the same objects Assert.assertNotSame( original, clone ); Assert.assertEquals( original.getDelimiter(), clone.getDelimiter() ); Assert.assertEquals( original.getEnclosure(), clone.getEnclosure() ); Assert.assertNotSame( original.getInputFields(), clone.getInputFields() ); Assert.assertNotSame( original.getInputFields()[ 0 ], clone.getInputFields()[ 0 ] ); Assert.assertEquals( original.getInputFields()[ 0 ].getName(), clone.getInputFields()[ 0 ].getName() ); } }
data.filenameFieldIndex = meta.getInputFields().length; data.rownumFieldIndex = meta.getInputFields().length; if ( data.filenameFieldIndex >= 0 ) { data.rownumFieldIndex++;
for ( int i = 0; i < inputMeta.getInputFields().length; i++ ) { TextFileInputField field = inputMeta.getInputFields()[i]; final TableItem item = getTableItem( field.getName() );
return; if ( Utils.isEmpty( meta.getInputFields() ) ) { return;
protected void doInputWiring( Query query, TransMeta transMeta ) { // // CSV FILE LOCATION AND FIELDS // InlineEtlPhysicalModel physicalModel = (InlineEtlPhysicalModel) query.getLogicalModel().getPhysicalModel(); CsvInputMeta csvinput = (CsvInputMeta) getStepMeta( transMeta, "CSV file input" ).getStepMetaInterface(); //$NON-NLS-1$ // the file name might need to be translated to the correct location here if ( csvFileLoc != null ) { csvinput.setFilename( csvFileLoc + physicalModel.getFileLocation() ); } else { csvinput.setFilename( physicalModel.getFileLocation() ); } csvinput.setDelimiter( physicalModel.getDelimiter() ); csvinput.setEnclosure( physicalModel.getEnclosure() ); csvinput.setHeaderPresent( physicalModel.getHeaderPresent() ); // update fields LogicalTable table = query.getLogicalModel().getLogicalTables().get( 0 ); csvinput.allocate( table.getLogicalColumns().size() ); for ( int i = 0; i < csvinput.getInputFields().length; i++ ) { // Update csv input LogicalColumn col = table.getLogicalColumns().get( i ); csvinput.getInputFields()[i] = new TextFileInputField(); String fieldName = (String) col.getProperty( InlineEtlPhysicalColumn.FIELD_NAME ); if ( logger.isDebugEnabled() ) { logger.debug( "FROM CSV: " + fieldName ); //$NON-NLS-1$ } csvinput.getInputFields()[i].setName( fieldName ); csvinput.getInputFields()[i].setType( convertType( col.getDataType() ) ); } }