org.pentaho.di.core.row.RowMeta Java Examples

The following examples show how to use org.pentaho.di.core.row.RowMeta. 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: BaseFileInputStep.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare to process. Executed only first time row processing. It can't be possible to prepare to process in the
 * init() phrase, because files can be in fields from previous step.
 */
protected void prepareToRowProcessing() throws KettleException {
  data.outputRowMeta = new RowMeta();
  RowMetaInterface[] infoStep = null;

  if ( meta.inputFiles.acceptingFilenames ) {
    // input files from previous step
    infoStep = filesFromPreviousStep();
  }

  // get the metadata populated. Simple and easy.
  meta.getFields( data.outputRowMeta, getStepname(), infoStep, null, this, repository, metaStore );
  // Create convert meta-data objects that will contain Date & Number formatters
  //
  data.convertRowMeta = data.outputRowMeta.cloneToType( ValueMetaInterface.TYPE_STRING );

  BaseFileInputStepUtils.handleMissingFiles( data.files, log, meta.errorHandling.errorIgnored,
      data.dataErrorLineHandler );

  // Count the number of repeat fields...
  for ( int i = 0; i < meta.inputFields.length; i++ ) {
    if ( meta.inputFields[i].isRepeated() ) {
      data.nr_repeats++;
    }
  }
}
 
Example #2
Source File: SelectValuesTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  helper = StepMockUtil.getStepMockHelper( SelectValuesMeta.class, "SelectValuesTest" );
  when( helper.stepMeta.isDoingErrorHandling() ).thenReturn( true );

  step = new SelectValues( helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans );
  step = spy( step );
  doReturn( inputRow ).when( step ).getRow();
  doNothing().when( step )
    .putError( any( RowMetaInterface.class ), any( Object[].class ), anyLong(), anyString(), anyString(),
      anyString() );

  RowMeta inputRowMeta = new RowMeta();
  inputRowMeta.addValueMeta( new ValueMetaString( SELECTED_FIELD ) );
  step.setInputRowMeta( inputRowMeta );
}
 
Example #3
Source File: MongoDbOutputTest.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
@Test public void testTopLevelArrayStructureContainingOneObjectMutipleFields() throws Exception {
  List<MongoDbOutputMeta.MongoField> paths = asList( mf( "field1", true, "[0]" ), mf( "field2", true, "[0]" ) );

  RowMetaInterface rmi = new RowMeta();
  rmi.addValueMeta( new ValueMetaString( "field1" ) );
  rmi.addValueMeta( new ValueMetaInteger( "field2" ) );

  Object[] row = new Object[ 2 ];
  row[ 0 ] = "value1";
  row[ 1 ] = 12L;
  VariableSpace vs = new Variables();

  for ( MongoDbOutputMeta.MongoField f : paths ) {
    f.init( vs );
  }

  DBObject result = kettleRowToMongo( paths, rmi, row, MongoDbOutputData.MongoTopLevel.ARRAY, false );

  assertEquals( JSON.serialize( result ), "[ { \"field1\" : \"value1\" , \"field2\" : 12}]" );
}
 
Example #4
Source File: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private StepMetaInterface stepMetaInterfaceWithFields(
  StepMetaInterface smi, List<String> infoStepnames, List<String> fieldNames )
  throws KettleStepException {
  RowMeta rowMetaWithFields = new RowMeta();
  StepIOMeta stepIOMeta = mock( StepIOMeta.class );
  when( stepIOMeta.getInfoStepnames() ).thenReturn( infoStepnames.toArray( new String[ 0 ] ) );
  fieldNames.stream()
    .forEach( field -> rowMetaWithFields.addValueMeta( new ValueMetaString( field ) ) );
  StepMetaInterface newSmi = spy( smi );
  when( newSmi.getStepIOMeta() ).thenReturn( stepIOMeta );

  doAnswer( (Answer<Void>) invocationOnMock -> {
    RowMetaInterface passedRmi = (RowMetaInterface) invocationOnMock.getArguments()[ 0 ];
    passedRmi.addRowMeta( rowMetaWithFields );
    return null;
  } ).when( newSmi )
    .getFields( any(), any(), any(), any(), any(), any(), any() );

  return newSmi;
}
 
