Java Code Examples for org.pentaho.di.core.row.value.ValueMetaString

The following examples show how to use org.pentaho.di.core.row.value.ValueMetaString. These examples are extracted from open source projects. 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
public RowMetaAndData getJobAttributeRow( ObjectId id_job, int nr, String code ) throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  par.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  par.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  par.addValue(
    new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ),
    new Long( nr ) );

  if ( psJobAttributesLookup == null ) {
    setLookupJobAttribute();
  }
  database.setValues( par, psJobAttributesLookup );
  return callRead( new Callable<RowMetaAndData>() {
    @Override public RowMetaAndData call() throws Exception {
      Object[] r = database.getLookup( psJobAttributesLookup );
      if ( r == null ) {
        return null;
      }
      return new RowMetaAndData( database.getReturnRowMeta(), r );
    }
  } );
}
 
Example 2
Source Project: pentaho-kettle   Source File: CheckSumTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHexOutput_md5() throws Exception {
  MockRowListener results = executeHexTest( 2, false, "xyz", new ValueMetaString( "test" ), false );
  assertEquals( 1, results.getWritten().size() );
  assertEquals( "d16fb36f0911f878998c136191af705e", results.getWritten().get( 0 )[1] );

  results = executeHexTest( 2, false, 10.8, new ValueMetaNumber( "test" ), false );
  assertEquals( 1, results.getWritten().size() );
  assertEquals( "372df98e33ac1bf6b26d225361ba7eb5", results.getWritten().get( 0 )[1] );

  results = executeHexTest( 2, false, 10.82, new ValueMetaNumber( "test" ), false );
  assertEquals( 1, results.getWritten().size() );
  assertEquals( "68b142f87143c917f29d178aa1715957", results.getWritten().get( 0 )[1] );

  byte[] input =
      IOUtils.toByteArray( getFile( "/org/pentaho/di/trans/steps/loadfileinput/files/pentaho_splash.png" )
          .getContent().getInputStream() );
  results = executeHexTest( 2, false, input, new ValueMetaBinary( "test" ), false );
  assertEquals( 1, results.getWritten().size() );
  assertEquals( "8d808ff9051fdbfd8050f762daddf813", results.getWritten().get( 0 )[1] );
}
 
Example 3
Source Project: pentaho-kafka-consumer   Source File: KafkaConsumerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param rowCount  The number of rows that should be returned
 * @param hasFields Whether a "UUID" field should be added to each row
 * @return A RowMetaAndData object that can be used for input data in a test transformation
 */
private static List<RowMetaAndData> generateInputData(int rowCount, boolean hasFields) {
    List<RowMetaAndData> retval = new ArrayList<RowMetaAndData>();
    RowMetaInterface rowMeta = new RowMeta();
    if (hasFields) {
        rowMeta.addValueMeta(new ValueMetaString("UUID"));
    }

    for (int i = 0; i < rowCount; i++) {
        Object[] data = new Object[0];
        if (hasFields) {
            data = new Object[]{UUID.randomUUID().toString()};
        }
        retval.add(new RowMetaAndData(rowMeta, data));
    }
    return retval;
}
 
Example 4
private ValueMetaInterface getValueMetaInterface( String fieldName, int fieldType ) {
  switch ( fieldType ) {
    case ValueMetaInterface.TYPE_INET:
      return new ValueMetaInternetAddress( fieldName );
    case ValueMetaInterface.TYPE_STRING:
      return new ValueMetaString( fieldName );
    case ValueMetaInterface.TYPE_INTEGER:
      return new ValueMetaInteger( fieldName );
    case ValueMetaInterface.TYPE_NUMBER:
      return new ValueMetaNumber( fieldName );
    case ValueMetaInterface.TYPE_BIGNUMBER:
      return new ValueMetaBigNumber( fieldName );
    case ValueMetaInterface.TYPE_TIMESTAMP:
      return new ValueMetaTimestamp( fieldName );
    case ValueMetaInterface.TYPE_DATE:
      return new ValueMetaDate( fieldName );
    case ValueMetaInterface.TYPE_BOOLEAN:
      return new ValueMetaBoolean( fieldName );
    case ValueMetaInterface.TYPE_BINARY:
      return new ValueMetaBinary( fieldName );
  }
  return null;
}
 
