Java Code Examples for org.pentaho.di.core.row.RowMetaInterface#setValueMetaList()

The following examples show how to use org.pentaho.di.core.row.RowMetaInterface#setValueMetaList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortRowsIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
List<RowMetaAndData> createTimestampData() {
  // Create
  long time = new Date().getTime();
  List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();

  RowMetaInterface rm = createStringRowMetaInterface();
  List<ValueMetaInterface> valueMetaList = new ArrayList<ValueMetaInterface>();
  valueMetaList.add( new ValueMetaTimestamp( "KEY1" ) );
  valueMetaList.add( new ValueMetaTimestamp( "KEY2" ) );
  rm.setValueMetaList( valueMetaList );
  Random rand = new Random();
  for ( int idx = 0; idx < MAX_COUNT; idx++ ) {
    int key1 = Math.abs( rand.nextInt() % 10000 );
    int key2 = Math.abs( rand.nextInt() % 10000 );

    Object[] r1 = new Object[] { new Timestamp( time + key1 ), new Timestamp( time + key2 ) };
    list.add( new RowMetaAndData( rm, r1 ) );
  }
  return list;
}
 
Example 2
Source File: DatabaseLookupMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldWithValueUsedTwice() throws KettleStepException {

  databaseLookupMeta.setReturnValueField( new String[] { "match", "match", "mismatch" } );
  databaseLookupMeta.setReturnValueNewName( new String[] { "v1", "v2", "v3" } );

  ValueMetaInterface v1 = new ValueMetaString( "match" );
  ValueMetaInterface v2 = new ValueMetaString( "match1" );
  RowMetaInterface[] info = new RowMetaInterface[1];
  info[0] = new RowMeta();
  info[0].setValueMetaList( Arrays.asList( v1, v2 ) );

  ValueMetaInterface r1 = new ValueMetaString( "value" );
  RowMetaInterface row = new RowMeta();
  row.setValueMetaList( new ArrayList<ValueMetaInterface>( Arrays.asList( r1 ) ) );

  databaseLookupMeta.getFields( row, "", info, null, null, null, null );

  List<ValueMetaInterface> expectedRow = Arrays.asList( new ValueMetaInterface[] { new ValueMetaString( "value" ),
    new ValueMetaString( "v1" ), new ValueMetaString( "v2" ), } );
  assertEquals( 3, row.getValueMetaList().size() );
  for ( int i = 0; i < 3; i++ ) {
    assertEquals( expectedRow.get( i ).getName(), row.getValueMetaList().get( i ).getName() );
  }
}
 
Example 3
Source File: DenormaliserAggregationsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * This is extracted common part for sum tests
 *
 * @return
 */
RowMetaInterface testSumPreconditions( String agg ) {

  // create rmi for one string and 2 integers
  RowMetaInterface rmi = new RowMeta();
  List<ValueMetaInterface> list = new ArrayList<ValueMetaInterface>();
  list.add( new ValueMetaString( "a" ) );
  list.add( new ValueMetaInteger( "b" ) );
  list.add( new ValueMetaInteger( "d" ) );
  rmi.setValueMetaList( list );

  // denormalizer key field will be String 'Junit'
  data.keyValue = new HashMap<String, List<Integer>>();
  List<Integer> listInt = new ArrayList<Integer>();
  listInt.add( 0 );
  data.keyValue.put( JUNIT, listInt );

  // we will calculate sum for second field ( like ["JUNIT", 1] )
  data.fieldNameIndex = new int[] { 1 };
  data.inputRowMeta = rmi;
  data.outputRowMeta = rmi;
  data.removeNrs = new int[] { -1 };

  // we do create internal instance of output field wiht sum aggregation
  DenormaliserTargetField tField = new DenormaliserTargetField();
  tField.setTargetAggregationType( agg );
  DenormaliserTargetField[] pivotField = new DenormaliserTargetField[] { tField };
  meta.setDenormaliserTargetField( pivotField );

  // return row meta interface to pass into denormalize method
  return rmi;
}
 
Example 4
Source File: ValueMetaBaseSetPreparedStmntValueTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLParsingWithNoDataFormatLocale() throws IOException {
  ValueMetaInterface r1 = new ValueMetaString( "value" );
  r1.setDateFormatLocale( null );
  RowMetaInterface row = new RowMeta();
  row.setValueMetaList( new ArrayList<ValueMetaInterface>( Arrays.asList( r1 ) ) );

  row.getMetaXML();
}