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

The following examples show how to use org.pentaho.di.core.row.RowMeta#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: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheEqualConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_EQ } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 1; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( new Object[]{ i * 100 }[0], result[0] );
  }
}
 
Example 2
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheNotEqualConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_NE } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 2; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( 100L, result[0] );
  }
}
 
Example 3
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheLessConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_LT } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 2; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( 100L, result[0] );
  }
}
 
Example 4
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheLessOrEqualConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_LE } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 1; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( 100L, result[0] );
  }
}
 
Example 5
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheGreaterConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_GT } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 1; i < 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( new Object[]{ ( i + 1 ) * 100 }[0], result[0] );
  }
}
 
Example 6
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheGreaterOrEqualConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_GE } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 1; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( new Object[]{ i * 100 }[0], result[0] );
  }
}
 
Example 7
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheIsNullConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_IS_NULL } );
  //insert with null lookupdata
  defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{null}, new Object[]{ 100 } );
  Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{null} );
  assertEquals( new Object[] { 100 }[ 0 ], result[ 0 ] );
}
 
Example 8
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheNotNullConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_IS_NOT_NULL } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i}, new Object[]{ i * 100 } );
  }
  for ( long i = 1; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i} );
    assertEquals( 100L, result[0] );
  }
}
 
Example 9
Source File: DefaultCacheTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getRowFromCacheInBetweenConditionTest() throws Exception {
  DatabaseLookupData databaseLookupData = mock( DatabaseLookupData.class );
  DatabaseLookupMeta databaseLookupMeta = mock( DatabaseLookupMeta.class );
  DefaultCache defaultCache = new DefaultCache( databaseLookupData, 10 );
  when( databaseLookupMeta.isLoadingAllDataInCache() ).thenReturn( true );
  Whitebox.setInternalState( databaseLookupData, "allEquals", false );
  RowMeta rowMeta = new RowMeta();
  ArrayList<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( ) );
  valueMetaList.add( new ValueMetaInteger( ) );
  rowMeta.setValueMetaList( valueMetaList );
  Whitebox.setInternalState( databaseLookupData, "lookupMeta", rowMeta );
  Whitebox.setInternalState( databaseLookupData, "conditions", new int[]{ DatabaseLookupMeta.CONDITION_BETWEEN } );
  //Several inserts with different key and different values
  for ( long i = 1; i <= 10; ++i ) {
    defaultCache.storeRowInCache( databaseLookupMeta, rowMeta, new Object[]{i, i * 10}, new Object[]{ i * 100, i * 1000 } );
  }
  for ( long i = 1; i <= 10; ++i ) {
    Object[] result = defaultCache.getRowFromCache( rowMeta, new Object[]{i, i * 10 } );
    assertEquals( new Object[]{ i * 100 }[0], result[0] );
  }
}
 
Example 10
Source File: BaseStepTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRowSafeModeEnabled() throws KettleException {
  Trans transMock = mock( Trans.class );
  when( transMock.isSafeModeEnabled() ).thenReturn( true );
  BaseStep baseStepSpy =
    spy( new BaseStep( mockHelper.stepMeta, mockHelper.stepDataInterface,
      0, mockHelper.transMeta, transMock ) );
  doNothing().when( baseStepSpy ).waitUntilTransformationIsStarted();
  doNothing().when( baseStepSpy ).openRemoteInputStepSocketsOnce();

  BlockingRowSet rowSet = new BlockingRowSet( 1 );
  List<ValueMetaInterface> valueMetaList = Arrays.asList( new ValueMetaInteger( "x" ), new ValueMetaString( "a" ) );
  RowMeta rowMeta = new RowMeta();
  rowMeta.setValueMetaList( valueMetaList );
  final Object[] row = new Object[] {};
  rowSet.putRow( rowMeta, row );

  baseStepSpy.setInputRowSets( Arrays.asList( rowSet ) );
  doReturn( rowSet ).when( baseStepSpy ).currentInputStream();

  baseStepSpy.getRow();
  verify( mockHelper.transMeta, times( 1 ) ).checkRowMixingStatically( any( StepMeta.class ), anyObject() );
}
 