Example #5
Source File: HTTPIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void test204Answer() throws Exception {
  startHttpServer( get204AnswerHandler() );
  HTTPData data = new HTTPData();
  int[] index = { 0, 1 };
  RowMeta meta = new RowMeta();
  meta.addValueMeta( new ValueMetaString( "fieldName" ) );
  meta.addValueMeta( new ValueMetaInteger( "codeFieldName" ) );
  Object[] expectedRow = new Object[] { "", 204L };
  HTTP http =
    new HTTPHandler( stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, false );
  RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
  http.setInputRowMeta( inputRowMeta );
  when( inputRowMeta.clone() ).thenReturn( inputRowMeta );
  when( stepMockHelper.processRowsStepMetaInterface.getUrl() ).thenReturn( HTTP_LOCALHOST_9998 );
  when( stepMockHelper.processRowsStepMetaInterface.getHeaderField() ).thenReturn( new String[] {} );
  when( stepMockHelper.processRowsStepMetaInterface.getArgumentField() ).thenReturn( new String[] {} );
  when( stepMockHelper.processRowsStepMetaInterface.getResultCodeFieldName() ).thenReturn( "ResultCodeFieldName" );
  when( stepMockHelper.processRowsStepMetaInterface.getFieldName() ).thenReturn( "ResultFieldName" );
  http.init( stepMockHelper.processRowsStepMetaInterface, data );
  Assert.assertTrue( http.processRow( stepMockHelper.processRowsStepMetaInterface, data ) );
  Object[] out = ( (HTTPHandler) http ).getOutputRow();
  Assert.assertTrue( meta.equals( out, expectedRow, index ) );
}
 
Example #6
Source File: Database.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Build the row using ResultSetMetaData rsmd
 *
 * @param rm             The resultset metadata to inquire
 * @param ignoreLength   true if you want to ignore the length (workaround for MySQL bug/problem)
 * @param lazyConversion true if lazy conversion needs to be enabled where possible
 */
private RowMetaInterface getRowInfo( ResultSetMetaData rm, boolean ignoreLength, boolean lazyConversion )
  throws KettleDatabaseException {
  try {
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_START, databaseMeta.getName() );

    if ( rm == null ) {
      throw new KettleDatabaseException( "No result set metadata available to retrieve row metadata!" );
    }

    RowMetaInterface rowMeta = new RowMeta();

    try {
      int nrcols = rm.getColumnCount();
      for ( int i = 1; i <= nrcols; i++ ) {
        ValueMetaInterface valueMeta = getValueFromSQLType( rm, i, ignoreLength, lazyConversion );
        rowMeta.addValueMeta( valueMeta );
      }
      return rowMeta;
    } catch ( SQLException ex ) {
      throw new KettleDatabaseException( "Error getting row information from database: ", ex );
    }
  } finally {
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_STOP, databaseMeta.getName() );
  }
}
 
Example #7
Source File: GroupByIntIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
List<RowMetaAndData> getTestRowMetaAndData( int count, Integer[] nulls ) {
  List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();
  RowMetaInterface rm = new RowMeta();
  rm.addValueMeta( new ValueMetaString( KEY1 ) );
  rm.addValueMeta( new ValueMetaInteger( KEY2 ) );
  rm.addValueMeta( new ValueMetaNumber( KEY3 ) );
  rm.addValueMeta( new ValueMetaBigNumber( KEY4 ) );

  Object[] row = new Object[4];
  List<Integer> nullsList = Arrays.asList( nulls );

  for ( int i = 0; i < count; i++ ) {
    if ( nullsList.contains( i ) ) {
      for ( int j = 0; j < row.length; j++ ) {
        row[j] = null;
      }
    } else {
      row[0] = "";
      row[1] = 1L;
      row[2] = 2.0;
      row[3] = new BigDecimal( 3 );
    }
    list.add( new RowMetaAndData( rm, row ) );
  }
  return list;
}
 