Example 5
Source Project: pentaho-kettle   Source File: VerticaDatabaseMetaTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSQLStatements() {
  assertEquals( " LIMIT 5", nativeMeta.getLimitClause( 5 ) );
  assertEquals( "--NOTE: Table cannot be altered unless all projections are dropped.\nALTER TABLE FOO ADD BAR VARCHAR(15)",
      nativeMeta.getAddColumnStatement( "FOO", new ValueMetaString( "BAR", 15, 0 ), "", false, "", false ) );

  assertEquals( "--NOTE: Table cannot be altered unless all projections are dropped.\nALTER TABLE FOO ALTER COLUMN BAR SET DATA TYPE VARCHAR(15)",
      nativeMeta.getModifyColumnStatement( "FOO", new ValueMetaString( "BAR", 15, 0 ), "", false, "", false ) );

  assertEquals( "SELECT FOO FROM BAR LIMIT 1", nativeMeta.getSQLColumnExists( "FOO", "BAR" ) );
  assertEquals( "SELECT * FROM FOO LIMIT 1", nativeMeta.getSQLQueryFields( "FOO" ) );
  assertEquals( "SELECT 1 FROM FOO LIMIT 1", nativeMeta.getSQLTableExists( "FOO" ) );
  assertEquals( "SELECT sequence_name FROM sequences WHERE sequence_name = 'FOO'", nativeMeta.getSQLSequenceExists( "FOO" ) );
  assertEquals( "SELECT sequence_name FROM sequences", nativeMeta.getSQLListOfSequences() );
  assertEquals( "SELECT nextval('FOO')", nativeMeta.getSQLNextSequenceValue( "FOO" ) );
  assertEquals( "SELECT currval('FOO')", nativeMeta.getSQLCurrentSequenceValue( "FOO" ) );

}
 
Example 6
Source Project: pentaho-kettle   Source File: GroupByIntIT.java    License: 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 7
Source Project: pentaho-kettle   Source File: BaseDatabaseMetaTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultSQLStatements() {
  // Note - this method should use only native or odbc metas.
  // Use of the jndi meta here could create a race condition
  // when test cases are run by multiple threads
  String lineSep = System.getProperty( "line.separator" );
  String expected = "ALTER TABLE FOO DROP BAR" + lineSep;
  assertEquals( expected, odbcMeta.getDropColumnStatement( "FOO", new ValueMetaString( "BAR" ), "", false, "", false ) );
  assertEquals( "TRUNCATE TABLE FOO", odbcMeta.getTruncateTableStatement( "FOO" ) );
  assertEquals( "SELECT * FROM FOO", odbcMeta.getSQLQueryFields( "FOO" ) );
  assertEquals( "SELECT 1 FROM FOO", odbcMeta.getSQLTableExists( "FOO" ) );
  assertEquals( "SELECT FOO FROM BAR", odbcMeta.getSQLColumnExists( "FOO", "BAR" ) );
  assertEquals( "insert into \"FOO\".\"BAR\"(KEYFIELD, VERSIONFIELD) values (0, 1)",
      nativeMeta.getSQLInsertAutoIncUnknownDimensionRow( "\"FOO\".\"BAR\"", "KEYFIELD", "VERSIONFIELD" ) );
  assertEquals( "select count(*) FROM FOO", nativeMeta.getSelectCountStatement( "FOO" ) );
  assertEquals( "COL9", nativeMeta.generateColumnAlias( 9, "FOO" ) );
  assertEquals( "[SELECT 1, INSERT INTO FOO VALUES(BAR), DELETE FROM BAR]", nativeMeta.parseStatements( "SELECT 1;INSERT INTO FOO VALUES(BAR);DELETE FROM BAR" ).toString() );
  assertEquals( "CREATE TABLE ", nativeMeta.getCreateTableStatement() );
  assertEquals( "DROP TABLE IF EXISTS FOO", nativeMeta.getDropTableIfExistsStatement( "FOO" ) );
}
 
Example 8
Source Project: pentaho-mongodb-plugin   Source File: MongoDbOutputTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void testTopLevelArrayStructureWithPrimitives() throws Exception {
  List<MongoDbOutputMeta.MongoField> paths = asList( mf( "field1", false, "[0]" ), mf( "field2", false, "[1]" ) );

  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 ), "[ \"value1\" , 12]" );
}
 