Example 11
Source File: DatabaseLookupUTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private RowMeta determineFieldsTypeQueryingDbSetupAndCall( String kettlePropertyValue ) throws KettleException {
  //Row Meta - What is expected as configured in the database
  RowMeta rowMeta = new RowMeta(  );
  List<ValueMetaInterface> valueMetaList = new ArrayList<>(  );
  valueMetaList.add( new ValueMetaInteger( "int" ) );
  valueMetaList.add( new ValueMetaNumber( "num" ) );
  valueMetaList.add( new ValueMetaBigNumber( "bignum" ) );
  valueMetaList.add( new ValueMetaString( "string" ) );
  rowMeta.setValueMetaList( valueMetaList );

  //Input Row Meta
  RowMeta inputRowMeta = new RowMeta(  );
  List<ValueMetaInterface> inputValueMetaList = new ArrayList<>(  );
  inputValueMetaList.add( new ValueMetaInteger( "int" ) );
  inputRowMeta.setValueMetaList( inputValueMetaList );

  //Row Meta Output - What is expected as configured in dialog
  RowMeta rowMetaOutput = new RowMeta(  );
  List<ValueMetaInterface> outputValueMetaList = new ArrayList<>(  );
  outputValueMetaList.add( new ValueMetaInteger( "int" ) );
  outputValueMetaList.add( new ValueMetaBigNumber( "num_as_bignum" ) );
  outputValueMetaList.add( new ValueMetaBigNumber( "bignum" ) );
  rowMetaOutput.setValueMetaList( outputValueMetaList );

  //Mock Init
  DatabaseLookup dbLookup = mock( DatabaseLookup.class );
  DatabaseLookupMeta dbLookupMeta = mock( DatabaseLookupMeta.class );
  DatabaseMeta dbMeta = mock( DatabaseMeta.class );
  DatabaseLookupData dbLookupData = mock( DatabaseLookupData.class );
  Database db = mock( Database.class );
  //Expected Mock Returns
  doReturn( new String[] { "int" } ).when( dbLookupMeta ).getTableKeyField();
  doReturn( new String[] { "num", "bignum" } ).when( dbLookupMeta ).getReturnValueField();
  doReturn( dbMeta ).when( dbLookupMeta ).getDatabaseMeta();
  doReturn( "lookuptable" ).when( dbMeta ).getQuotedSchemaTableCombination( anyString(), anyString() );
  doReturn( inputRowMeta ).when( dbLookup ).getInputRowMeta();
  doReturn( rowMeta ).when( db ).getTableFields( "lookuptable" );
  //Internal State Init
  Whitebox.setInternalState( dbLookup, "data", dbLookupData );
  Whitebox.setInternalState( dbLookupData, "db", db );
  Whitebox.setInternalState( dbLookupData, "outputRowMeta", rowMetaOutput );
  Whitebox.setInternalState( dbLookup, "meta", dbLookupMeta );
  Whitebox.setInternalState( dbLookup, "variables", new Variables() );

  doCallRealMethod().when( dbLookup ).setVariable( anyString(), anyString() );
  doCallRealMethod().when( dbLookup ).getVariable( anyString(), anyString() );
  doCallRealMethod().when( dbLookup ).determineFieldsTypesQueryingDb();
  if ( kettlePropertyValue != null ) {
    dbLookup.setVariable( "KETTLE_COMPATIBILITY_DB_LOOKUP_USE_FIELDS_RETURN_TYPE_CHOSEN_IN_UI", kettlePropertyValue );
  }
  dbLookup.determineFieldsTypesQueryingDb();
  return rowMetaOutput;
}
 
Example 12
Source File: JsonInputTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected static RowMetaInterface createRowMeta( ValueMetaInterface... valueMetas ) {
  RowMeta rowMeta = new RowMeta();
  rowMeta.setValueMetaList( Arrays.asList( valueMetas ) );
  return rowMeta;
}