public String getString( int index, String def ) throws KettleValueException { String string = rowMeta.getString( data, index ); if ( string == null ) { return def; } return string; }
@Override public String toString() { try { return rowMeta.getString( data ); } catch ( KettleValueException e ) { return rowMeta.toString() + ", error presenting data: " + e.toString(); } }
private String getResolvedReplaceByString( int index, Object[] row ) throws KettleException { if ( data.setEmptyString[index] ) { // return empty string rather than null value return StringUtil.EMPTY_STRING; } // if there is something in the original replaceByString, then use it. if ( data.replaceFieldIndex[index] == -1 ) { return data.replaceByString[index]; } return getInputRowMeta().getString( row, data.replaceFieldIndex[index] ); }
private Object[] compareTables( RowMetaInterface rowMeta, Object[] r ) throws KettleException { try { String referenceSchema = getInputRowMeta().getString( r, data.refSchemaIndex ); String referenceTable = getInputRowMeta().getString( r, data.refTableIndex ); String compareSchema = getInputRowMeta().getString( r, data.cmpSchemaIndex ); String compareTable = getInputRowMeta().getString( r, data.cmpTableIndex ); String keyFields = getInputRowMeta().getString( r, data.keyFieldsIndex ); String excludeFields = getInputRowMeta().getString( r, data.excludeFieldsIndex ); return compareTables( rowMeta, r, referenceSchema, referenceTable, compareSchema, compareTable, keyFields, excludeFields ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "TableCompare.Exception.UnexpectedErrorComparingTables" ), e ); } }
@Override public String[] call() throws Exception { ResultSet resultSet = database.openQuery( ps, parameterMeta, parameterData ); List<Object[]> rows = database.getRows( resultSet, 0, null ); if ( Utils.isEmpty( rows ) ) { return new String[ 0 ]; } // assemble the result // RowMetaInterface rowMeta = database.getReturnRowMeta(); String[] strings = new String[ rows.size() ]; for ( int i = 0; i < strings.length; i++ ) { Object[] row = rows.get( i ); strings[ i ] = rowMeta.getString( row, 0 ); } return strings; } } );
@Override public List<RepositoryElementMetaInterface> call() throws Exception { List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>(); ResultSet rs = database.openQuery( sql, directoryIdRow.getRowMeta(), directoryIdRow.getData() ); if ( rs != null ) { List<Object[]> rows = database.getRows( rs, -1, null ); if ( rs != null ) { database.closeQuery( rs ); } RowMetaInterface rowMeta = database.getReturnRowMeta(); for ( Object[] r : rows ) { ObjectId id = new LongObjectId( rowMeta.getInteger( r, 4 ) ); repositoryObjects.add( new RepositoryObject( id, rowMeta.getString( r, 0 ), repositoryDirectory, rowMeta .getString( r, 1 ), rowMeta.getDate( r, 2 ), objectType, rowMeta.getString( r, 3 ), false ) ); } } return repositoryObjects; } } );
/** * Substitutes field values in <code>aString</code>. Field values are of the form "?{<field name>}". The values are * retrieved from the specified row. Please note that the getString() method is used to convert to a String, for all * values in the row. * * @param aString * the string on which to apply the substitution. * @param rowMeta * The row metadata to use. * @param rowData * The row data to use * * @return the string with the substitution applied. * @throws KettleValueException * In case there is a String conversion error */ public static String substituteField( String aString, RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException { Map<String, String> variables = new HashMap<String, String>(); for ( int i = 0; i < rowMeta.size(); i++ ) { variables.put( rowMeta.getValueMeta( i ).getName(), rowMeta.getString( rowData, i ) ); } return substitute( aString, variables, FIELD_OPEN, FIELD_CLOSE ); }
synchronized Object[] getOneRow( RowMetaInterface rowMeta, Object[] row ) throws KettleException { Object[] rowData = RowDataUtil.resizeArray( row, data.outputRowMeta.size() ); int index = 0; Set<Integer> numFieldsAlreadyBeenTransformed = new HashSet<Integer>(); for ( int i = 0; i < data.numFields; i++ ) { RowMetaInterface currentRowMeta = ( numFieldsAlreadyBeenTransformed.contains( data.inStreamNrs[i] ) ) ? data.outputRowMeta : getInputRowMeta(); String value = replaceString( currentRowMeta.getString( rowData, data.inStreamNrs[i] ), data.patterns[i], getResolvedReplaceByString( i, row ) ); if ( Utils.isEmpty( data.outStreamNrs[i] ) ) { // update field value rowData[data.inStreamNrs[i]] = value; numFieldsAlreadyBeenTransformed.add( data.inStreamNrs[i] ); } else { // add new field value rowData[data.inputFieldsNr + index++] = value; } } return rowData; }
private SyslogMessageTask createSyslogMessageTask() throws Exception { SyslogMessageData data = new SyslogMessageData(); RowMetaInterface inputRowMeta = mock( RowMetaInterface.class ); when( inputRowMeta.indexOfValue( any() ) ).thenReturn( 0 ); when( inputRowMeta.getString( any(), eq( 0 ) ) ).thenReturn( testMessage ); SyslogMessageTask syslogMessage = new SyslogMessageTask( stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, stepMockHelper.processRowsStepMetaInterface ); syslogMessage.init( stepMockHelper.processRowsStepMetaInterface, data ); syslogMessage.setInputRowMeta( inputRowMeta ); return syslogMessage; } }
private void getFilenamesFromPreviousSteps() throws KettleException { List<String> filenames = new ArrayList<String>(); boolean firstRow = true; int index = -1; Object[] row = getRow(); while ( row != null ) { if ( firstRow ) { firstRow = false; // Get the filename field index... // String filenameField = environmentSubstitute( meta.getFilenameField() ); index = getInputRowMeta().indexOfValue( filenameField ); if ( index < 0 ) { throw new KettleException( Messages.getString( "S3CsvInput.Exception.FilenameFieldNotFound", filenameField ) ); } } String filename = getInputRowMeta().getString( row, index ); filenames.add( filename ); // add it to the list... row = getRow(); // Grab another row... } data.filenames = filenames.toArray( new String[filenames.size()] ); logBasic( Messages.getString( "S3CsvInput.Log.ReadingFromNrFiles", Integer.toString( data.filenames.length ) ) ); }
private Object[] getOneRow( RowMetaInterface rowMeta, Object[] row ) throws KettleException { Object[] RowData = new Object[data.outputRowMeta.size()]; // Copy the input fields. System.arraycopy( row, 0, RowData, 0, rowMeta.size() ); int length = meta.getFieldInStream().length; int j = 0; // Index into "new fields" area, past the first {data.inputFieldsNr} records for ( int i = 0; i < length; i++ ) { String valueIn = getInputRowMeta().getString( row, data.inStreamNrs[i] ); String value = CutString( valueIn, data.cutFrom[i], data.cutTo[i] ); if ( Utils.isEmpty( data.outStreamNrs[i] ) ) { RowData[data.inStreamNrs[i]] = value; } else { RowData[data.inputFieldsNr + j] = value; j++; } } return RowData; }
private synchronized void deleteValues( RowMetaInterface rowMeta, Object[] row ) throws KettleException { // OK, now do the lookup. // We need the lookupvalues for that. Object[] deleteRow = new Object[data.deleteParameterRowMeta.size()]; int deleteIndex = 0; for ( int i = 0; i < meta.getKeyStream().length; i++ ) { if ( data.keynrs[i] >= 0 ) { deleteRow[deleteIndex] = row[data.keynrs[i]]; deleteIndex++; } if ( data.keynrs2[i] >= 0 ) { deleteRow[deleteIndex] = row[data.keynrs2[i]]; deleteIndex++; } } data.db.setValues( data.deleteParameterRowMeta, deleteRow, data.prepStatementDelete ); if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "Delete.Log.SetValuesForDelete", data.deleteParameterRowMeta .getString( deleteRow ), rowMeta.getString( row ) ) ); } data.db.insertRow( data.prepStatementDelete ); incrementLinesUpdated(); }
private void getFilenamesFromPreviousSteps() throws KettleException { List<String> filenames = new ArrayList<String>(); boolean firstRow = true; int index = -1; Object[] row = getRow(); while ( row != null ) { if ( firstRow ) { firstRow = false; // Get the filename field index... // String filenameField = environmentSubstitute( meta.getFilenameField() ); index = getInputRowMeta().indexOfValue( filenameField ); if ( index < 0 ) { throw new KettleException( BaseMessages.getString( PKG, "CsvInput.Exception.FilenameFieldNotFound", filenameField ) ); } } String filename = getInputRowMeta().getString( row, index ); filenames.add( filename ); // add it to the list... row = getRow(); // Grab another row... } data.filenames = filenames.toArray( new String[ filenames.size() ] ); logBasic( BaseMessages.getString( PKG, "CsvInput.Log.ReadingFromNrFiles", Integer .toString( data.filenames.length ) ) ); }
private void getFilenamesFromPreviousSteps() throws KettleException { List<String> filenames = new ArrayList<String>(); boolean firstRow = true; int index = -1; Object[] row = getRow(); while ( row != null ) { if ( firstRow ) { firstRow = false; // Get the filename field index... // String filenameField = environmentSubstitute( meta.getFilenameField() ); index = getInputRowMeta().indexOfValue( filenameField ); if ( index < 0 ) { throw new KettleException( BaseMessages.getString( PKG, "ParGzipCsvInput.Exception.FilenameFieldNotFound", filenameField ) ); } } String filename = getInputRowMeta().getString( row, index ); filenames.add( filename ); // add it to the list... row = getRow(); // Grab another row... } data.filenames = filenames.toArray( new String[filenames.size()] ); logBasic( BaseMessages.getString( PKG, "ParGzipCsvInput.Log.ReadingFromNrFiles", Integer .toString( data.filenames.length ) ) ); }
@Override public Collection<IExternalResourceInfo> getResourcesFromRow( GetXMLData textFileInput, RowMetaInterface rowMeta, Object[] row ) { Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>(); // For some reason the step doesn't return the StepMetaInterface directly, so go around it GetXMLDataMeta meta = (GetXMLDataMeta) textFileInput.getStepMetaInterface(); if ( meta == null ) { meta = (GetXMLDataMeta) textFileInput.getStepMeta().getStepMetaInterface(); } try { if ( meta.getIsAFile() ) { String filename = ( meta == null ) ? null : rowMeta.getString( row, meta.getXMLField(), null ); if ( !Utils.isEmpty( filename ) ) { FileObject fileObject = KettleVFS.getFileObject( filename ); resources.add( ExternalResourceInfoFactory.createFileResource( fileObject, true ) ); } } // TODO URLs? } catch ( KettleException kve ) { // TODO throw exception or ignore? } return resources; }
private boolean putRowOut( Object[] r ) throws KettleException { if ( log.isRowLevel() ) { logRowlevel( BaseMessages.getString( PKG, "GetXMLData.Log.ReadRow", data.outputRowMeta.getString( r ) ) ); } incrementLinesInput(); data.rownr++; putRow( data.outputRowMeta, r ); // copy row to output rowset(s); if ( meta.getRowLimit() > 0 && data.rownr > meta.getRowLimit() ) { // limit has been reached: stop now. setOutputDone(); return false; } return true; }
private synchronized boolean keepRow( RowMetaInterface rowMeta, Object[] row ) throws KettleException { try { return meta.getCondition().evaluate( rowMeta, row ); } catch ( Exception e ) { String message = BaseMessages.getString( PKG, "FilterRows.Exception.UnexpectedErrorFoundInEvaluationFuction" ); logError( message ); logError( BaseMessages.getString( PKG, "FilterRows.Log.ErrorOccurredForRow" ) + rowMeta.getString( row ) ); logError( Const.getStackTracker( e ) ); throw new KettleException( message, e ); } }
private boolean verifyOutput( Object[][] expectedRows, RowSet outputRowSet ) throws KettleValueException { if ( expectedRows.length == outputRowSet.size() ) { for ( Object[] expectedRow : expectedRows ) { Object[] row = outputRowSet.getRow(); if ( expectedRow.length == outputRowSet.getRowMeta().size() ) { for ( int j = 0; j < expectedRow.length; j++ ) { if ( !expectedRow[j].equals( outputRowSet.getRowMeta().getString( row, j ) ) ) { return false; } } return true; } } } return false; }
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { meta = (MailInputMeta) smi; data = (MailInputData) sdi; Object[] outputRowData = getOneRow(); if ( outputRowData == null ) { // no more input to be expected... setOutputDone(); return false; } if ( isRowLevel() ) { log.logRowlevel( toString(), BaseMessages.getString( PKG, "MailInput.Log.OutputRow", data.outputRowMeta .getString( outputRowData ) ) ); } putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s); if ( data.rowlimit > 0 && data.rownr >= data.rowlimit ) { // limit has been reached: stop now. setOutputDone(); return false; } return true; }
private void writeToSalesForce( Object[] rowData ) throws KettleException { try { if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "SalesforceDelete.Log.WriteToSalesforce", data.iBufferPos, meta .getBatchSizeInt() ) ); } // if there is room in the buffer if ( data.iBufferPos < meta.getBatchSizeInt() ) { // Load the buffer array data.deleteId[data.iBufferPos] = getInputRowMeta().getString( rowData, data.indexOfKeyField ); data.outputBuffer[data.iBufferPos] = rowData; data.iBufferPos++; } if ( data.iBufferPos >= meta.getBatchSizeInt() ) { if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "SalesforceDelete.Log.CallingFlush" ) ); } flushBuffers(); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceDelete.Error.WriteToSalesforce", e .getMessage() ) ); } }