Example #8
Source File: AppendIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaString( "field1" ), new ValueMetaInteger( "field2" ),
    new ValueMetaNumber( "field3" ), new ValueMetaDate( "field4" ),
    new ValueMetaBoolean( "field5" ),
    new ValueMetaBigNumber( "field6" ),
    new ValueMetaBigNumber( "field7" ) };

  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rm.addValueMeta( valuesMeta[i] );
  }

  return rm;
}
 
Example #9
Source File: PhysicalTableImporterTest.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testGetDataTypeTimestamp() throws Exception {
  final Database database = mock( Database.class );
  RowMeta rowMeta = new RowMeta();
  rowMeta.addValueMeta( new ValueMetaTimestamp( "ordertime" ) );
  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  when( database.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.quoteField( "aSchema" ) ).thenReturn( "aSchema" );
  when( databaseMeta.quoteField( "aTable" ) ).thenReturn( "aTable" );
  when( databaseMeta.getSchemaTableCombination( "aSchema", "aTable" ) ).thenReturn( "aSchema.aTable" );
  when( database.getTableFields( "aSchema.aTable" ) ).thenReturn( rowMeta );

  SqlPhysicalTable physicalTable =
    importTableDefinition( database, "aSchema", "aTable", "klingon" );
  List<IPhysicalColumn> physicalColumns = physicalTable.getPhysicalColumns();

  assertEquals( 1, physicalColumns.size() );

  IPhysicalColumn column = physicalColumns.get( 0 );
  DataType dt = ( DataType ) column.getProperty( "datatype" );
  assertEquals( "Date", dt.getName() );
}
 
Example #10
Source File: TableInputMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFields() throws Exception {
  TableInputMetaHandler meta = new TableInputMetaHandler();
  meta.setLazyConversionActive( true );
  DatabaseMeta dbMeta = mock( DatabaseMeta.class );
  meta.setDatabaseMeta( dbMeta );
  Database mockDB = meta.getDatabase();
  when( mockDB.getQueryFields( anyString(), anyBoolean() ) ).thenReturn( createMockFields() );

  RowMetaInterface expectedRowMeta = new RowMeta();
  ValueMetaInterface valueMeta = new ValueMetaString( "field1" );
  valueMeta.setStorageMetadata( new ValueMetaString( "field1" ) );
  valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
  expectedRowMeta.addValueMeta( valueMeta );

  VariableSpace space = mock( VariableSpace.class );
  RowMetaInterface rowMetaInterface = new RowMeta();
  meta.getFields( rowMetaInterface, "TABLE_INPUT_META", null, null, space, null, null );

  assertEquals( expectedRowMeta.toString(), rowMetaInterface.toString() );
}
 
Example #11
Source File: DatabaseLookupIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createResultRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaInteger( "int_field", 8, 0 ),
    new ValueMetaString( "str_field", 30, 0 ),
    new ValueMetaInteger( "RET_CODE", 8, 0 ),
    new ValueMetaString( "RET_STRING", 30, 0 ) };

  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rm.addValueMeta( valuesMeta[i] );
  }

  return rm;
}
 
