private RowMetaInterface copyValueMetasFrom( RowMetaInterface source, int n ) { RowMeta result = new RowMeta(); for ( int i = 0; i < n; i++ ) { // don't need cloning here, // because value metas will be cloned during iterating through rows result.addValueMeta( source.getValueMeta( i ) ); } return result; }
/** * Get an array of the names of all the Values in the Row. * * @return an array of Strings: the names of all the Values in the Row. */ @Override public String[] getFieldNames() { lock.readLock().lock(); try { String[] retval = new String[ size() ]; for ( int i = 0; i < size(); i++ ) { String valueName = getValueMeta( i ).getName(); retval[i] = valueName == null ? "" : valueName; } return retval; } finally { lock.readLock().unlock(); } }
@Override public Object[] readData( DataInputStream inputStream ) throws KettleFileException, SocketTimeoutException { lock.readLock().lock(); try { Object[] data = new Object[ size() ]; for ( int i = 0; i < size(); i++ ) { data[ i ] = getValueMeta( i ).readData( inputStream ); } if ( size() == 0 ) { try { inputStream.readBoolean(); } catch ( EOFException e ) { throw new KettleEOFException( e ); } catch ( SocketTimeoutException e ) { throw e; } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to read the marker flag data from input stream", e ); } } return data; } finally { lock.readLock().unlock(); } }
@Override public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) { if ( r == null ) { r = new RowMeta(); // give back values } // No values are added to the row in this type of step }
@Test public void testGetFields() throws KettleStepException { DetectLastRowMeta meta = new DetectLastRowMeta(); meta.setDefault(); meta.setResultFieldName( "The Result" ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null ); assertEquals( 1, rowMeta.size() ); assertEquals( "The Result", rowMeta.getValueMeta( 0 ).getName() ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() ); }
@Test public void fiveShufflersAgainstTenSearchers() throws Exception { final int elementsAmount = 100; final int shufflersAmount = 5; final int searchersAmount = 10; final RowMeta rowMeta = new RowMeta(); for ( int i = 0; i < elementsAmount; i++ ) { rowMeta.addValueMeta( new ValueMetaString( "meta_" + i ) ); } final AtomicBoolean condition = new AtomicBoolean( true ); List<Shuffler> shufflers = new ArrayList<Shuffler>( shufflersAmount ); for ( int i = 0; i < shufflersAmount; i++ ) { shufflers.add( new Shuffler( condition, rowMeta, cycles ) ); } List<Searcher> searchers = new ArrayList<Searcher>( searchersAmount ); for ( int i = 0; i < searchersAmount; i++ ) { String name = "meta_" + ( new Random().nextInt( elementsAmount ) ); assertTrue( rowMeta.indexOfValue( name ) >= 0 ); searchers.add( new Searcher( condition, rowMeta, name ) ); } ConcurrencyTestRunner.runAndCheckNoExceptionRaised( shufflers, searchers, condition ); }
private void addColumn( ValueMetaInterface meta, Object... values ) { int column = rowMeta.size(); rowMeta.addValueMeta( meta ); for ( int row = 0; row < values.length; row++ ) { data.put( row, column, Optional.fromNullable( values[row] ) ); } }
@Test public void lookup_DoesNotFind_WithBetweenOperator() throws Exception { RowMeta meta = keysMeta.clone(); meta.setValueMeta( 3, new ValueMetaDate() ); meta.addValueMeta( new ValueMetaInteger() ); ReadAllCache cache = buildCache( "<>,IS NOT NULL,BETWEEN,IS NULL" ); Object[] found = cache.getRowFromCache( meta, new Object[] { -1L, null, new Date( 1000 ), new Date( 2000 ), null } ); assertNull( "(1000 <= keys[2] <= 2000) --> none", found ); }
@Override public void addRowMeta( RowMetaInterface rowMeta ) { for ( int i = 0; i < rowMeta.size(); i++ ) { addValueMeta( rowMeta.getValueMeta( i ) ); } }
/** * Get a Boolean value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The boolean found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public Boolean getBoolean( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getBoolean( dataRow[ index ] ); }
@Test public void getObjectInformation_ExistingJob_IsDeletedFlagNotSet() throws Exception { KettleDatabaseRepositoryJobDelegate jobDelegate = spy( new KettleDatabaseRepositoryJobDelegate( repository ) ); RowMeta meta = createMetaForJob(); Object[] values = new Object[ meta.size() ]; values[ Arrays.asList( meta.getFieldNames() ).indexOf( KettleDatabaseRepositoryBase.FIELD_JOB_NAME ) ] = EXISTING_ID; doReturn( new RowMetaAndData( meta, values ) ) .when( jobDelegate ) .getJob( new StringObjectId( EXISTING_ID ) ); assertIsDeletedNotSet_ForExistingObject( null, jobDelegate, RepositoryObjectType.JOB ); }
@Override public Object[] apply( Map<Integer, Optional<Object>> input ) { Object[] row = new Object[rowMeta.size()]; for ( Map.Entry<Integer, Optional<Object>> entry : input.entrySet() ) { row[entry.getKey()] = entry.getValue().orNull(); } return row; } } );
@Override public RowMeta clone() { lock.readLock().lock(); try { return new RowMeta( this, null ); } catch ( Exception e ) { throw new RuntimeException( e ); } finally { lock.readLock().unlock(); } }
@Test public void getFields() throws Exception { MappingInputMeta meta = new MappingInputMeta(); meta.setInputRowMeta( inputRowMeta ); meta.setValueRenames( renames ); meta.allocate( fields.length ); meta.setFieldName( fields ); meta.setSelectingAndSortingUnspecifiedFields( sortUnspecified ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "origin", new RowMetaInterface[ 0 ], null, null, null, null ); assertEquals( Arrays.toString( expectedOutputFields ), expectedOutputFields.length, rowMeta.size() ); for ( int i = 0; i < rowMeta.size(); i++ ) { assertEquals( String.format( "Element %d", i ), expectedOutputFields[ i ], rowMeta.getValueMeta( i ).getName() ); } } }
@Test public void lookup_Finds_WithBetweenOperator() throws Exception { RowMeta meta = keysMeta.clone(); meta.setValueMeta( 3, new ValueMetaDate() ); meta.addValueMeta( new ValueMetaInteger() ); ReadAllCache cache = buildCache( "<>,IS NOT NULL,BETWEEN,IS NULL" ); Object[] found = cache.getRowFromCache( meta, new Object[] { -1L, null, new Date( 140 ), new Date( 160 ), null } ); assertArrayEquals( "(140 <= keys[2] <= 160) --> row 4", data[ 4 ], found ); }
@Override List<ValueMetaInterface> doCall() throws Exception { Random random = new Random(); List<ValueMetaInterface> result = new ArrayList<ValueMetaInterface>( cycles ); for ( int i = 0; ( i < cycles ) && condition.get(); i++ ) { ValueMetaInterface added = new ValueMetaString( nameSeed + '_' + i ); rowMeta.addValueMeta( added ); result.add( added ); Thread.sleep( random.nextInt( 100 ) ); } return result; } }
/** * Get a Number value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The number found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public Double getNumber( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getNumber( dataRow[ index ] ); }
@Test public void getObjectInformation_ExistingTrans_IsDeletedFlagNotSet() throws Exception { KettleDatabaseRepositoryTransDelegate transDelegate = spy( new KettleDatabaseRepositoryTransDelegate( repository ) ); RowMeta meta = createMetaForJob(); Object[] values = new Object[ meta.size() ]; values[ Arrays.asList( meta.getFieldNames() ).indexOf( KettleDatabaseRepositoryBase.FIELD_TRANSFORMATION_NAME ) ] = EXISTING_ID; doReturn( new RowMetaAndData( meta, values ) ) .when( transDelegate ) .getTransformation( new StringObjectId( EXISTING_ID ) ); assertIsDeletedNotSet_ForExistingObject( transDelegate, null, RepositoryObjectType.TRANSFORMATION ); }
@Test public void getObjectInformation_AbsentJob_IsDeletedFlagSet() throws Exception { KettleDatabaseRepositoryJobDelegate jobDelegate = spy( new KettleDatabaseRepositoryJobDelegate( repository ) ); RowMeta meta = createMetaForJob(); doReturn( new RowMetaAndData( meta, new Object[ meta.size() ] ) ) .when( jobDelegate ) .getJob( new StringObjectId( ABSENT_ID ) ); assertIsDeletedSet_ForAbsentObject( null, jobDelegate, RepositoryObjectType.JOB ); }
@Override public RowMeta getRowMeta( String s, VariableSpace variableSpace ) { RowMeta rowMeta = new RowMeta(); rowMeta.addValueMeta( new ValueMetaString( "message" ) ); return rowMeta; }