Example 9
public ObjectId updateElementType( ObjectId namespaceId, ObjectId elementTypeId, IMetaStoreElementType type ) throws KettleException {

    RowMetaAndData table = new RowMetaAndData();

    table.addValue(
      new ValueMetaInteger(
        KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE ),
      elementTypeId );
    table.addValue( new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_NAMESPACE ), namespaceId );
    table.addValue( new ValueMetaString(
      KettleDatabaseRepository.FIELD_ELEMENT_TYPE_NAME ), type.getName() );
    table.addValue( new ValueMetaString(
      KettleDatabaseRepository.FIELD_ELEMENT_TYPE_DESCRIPTION ), type
      .getDescription() );

    repository.connectionDelegate.updateTableRow(
      KettleDatabaseRepository.TABLE_R_ELEMENT_TYPE,
      KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE, table );

    if ( log.isDebug() ) {
      log.logDebug( "Updated element type [" + type.getName() + "]" );
    }

    return elementTypeId;
  }
 
Example 10
Source Project: pentaho-mongodb-plugin   Source File: MongoDbOutputTest.java    License: 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 11
Source Project: pentaho-kettle   Source File: FixedFileInputField.java    License: Apache License 2.0 6 votes vote down vote up
public String getXML() {
  StringBuilder retval = new StringBuilder( 300 );

  retval.append( "      " ).append( XMLHandler.openTag( XML_TAG ) ).append( Const.CR );
  retval.append( "        " ).append( XMLHandler.addTagValue( "name", name ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "type",
    ValueMetaFactory.getValueMetaName( type ) ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "format", format ) );
  retval.append( "        " ).append(
    XMLHandler.addTagValue( "trim_type", ValueMetaString.getTrimTypeCode( trimType ) ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "currency", currency ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "decimal", decimal ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "group", grouping ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "width", width ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "length", length ) );
  retval.append( "        " ).append( XMLHandler.addTagValue( "precision", precision ) );
  retval.append( "      " ).append( XMLHandler.closeTag( XML_TAG ) ).append( Const.CR );

  return retval.toString();
}
 
Example 12
Source Project: pentaho-kettle   Source File: EnterValueDialog.java    License: Apache License 2.0 6 votes vote down vote up
private ValueMetaAndData getValue( String valuename ) throws KettleValueException {
  try {
    int valtype = ValueMetaFactory.getIdForValueMeta( wValueType.getText() );
    ValueMetaAndData val = new ValueMetaAndData( valuename, wInputString.getText() );

    ValueMetaInterface valueMeta = ValueMetaFactory.cloneValueMeta( val.getValueMeta(), valtype );
    Object valueData = val.getValueData();

    int formatIndex = wFormat.getSelectionIndex();
    valueMeta.setConversionMask( formatIndex >= 0 ? wFormat.getItem( formatIndex ) : wFormat.getText() );
    valueMeta.setLength( Const.toInt( wLength.getText(), -1 ) );
    valueMeta.setPrecision( Const.toInt( wPrecision.getText(), -1 ) );
    val.setValueMeta( valueMeta );

    ValueMetaInterface stringValueMeta = new ValueMetaString( valuename );
    stringValueMeta.setConversionMetadata( valueMeta );

    Object targetData = stringValueMeta.convertDataUsingConversionMetaData( valueData );
    val.setValueData( targetData );

    return val;
  } catch ( Exception e ) {
    throw new KettleValueException( e );
  }
}
 
Example 13
Source Project: pentaho-kettle   Source File: TransSingleThreadIT.java    License: 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 14
Source Project: pentaho-kettle   Source File: TextFileInputTest.java    License: Apache License 2.0 6 votes vote down vote up
private TextFileInputData createDataObject( String file,
                                            String separator,
                                            String... outputFields ) throws Exception {
  TextFileInputData data = new TextFileInputData();
  data.files = new FileInputList();
  data.files.addFile( KettleVFS.getFileObject( file ) );

  data.separator = separator;

  data.outputRowMeta = new RowMeta();
  if ( outputFields != null ) {
    for ( String field : outputFields ) {
      data.outputRowMeta.addValueMeta( new ValueMetaString( field ) );
    }
  }

  data.dataErrorLineHandler = mock( FileErrorHandler.class );
  data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
  data.filterProcessor = new TextFileFilterProcessor( new TextFileFilter[ 0 ], new Variables() );
  data.filePlayList = new FilePlayListAll();
  return data;
}
 