Example #12
Source File: FixedTimeStreamWindowTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedStreamingBatchPoolInternalState() throws Exception {
  /*
  * Tests that the sharedStreamingBatchPool adjusts its core pool size based on the value being set
  * via the SHARED_STREAMING_BATCH_POOL_SIZE system property and that the sharedStreamingBatchPool
  * remains a singleton across FixedTimeStreamWindow instances.
  * */

  System.setProperty( Const.SHARED_STREAMING_BATCH_POOL_SIZE, "5" );
  FixedTimeStreamWindow<List> window1 =
      new FixedTimeStreamWindow<>( subtransExecutor, new RowMeta(), 0, 2, 1 );
  Field field1 = window1.getClass().getDeclaredField( "sharedStreamingBatchPool" );
  field1.setAccessible( true );
  ThreadPoolExecutor sharedStreamingBatchPool1 = (ThreadPoolExecutor) field1.get( window1 );
  assertTrue( sharedStreamingBatchPool1.getCorePoolSize() == 5 );

  System.setProperty( Const.SHARED_STREAMING_BATCH_POOL_SIZE, "10" );
  FixedTimeStreamWindow<List> window2 =
      new FixedTimeStreamWindow<>( subtransExecutor, new RowMeta(), 0, 2, 1 );
  Field field2 = window2.getClass().getDeclaredField( "sharedStreamingBatchPool" );
  field2.setAccessible( true );
  ThreadPoolExecutor sharedStreamingBatchPool2 = (ThreadPoolExecutor) field2.get( window2 );
  assertTrue( sharedStreamingBatchPool2.getCorePoolSize() == 10 );

  assertEquals( sharedStreamingBatchPool1, sharedStreamingBatchPool2 );
}
 
Example #13
Source File: KettleDatabaseRepository_GetObjectInformation_Test.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void getObjectInformation_GetDatabaseInformation() throws Exception {
  KettleDatabaseRepositoryDatabaseDelegate databaseDelegate =
      spy( new KettleDatabaseRepositoryDatabaseDelegate( repository ) );
  repository.databaseDelegate = databaseDelegate;
  RowMeta meta = createMetaForDatabase();
  Object[] values = new Object[ meta.size() ];
  values[ Arrays.asList( meta.getFieldNames() ).indexOf( KettleDatabaseRepositoryBase.FIELD_DATABASE_NAME ) ] = EXISTING_ID;
  doReturn( new RowMetaAndData( meta, values ) )
    .when( databaseDelegate )
    .getDatabase( new StringObjectId( EXISTING_ID ) );
  RepositoryObject actual = repository.getObjectInformation( new StringObjectId( EXISTING_ID ), RepositoryObjectType.DATABASE );

  assertEquals( new StringObjectId( EXISTING_ID ), actual.getObjectId() );
  assertEquals( EXISTING_ID, actual.getName() );
  assertEquals( RepositoryObjectType.DATABASE, actual.getObjectType() );
}
 
Example #14
Source File: KafkaConsumerMetaTest.java    From pentaho-kafka-consumer with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaults() throws KettleStepException {
    KafkaConsumerMeta m = new KafkaConsumerMeta();
    m.setDefault();

    RowMetaInterface rowMeta = new RowMeta();
    m.getFields(rowMeta, "kafka_consumer", null, null, null, null, null);

    // expect two fields to be added to the row stream
    assertEquals(2, rowMeta.size());

    // those fields must strings and named as configured
    assertEquals(ValueMetaInterface.TYPE_BINARY, rowMeta.getValueMeta(0).getType()); // TODO change to string
    assertEquals(ValueMetaInterface.TYPE_BINARY, rowMeta.getValueMeta(1).getType()); // TODO change to string
    assertEquals(ValueMetaInterface.STORAGE_TYPE_NORMAL, rowMeta.getValueMeta(0).getStorageType());
    assertEquals(ValueMetaInterface.STORAGE_TYPE_NORMAL, rowMeta.getValueMeta(1).getStorageType());
    // TODO check naming
    //assertEquals( rowMeta.getFieldNames()[0], m.getOutputField() );
}
 
Example #15
Source File: SFTPPutTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void remoteFilenameFieldIsMandatoryWhenStreamingFromInputField() throws Exception {
  RowMeta rowMeta = rowOfStringsMeta( "sourceFilenameFieldName", "remoteDirectoryFieldName" );
  step.setInputRowMeta( rowMeta );

  doReturn( new Object[] { "qwerty", "asdfg" } ).when( step ).getRow();

  SFTPPutMeta meta = new SFTPPutMeta();
  meta.setInputStream( true );
  meta.setPassword( "qwerty" );
  meta.setSourceFileFieldName( "sourceFilenameFieldName" );
  meta.setRemoteDirectoryFieldName( "remoteDirectoryFieldName" );

  step.processRow( meta, new SFTPPutData() );
  assertEquals( 1, step.getErrors() );
}
 
