private Object[] getHashValue() throws KettleValueException { Object[] groupDataHash = new Object[groupMeta.size()]; for ( int i = 0; i < groupMeta.size(); i++ ) { ValueMetaInterface valueMeta = groupMeta.getValueMeta( i ); groupDataHash[i] = valueMeta.convertToNormalStorageType( groupData[i] ); } return groupDataHash; } }
private void initReturnMeta() { // We also want to know the metadata of the return values beforehand (null handling) data.returnMeta = new RowMeta(); for ( int i = 0; i < meta.getReturnValueField().length; i++ ) { ValueMetaInterface v = data.outputRowMeta.getValueMeta( getInputRowMeta().size() + i ).clone(); data.returnMeta.addValueMeta( v ); } }
void prepareForReMap() throws KettleStepException { // prepare for re-map when removeSelectedFields if ( meta.isRemoveSelectedFields() ) { data.remainingFieldsInputOutputMapping = new int[ data.outputRowMeta.size() - 1 ]; // -1: don't need the new // target field String[] fieldNames = data.outputRowMeta.getFieldNames(); for ( int i = 0; i < fieldNames.length - 1; i++ ) { // -1: don't search the new target field data.remainingFieldsInputOutputMapping[ i ] = data.inputRowMetaModified.indexOfValue( fieldNames[ i ] ); if ( data.remainingFieldsInputOutputMapping[ i ] < 0 ) { throw new KettleStepException( BaseMessages.getString( PKG, "ConcatFields.Error.RemainingFieldNotFoundInputStream", "" + fieldNames[ i ] ) ); } } } }
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // Set the sorted properties: ascending/descending for ( int i = 0; i < fieldName.length; i++ ) { int idx = inputRowMeta.indexOfValue( fieldName[i] ); if ( idx >= 0 ) { ValueMetaInterface valueMeta = inputRowMeta.getValueMeta( idx ); valueMeta.setSortedDescending( !ascending[i] ); // TODO: add case insensivity } } }
private void initGroupMeta( RowMetaInterface previousRowMeta ) throws KettleValueException { data.groupMeta = new RowMeta(); for ( int i = 0; i < data.groupnrs.length; i++ ) { data.groupMeta.addValueMeta( previousRowMeta.getValueMeta( data.groupnrs[ i ] ) ); } }
@Override public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { row.clear(); for ( int i = 0; i < m_stats.length; i++ ) { UnivariateStatsMetaFunction fn = m_stats[i]; ValueMetaInterface[] vmis = getValueMetas( fn, origin ); for ( int j = 0; j < vmis.length; j++ ) { row.addValueMeta( vmis[j] ); } } }
public void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository, IMetaStore metaStore ) throws KettleStepException { RowMetaInterface out = prev.clone(); getFields( out, stepMeta.getName(), new RowMetaInterface[] { info, }, null, transMeta, repository, metaStore ); if ( out != null ) { for ( int i = 0; i < out.size(); i++ ) { ValueMetaInterface outvalue = out.getValueMeta( i ); DatabaseImpact di = new DatabaseImpact( DatabaseImpact.TYPE_IMPACT_READ, transMeta.getName(), stepMeta.getName(), databaseMeta .getDatabaseName(), "", outvalue.getName(), outvalue.getName(), stepMeta.getName(), sql, BaseMessages.getString( PKG, "DynamicSQLRowMeta.DatabaseImpact.Title" ) ); impact.add( di ); } } }
@Override public void getFields( RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space ) { if ( value != null ) { ValueMetaInterface v = value.getValueMeta(); v.setOrigin( origin ); r.addValueMeta( v ); } }
@Test public void testGetValueMetaPlugin() throws KettleStepException { GetVariableMeta meta = new GetVariableMeta(); meta.setDefault(); FieldDefinition field = new FieldDefinition(); field.setFieldName( "outputField" ); field.setVariableString( String.valueOf( 2000000L ) ); field.setFieldType( ValueMetaInterface.TYPE_TIMESTAMP ); meta.setFieldDefinitions( new FieldDefinition[]{ field } ); RowMetaInterface rowMeta = new RowMeta(); meta.getFields( rowMeta, "stepName", null, null, new Variables(), null, null ); assertNotNull( rowMeta ); assertEquals( 1, rowMeta.size() ); assertEquals( "outputField", rowMeta.getFieldNames()[0] ); assertEquals( ValueMetaInterface.TYPE_TIMESTAMP, rowMeta.getValueMeta( 0 ).getType() ); assertTrue( rowMeta.getValueMeta( 0 ) instanceof ValueMetaTimestamp ); }
@Test public void getInetAddress_Test() throws Exception { ValueMetaInternetAddress v = new ValueMetaInternetAddress( "IP" ); RowMetaInterface row = mock( RowMetaInterface.class ); doReturn( v ).when( row ).searchValueMeta( anyString() ); doReturn( 0 ).when( row ).indexOfValue( anyString() ); assertEquals( InetAddress.getLoopbackAddress(), new FieldHelper( row, "IP" ).getInetAddress( new Object[] { InetAddress.getLoopbackAddress() } ) ); }
private Optional<String> getField( Object[] row, String field ) { int messageFieldIndex = getInputRowMeta().indexOfValue( field ); checkArgument( messageFieldIndex > -1, getString( PKG, "MQTTProducer.Error.FieldNotFound", field ) ); return ofNullable( row[ messageFieldIndex ] ).map( Object::toString ); }
public void addValue( ValueMetaInterface valueMeta, Object valueData ) { if ( valueMeta.isInteger() && ( valueData instanceof ObjectId ) ) { valueData = new LongObjectId( (ObjectId) valueData ).longValue(); } data = RowDataUtil.addValueData( data, rowMeta.size(), valueData ); rowMeta.addValueMeta( valueMeta ); }
private void fillPreviousFieldTableViewColumn() throws KettleException { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null ) { List<String> fieldNameList = Arrays.asList( r.getFieldNames() ); Collections.sort( fieldNameList ); colinf[1] = new ColumnInfo( getLocalizedColumn( 1 ), ColumnInfo.COLUMN_TYPE_CCOMBO, fieldNameList.toArray( new String[0] ), true ); } }
public void loadRow( Object[] r ) throws Exception { // Store rows for processing Map<String, Object> columns = new Hashtable<String, Object>(); for ( String field : inputRowMeta.getFieldNames() ) { columns.put( field, r[inputRowMeta.indexOfValue( field )] ); } rowList.add( new Row( columns, true ) ); }
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 Object[] constructErrorRow( RowMetaInterface rowMeta, Object[] r, String keyField, String referenceValue, String compareValue ) throws KettleException { if ( data.errorRowMeta == null ) { data.errorRowMeta = rowMeta.clone(); } r[data.keyDescIndex] = keyField; r[data.valueReferenceIndex] = referenceValue; r[data.valueCompareIndex] = compareValue; return r; }
private void prepareProcessPreviousFields() { if ( getInputRowMeta() == null ) { data.previousFieldsNumber = 0; data.finalOutputRowMeta = data.outputRowMeta; } else { data.previousFieldsNumber = getInputRowMeta().size(); data.finalOutputRowMeta = getInputRowMeta().clone(); meta.getFields( data.finalOutputRowMeta, getStepname(), null, null, this, repository, metaStore ); } }
@Test public void getFieldsWithoutSubject() { ValueMetaDate valueMeta = new ValueMetaDate(); valueMeta.setName( "date" ); doReturn( valueMeta ).when( rowMeta ).searchValueMeta( "date" ); memoryGroupByMeta.setSubjectField( new String[] { null } ); memoryGroupByMeta.setGroupField( new String[] { "date" } ); memoryGroupByMeta.setAggregateField( new String[] { "countDate" } ); memoryGroupByMeta.setAggregateType( new int[] { TYPE_GROUP_COUNT_ANY } ); memoryGroupByMeta.getFields( rowMeta, "Group by", mockInfo, mockNextStep, mockSpace, null, mockIMetaStore ); verify( rowMeta, times( 1 ) ).clear(); verify( rowMeta, times( 1 ) ).addRowMeta( any() ); assertNotNull( rowMeta.searchValueMeta( "countDate" ) ); } }
public RowMetaInterface getAllFields( RowMetaInterface inputRowMeta ) { RowMetaInterface rowMeta = inputRowMeta.clone(); for ( CalculatorMetaFunction fn : getCalculation() ) { if ( !Utils.isEmpty( fn.getFieldName() ) ) { // It's a new field! ValueMetaInterface v = getValueMeta( fn, null ); rowMeta.addValueMeta( v ); } } return rowMeta; }
@Test public void prevStepFieldsAreIncludedInGetStepFields() throws KettleStepException { TransMeta transMeta = new TransMeta( new Variables() ); StepMeta prevStep1 = testStep( "prevStep1", emptyList(), asList( "field1", "field2" ) ); StepMeta prevStep2 = testStep( "prevStep2", emptyList(), asList( "field3", "field4", "field5" ) ); StepMeta someStep = testStep( "step", asList( "prevStep1" ), asList( "outputField" ) ); StepMeta after = new StepMeta( "after", new DummyTransMeta() ); wireUpTestTransMeta( transMeta, prevStep1, prevStep2, someStep, after ); RowMetaInterface results = transMeta.getStepFields( someStep, after, mock( ProgressMonitorListener.class ) ); assertThat( 4, equalTo( results.size() ) ); assertThat( new String[] { "field3", "field4", "field5", "outputField" }, equalTo( results.getFieldNames() ) ); }