Example 15
Source Project: pentaho-kettle   Source File: JaninoStepIT.java    License: Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaString( "string" ),
    new ValueMetaInteger( "integer" ),
    new ValueMetaNumber( "number" ),
    new ValueMetaBigNumber( "bigdecimal" ),
    new ValueMetaDate( "date" ),
    new ValueMetaBinary( "binary" ),
    new ValueMetaBoolean( "bool" ),
    new ValueMetaTimestamp( "timestamp" ),
    new ValueMetaInternetAddress( "inetaddress" ), };

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

  return rm;
}
 
Example 16
Source Project: pentaho-kettle   Source File: RowTest.java    License: Apache License 2.0 6 votes vote down vote up
private RowMetaInterface createTestRowMetaIndexedStringConversion1( String[] colors, Date[] dates ) {
  RowMetaInterface rowMeta = new RowMeta();

  // A string object, indexed.
  ValueMetaInterface meta1 = new ValueMetaString( "stringValue", 30, 0 );
  meta1.setIndex( colors );
  meta1.setStorageType( ValueMetaInterface.STORAGE_TYPE_INDEXED );
  rowMeta.addValueMeta( meta1 );

  ValueMetaInterface meta2 = new ValueMetaDate( "dateValue" );
  meta2.setIndex( dates );
  meta2.setStorageType( ValueMetaInterface.STORAGE_TYPE_INDEXED );
  rowMeta.addValueMeta( meta2 );

  return rowMeta;
}
 
Example 17
Source Project: pentaho-kettle   Source File: JavaScriptStringIT.java    License: 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 18
private synchronized ObjectId insertDirectory( ObjectId id_directory_parent, RepositoryDirectoryInterface dir ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextDirectoryID();

  String tablename = KettleDatabaseRepository.TABLE_R_DIRECTORY;
  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY ), id );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT ),
    id_directory_parent );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME ), dir.getName() );

  repository.connectionDelegate.getDatabase().prepareInsert( table.getRowMeta(), tablename );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 19
Source Project: pentaho-kettle   Source File: HTTPPOSTIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test204Answer() throws Exception {
  startHttpServer( get204AnswerHandler() );
  HTTPPOSTData data = new HTTPPOSTData();
  int[] index = { 0, 1 };
  RowMeta meta = new RowMeta();
  meta.addValueMeta( new ValueMetaString( "fieldName" ) );
  meta.addValueMeta( new ValueMetaInteger( "codeFieldName" ) );
  Object[] expectedRow = new Object[] { "", 204L };
  HTTPPOST HTTPPOST = new HTTPPOSTHandler(
    stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, false );
  RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
  HTTPPOST.setInputRowMeta( inputRowMeta );
  when( inputRowMeta.clone() ).thenReturn( inputRowMeta );
  when( stepMockHelper.processRowsStepMetaInterface.getUrl() ).thenReturn( HTTP_LOCALHOST_9998 );
  when( stepMockHelper.processRowsStepMetaInterface.getQueryField() ).thenReturn( new String[] {} );
  when( stepMockHelper.processRowsStepMetaInterface.getArgumentField() ).thenReturn( new String[] {} );
  when( stepMockHelper.processRowsStepMetaInterface.getResultCodeFieldName() ).thenReturn( "ResultCodeFieldName" );
  when( stepMockHelper.processRowsStepMetaInterface.getFieldName() ).thenReturn( "ResultFieldName" );
  HTTPPOST.init( stepMockHelper.processRowsStepMetaInterface, data );
  Assert.assertTrue( HTTPPOST.processRow( stepMockHelper.processRowsStepMetaInterface, data ) );
  Object[] out = ( (HTTPPOSTHandler) HTTPPOST ).getOutputRow();
  Assert.assertTrue( meta.equals( out, expectedRow, index ) );
}
 