Example #16
Source File: EditRowsDialog_EmptyStringVsNull_Test.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void executeAndAssertResults( String[] expected ) throws Exception {
  EditRowsDialog dialog = mock( EditRowsDialog.class );

  when( dialog.getRowForData( any( TableItem.class ), anyInt() ) ).thenCallRealMethod();
  doCallRealMethod().when( dialog ).setRowMeta( any( RowMetaInterface.class ) );
  doCallRealMethod().when( dialog ).setStringRowMeta( any( RowMetaInterface.class ) );

  when( dialog.isDisplayingNullValue( any( TableItem.class ), anyInt() ) ).thenReturn( false );

  RowMeta meta = new RowMeta();
  meta.addValueMeta( new ValueMetaString( "s1" ) );
  meta.addValueMeta( new ValueMetaString( "s2" ) );
  meta.addValueMeta( new ValueMetaString( "s3" ) );
  dialog.setRowMeta( meta );
  dialog.setStringRowMeta( meta );

  TableItem item = mock( TableItem.class );
  when( item.getText( 1 ) ).thenReturn( " " );
  when( item.getText( 2 ) ).thenReturn( "" );
  when( item.getText( 3 ) ).thenReturn( null );

  Object[] data = dialog.getRowForData( item, 0 );
  TransTestingUtil.assertResult( expected, data );
}
 
Example #17
Source File: PentahoMapRunnable.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
public void injectValue( Object key, int keyOrdinal, ITypeConverter inConverterK, Object value, int valueOrdinal,
                         ITypeConverter inConverterV, RowMeta injectorRowMeta, RowProducer rowProducer,
                         Reporter reporter )
  throws Exception {
  Object[] row = new Object[ injectorRowMeta.size() ];
  row[ keyOrdinal ] =
    inConverterK != null ? inConverterK.convert( injectorRowMeta.getValueMeta( keyOrdinal ), key ) : key;
  row[ valueOrdinal ] =
    inConverterV != null ? inConverterV.convert( injectorRowMeta.getValueMeta( valueOrdinal ), value )
      : value;

  if ( log.isDebug() ) {
    setDebugStatus( reporter, "Injecting input record [" + row[ keyOrdinal ] + "] - [" + row[ valueOrdinal ] + "]" );
  }

  rowProducer.putRow( injectorRowMeta, row );
}
 
Example #18
Source File: CreditCardValidatorMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFields() throws KettleStepException {
  CreditCardValidatorMeta meta = new CreditCardValidatorMeta();
  meta.setDefault();
  meta.setResultFieldName( "The Result Field" );
  meta.setCardType( "The Card Type Field" );
  meta.setNotValidMsg( "Is Card Valid" );

  RowMeta rowMeta = new RowMeta();
  meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null );
  assertEquals( 3, rowMeta.size() );
  assertEquals( "The Result Field", rowMeta.getValueMeta( 0 ).getName() );
  assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() );
  assertEquals( "this step", rowMeta.getValueMeta( 0 ).getOrigin() );
  assertEquals( "The Card Type Field", rowMeta.getValueMeta( 1 ).getName() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 1 ).getType() );
  assertEquals( "this step", rowMeta.getValueMeta( 1 ).getOrigin() );
  assertEquals( "Is Card Valid", rowMeta.getValueMeta( 2 ).getName() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 2 ).getType() );
  assertEquals( "this step", rowMeta.getValueMeta( 2 ).getOrigin() );
}
 
Example #19
Source File: MongoDbOutputTest.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Testing the use of Environment Substitution during initialization of fields.
 * @throws Exception
 */
@Test public void testTopLevelArrayWithEnvironmentSubstitution() throws Exception {
  List<MongoDbOutputMeta.MongoField> paths = asList( mf( "${ENV_FIELD}", true, "[0]" ),
          mf( "field2", true, "${ENV_DOC_PATH}" ) );

  RowMetaInterface rmi = new RowMeta();
  rmi.addValueMeta( new ValueMetaString( "field1" ) );
  rmi.addValueMeta( new ValueMetaInteger( "field2" ) );

  Object[] row = new Object[ 2 ];
  row[ 0 ] = "value1";
  row[ 1 ] = 12L;
  VariableSpace vs = new Variables();
  vs.setVariable( "ENV_FIELD", "field1" );
  vs.setVariable( "ENV_DOC_PATH", "[1]" );

  for ( MongoDbOutputMeta.MongoField f : paths ) {
    f.init( vs );
  }

  DBObject result = kettleRowToMongo( paths, rmi, row, MongoDbOutputData.MongoTopLevel.ARRAY, false );
  assertEquals( JSON.serialize( result ), "[ { \"field1\" : \"value1\"} , { \"field2\" : 12}]" );
}
 
Example #20
Source File: CombinationLookupIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createTargetRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaInteger( "ID", 8, 0 ),
    new ValueMetaString( "DLR_CD", 8, 0 ),
    new ValueMetaString( "DLR_NM", 30, 0 ),
    new ValueMetaString( "DLR_DESC", 30, 0 ), };

  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rm.addValueMeta( valuesMeta[i] );
  }

  return rm;
}
 
Example #21
Source File: JavaScriptStringIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Create the meta data for the results (lpad/rpad/upper/lower).
 */
public RowMetaInterface createRowMetaInterfaceResult2() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
    {
      new ValueMetaString( "string" ), new ValueMetaString( "lpadded1" ),
      new ValueMetaString( "lpadded2" ),
      new ValueMetaString( "rpadded1" ),
      new ValueMetaString( "rpadded2" ),
      new ValueMetaString( "upperStr" ),
      new ValueMetaString( "lowerStr" ), };

  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rm.addValueMeta( valuesMeta[ i ] );
  }

  return rm;
}
 
Example #22
Source File: TransSingleThreadIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaString( "field1" ), new ValueMetaInteger( "field2" ),
    new ValueMetaNumber( "field3" ), new ValueMetaDate( "field4" ),
    new ValueMetaBoolean( "field5" ),
    new ValueMetaBigNumber( "field6" ),
    new ValueMetaBigNumber( "field7" ), };

  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rm.addValueMeta( valuesMeta[i] );
  }

  return rm;
}
 
Example #23
Source File: DatabaseLookupUTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private DatabaseLookupData getCreatedData( boolean allEquals ) throws Exception {
  Database db = mock( Database.class );
  when( db.getRows( anyString(), anyInt() ) )
    .thenReturn( Collections.singletonList( new Object[] { 1L } ) );

  RowMeta returnRowMeta = new RowMeta();
  returnRowMeta.addValueMeta( new ValueMetaInteger() );
  when( db.getReturnRowMeta() ).thenReturn( returnRowMeta );

  DatabaseLookupMeta meta = createTestMeta();
  DatabaseLookupData data = new DatabaseLookupData();

  DatabaseLookup step = createSpiedStep( db, mockHelper, meta );
  step.init( meta, data );


  data.db = db;
  data.keytypes = new int[] { ValueMetaInterface.TYPE_INTEGER };
  if ( allEquals ) {
    data.allEquals = true;
    data.conditions = new int[] { DatabaseLookupMeta.CONDITION_EQ };
  } else {
    data.allEquals = false;
    data.conditions = new int[] { DatabaseLookupMeta.CONDITION_LT };
  }
  step.processRow( meta, data );

  return data;
}
 