Example 20
public RowMetaAndData fillTableRow( IUser userInfo ) {
  RowMetaAndData r = new RowMetaAndData();
  r.addValue( new ValueMetaInteger( "ID_USER" ), userInfo.getObjectId() );
  r.addValue( new ValueMetaString( "LOGIN" ), userInfo.getLogin() );
  r.addValue( new ValueMetaString( "PASSWORD" ), Encr.encryptPassword( userInfo
    .getPassword() ) );
  r.addValue( new ValueMetaString( "NAME" ), userInfo.getUsername() );
  r.addValue( new ValueMetaString( "DESCRIPTION" ), userInfo.getDescription() );
  r.addValue( new ValueMetaBoolean( "ENABLED" ), Boolean.valueOf( userInfo.isEnabled() ) );
  return r;
}
 
Example 21
private static RowMeta createRowMeta( String... fields ) {
  RowMeta meta = new RowMeta();
  for ( String field : fields ) {
    meta.addValueMeta( new ValueMetaString( field ) );
  }
  return meta;
}
 
Example 22
public synchronized LongObjectId getIDWithValue( String tablename, String idfield, String lookupfield,
                                                 String value ) throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  par.addValue( new ValueMetaString( "value" ), value );
  RowMetaAndData result = getOneRow(
    "SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ?", par.getRowMeta(), par
      .getData() );

  if ( result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0 ) );
  }
  return null;
}
 
Example 23
Source Project: pentaho-kettle   Source File: HTTPIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateNamesInHeader() throws Exception {
  startHttpServer( getDuplicateHeadersHandler() );
  HTTPData data = new HTTPData();
  RowMeta meta = new RowMeta();
  meta.addValueMeta( new ValueMetaString( "headerFieldName" ) );
  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.getEncoding() ).thenReturn( "UTF8" );
  when( stepMockHelper.processRowsStepMetaInterface.getResponseHeaderFieldName() ).thenReturn(
    "ResponseHeaderFieldName" );
  http.init( stepMockHelper.processRowsStepMetaInterface, data );
  Assert.assertTrue( http.processRow( stepMockHelper.processRowsStepMetaInterface, data ) );
  Object[] out = ( (HTTPHandler) http ).getOutputRow();
  Assert.assertTrue( out.length == 1 );
  JSONParser parser = new JSONParser();
  JSONObject json = (JSONObject) parser.parse( (String) out[ 0 ] );
  Object userAgent = json.get( "User-agent" );
  Assert.assertTrue( "HTTPTool/1.0".equals( userAgent ) );
  Object cookies = json.get( "Set-cookie" );
  Assert.assertTrue( cookies instanceof JSONArray );
  for ( int i = 0; i < 3; i++ ) {
    String cookie = ( (String) ( (JSONArray) cookies ).get( i ) );
    Assert.assertTrue( cookie.startsWith( "cookie" + i ) );
  }
}
 
Example 24
Source Project: pentaho-kettle   Source File: ConcatFieldsMeta.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
                       VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // do not call the super class from TextFileOutputMeta since it modifies the source meta data
  // see getFieldsModifyInput() instead

  // remove selected fields from the stream when true
  if ( removeSelectedFields ) {
    if ( getOutputFields().length > 0 ) {
      for ( int i = 0; i < getOutputFields().length; i++ ) {
        TextFileField field = getOutputFields()[ i ];
        try {
          row.removeValueMeta( field.getName() );
        } catch ( KettleValueException e ) {
          // just ignore exceptions since missing fields are handled in the ConcatFields class
        }
      }
    } else { // no output fields selected, take them all, remove them all
      row.clear();
    }
  }

  // Check Target Field Name
  if ( Utils.isEmpty( targetFieldName ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "ConcatFieldsMeta.CheckResult.TargetFieldNameMissing" ) );
  }
  // add targetFieldName
  ValueMetaInterface vValue = new ValueMetaString( targetFieldName );
  vValue.setLength( targetFieldLength, 0 );
  vValue.setOrigin( name );
  if ( !Utils.isEmpty( getEncoding() ) ) {
    vValue.setStringEncoding( getEncoding() );
  }
  row.addValueMeta( vValue );
}
 