Example #24
Source File: ByteArrayHashIndexTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAndPut() throws KettleValueException {
  ByteArrayHashIndex obj = new ByteArrayHashIndex( new RowMeta(), 10 );
  assertNull( obj.get( new byte[]{ 10 } ) );

  obj.put( new byte[]{ 10 }, new byte[]{ 53, 12 } );
  assertNotNull( obj.get( new byte[]{ 10 } ) );
  assertArrayEquals( new byte[]{ 53, 12 }, obj.get( new byte[]{ 10 } ) );
}
 
Example #25
Source File: ReadAllCacheTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void lookup_Finds_WithTwoBetweenOperators() throws Exception {
  RowMeta meta = new RowMeta();
  meta.addValueMeta( new ValueMetaInteger() );
  meta.addValueMeta( new ValueMetaString() );
  meta.addValueMeta( new ValueMetaString() );
  meta.addValueMeta( new ValueMetaDate() );
  meta.addValueMeta( new ValueMetaDate() );
  meta.addValueMeta( new ValueMetaInteger() );

  ReadAllCache cache = buildCache( ">,BETWEEN,BETWEEN,IS NULL" );
  Object[] found = cache.getRowFromCache(
    meta, new Object[] { -1L, "1", "3", new Date( 0 ), new Date( 1000 ), null } );
  assertArrayEquals( "('1' <= keys[1] <= '3') && (0 <= keys[2] <= 1000) --> row 2", data[ 2 ], found );
}
 
Example #26
Source File: BlockingStep_PDI_11344_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta = {
    new ValueMetaString( "field1" ), new ValueMetaInteger( "field2" ), new ValueMetaNumber( "field3" ),
    new ValueMetaDate( "field4" ), new ValueMetaBoolean( "field5" ), new ValueMetaBigNumber( "field6" ),
    new ValueMetaBigNumber( "field7" ) };

  for ( ValueMetaInterface aValuesMeta : valuesMeta ) {
    rm.addValueMeta( aValuesMeta );
  }

  return rm;
}
 
Example #27
Source File: KettleDatabaseRepository_GetObjectInformation_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void getObjectInformation_AbsentTrans_IsDeletedFlagSet() throws Exception {
  KettleDatabaseRepositoryTransDelegate transDelegate =
    spy( new KettleDatabaseRepositoryTransDelegate( repository ) );

  RowMeta meta = createMetaForTrans();
  doReturn( new RowMetaAndData( meta, new Object[ meta.size() ] ) )
    .when( transDelegate )
    .getTransformation( new StringObjectId( ABSENT_ID ) );

  assertIsDeletedSet_ForAbsentObject( transDelegate, null, RepositoryObjectType.TRANSFORMATION );
}
 
Example #28
Source File: PluginRegistry.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private RowMetaInterface getPluginInformationRowMeta() {
  RowMetaInterface row = new RowMeta();

  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.Type.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.ID.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.Name.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.Description.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.Libraries.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.ImageFile.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.ClassName.Label" ) ) );
  row.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "PluginRegistry.Information.Category.Label" ) ) );

  return row;
}
 
Example #29
Source File: MergeRowsMetaCheckTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected RowMetaInterface generateRowMeta10MixedTypes() {
  RowMeta output = new RowMeta();
  for ( int i = 0; i < 10; i++ ) {
    if ( i < 5 ) {
      output.addValueMeta( new ValueMetaString( "row_" + ( i + 1 ) ) );
    } else {
      output.addValueMeta( new ValueMetaInteger( "row_" + ( i + 1 ) ) );
    }
  }
  return output;
}
 
Example #30
Source File: MappingInputMeta_GetFields_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public MappingInputMeta_GetFields_Test( RowMeta inputRowMeta, List<MappingValueRename> renames, String[] fields,
                                        boolean sortUnspecified, String[] expectedOutputFields ) {
  this.inputRowMeta = inputRowMeta;
  this.renames = renames;
  this.fields = fields;
  this.sortUnspecified = sortUnspecified;
  this.expectedOutputFields = expectedOutputFields;
}