Example 25
Source Project: pentaho-hadoop-shims   Source File: ParquetConverter.java    License: Apache License 2.0 5 votes vote down vote up
private void addValueMeta( int pdiType, String pentahoFieldName ) {
  switch ( pdiType ) {
    case ValueMetaInterface.TYPE_BINARY:
      fields.addValueMeta( new ValueMetaBinary( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_BIGNUMBER:
      fields.addValueMeta( new ValueMetaBigNumber( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      fields.addValueMeta( new ValueMetaBoolean( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_DATE:
      fields.addValueMeta( new ValueMetaDate( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_INET:
      fields.addValueMeta( new ValueMetaInternetAddress( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      fields.addValueMeta( new ValueMetaInteger( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_NUMBER:
      fields.addValueMeta( new ValueMetaNumber( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_STRING:
      fields.addValueMeta( new ValueMetaString( pentahoFieldName ) );
      break;
    case ValueMetaInterface.TYPE_TIMESTAMP:
      fields.addValueMeta( new ValueMetaTimestamp( pentahoFieldName ) );
      break;
  }
}
 
Example 26
@Override public TextFileInputField getTestObject() {
  TextFileInputField rtn = new TextFileInputField( UUID.randomUUID().toString(), rand.nextInt(), rand.nextInt() );
  rtn.setType( rand.nextInt( 7 ) );
  rtn.setCurrencySymbol( UUID.randomUUID().toString() );
  rtn.setDecimalSymbol( UUID.randomUUID().toString() );
  rtn.setFormat( UUID.randomUUID().toString() );
  rtn.setGroupSymbol( UUID.randomUUID().toString() );
  rtn.setIfNullValue( UUID.randomUUID().toString() );
  rtn.setIgnored( rand.nextBoolean() );
  rtn.setNullString( UUID.randomUUID().toString() );
  rtn.setPrecision( rand.nextInt( 9 ) );
  rtn.setRepeated( rand.nextBoolean() );
  rtn.setTrimType( rand.nextInt( ValueMetaString.trimTypeDesc.length ) );
  return rtn;
}
 
Example 27
Source Project: pentaho-kettle   Source File: SalesforceInsertMeta.java    License: Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  String realfieldname = space.environmentSubstitute( getSalesforceIDFieldName() );
  if ( !Utils.isEmpty( realfieldname ) ) {
    ValueMetaInterface v = new ValueMetaString( realfieldname );
    v.setLength( 18 );
    v.setOrigin( name );
    r.addValueMeta( v );
  }
}
 
Example 28
Source Project: pentaho-kettle   Source File: StringOperationsTest.java    License: Apache License 2.0 5 votes vote down vote up
private RowSet mockInputRowSet() {
  ValueMetaString valueMeta = new ValueMetaString( "Value" );
  valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
  valueMeta.setStorageMetadata( new ValueMetaString( "Value" ) );

  RowMeta inputRowMeta = new RowMeta();
  inputRowMeta.addValueMeta( valueMeta );

  RowSet inputRowSet = smh.getMockInputRowSet( new Object[][] { { " Value ".getBytes() } } );
  doReturn( inputRowMeta ).when( inputRowSet ).getRowMeta();

  return inputRowSet;
}
 
Example 29
Source Project: pentaho-mongodb-plugin   Source File: MongoDbOutputTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * PDI-11045. When doing a non-modifier update/upsert it should not be necessary to define query fields a second time
 * in the step (i.e. those paths that the user defines for the matching conditions should be placed into the update
 * document automatically).
 *
 * @throws KettleException
 */
@Test public void testUpdateObjectContainsQueryFields() throws Exception {
  List<MongoDbOutputMeta.MongoField> paths = new ArrayList<MongoDbOutputMeta.MongoField>( 2 );

  MongoDbOutputMeta.MongoField mf = mf( "field1", true, "" );
  mf.m_updateMatchField = true;
  paths.add( mf );

  mf = mf( "field2", true, "" );
  paths.add( mf );

  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.RECORD, false );

  assertEquals( JSON.serialize( result ), "{ \"field1\" : \"value1\" , \"field2\" : 12}" );
}
 
Example 30
Source Project: pentaho-kettle   Source File: JmsConsumerMeta.java    License: Apache License 2.0 5 votes vote down vote up
@Override public RowMeta getRowMeta( String s, VariableSpace variableSpace ) {
  RowMeta rowMeta = new RowMeta();
  rowMeta.addValueMeta( new ValueMetaString( messageField ) );
  rowMeta.addValueMeta( new ValueMetaString( destinationField ) );
  rowMeta.addValueMeta( new ValueMetaString( messageId ) );
  rowMeta.addValueMeta( new ValueMetaString( jmsTimestamp ) );
  rowMeta.addValueMeta( new ValueMetaString( jmsRedelivered ) );
  return rowMeta;
}