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

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface. 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: JsonInputTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoFilesInListError() throws Exception {
  ByteArrayOutputStream err = new ByteArrayOutputStream();
  helper.redirectLog( err, LogLevel.ERROR );

  JsonInputMeta meta = createFileListMeta( Collections.<FileObject>emptyList() );
  meta.setDoNotFailIfNoFile( false );
  JsonInputField price = new JsonInputField();
  price.setName( "price" );
  price.setType( ValueMetaInterface.TYPE_NUMBER );
  price.setPath( "$..book[*].price" );
  meta.setInputFields( new JsonInputField[] { price } );

  try ( LocaleChange enUS = new LocaleChange( Locale.US ) ) {
    JsonInput jsonInput = createJsonInput( meta );
    processRows( jsonInput, 1 );
  }
  String errMsgs = err.toString();
  assertTrue( errMsgs, errMsgs.contains( "No file(s) specified!" ) );
}
 
Example #2
Source File: TeraFastDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * ...
 */
public void getUpdate() {
  try {
    final RowMetaInterface row = this.transMeta.getPrevStepFields( this.stepname );
    if ( row != null ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( final TableItem tableItem, final ValueMetaInterface value ) {
          // possible to check format of input fields
          return true;
        }
      };
      BaseStepDialog.getFieldsFromPrevious(
        row, this.wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      this.shell, BaseMessages.getString( PKG, "TeraFastDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "TeraFastDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #3
Source File: PGBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta,
  RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository,
  IMetaStore metaStore ) throws KettleStepException {
  if ( prev != null ) {
    /* DEBUG CHECK THIS */
    // Insert dateMask fields : read/write
    for ( int i = 0; i < fieldTable.length; i++ ) {
      ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );

      DatabaseImpact ii =
        new DatabaseImpact(
          DatabaseImpact.TYPE_IMPACT_READ_WRITE, transMeta.getName(), stepMeta.getName(), databaseMeta
            .getDatabaseName(), transMeta.environmentSubstitute( tableName ), fieldTable[i],
          fieldStream[i], v != null ? v.getOrigin() : "?", "", "Type = " + v.toStringMeta() );
      impact.add( ii );
    }
  }
}
 
Example #4
Source File: MongoDbInputMeta.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( "deprecation" )
@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space ) throws KettleStepException {

  if ( m_outputJson || m_fields == null || m_fields.size() == 0 ) {
    ValueMetaInterface jsonValueMeta = new ValueMeta( jsonFieldName, ValueMetaInterface.TYPE_STRING );
    jsonValueMeta.setOrigin( origin );
    rowMeta.addValueMeta( jsonValueMeta );
  } else {
    for ( MongoField f : m_fields ) {
      ValueMetaInterface vm = new ValueMeta();
      vm.setName( f.m_fieldName );
      vm.setOrigin( origin );
      vm.setType( ValueMeta.getType( f.m_kettleType ) );
      if ( f.m_indexedVals != null ) {
        vm.setIndex( f.m_indexedVals.toArray() ); // indexed values
      }
      rowMeta.addValueMeta( vm );
    }
  }
}
 
Example #5
Source File: GroupByAggregationNullsTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  data = new GroupByData();
  data.subjectnrs = new int[] { 0 };
  GroupByMeta meta = new GroupByMeta();
  meta.setAggregateType( new int[] { 5 } );
  ValueMetaInterface vmi = new ValueMetaInteger();
  when( mockHelper.stepMeta.getStepMetaInterface() ).thenReturn( meta );
  RowMetaInterface rmi = Mockito.mock( RowMetaInterface.class );
  data.inputRowMeta = rmi;
  data.outputRowMeta = rmi;
  when( rmi.getValueMeta( Mockito.anyInt() ) ).thenReturn( vmi );
  data.aggMeta = rmi;
  data.agg = new Object[] { def };
  step = new GroupBy( mockHelper.stepMeta, data, 0, mockHelper.transMeta, mockHelper.trans );
}
 
Example #6
Source File: MappingInputFieldsTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  KettleEnvironment.init();

  // PluginRegistry.addPluginType(ValueMetaPluginType.getInstance());
  PluginRegistry.getInstance().registerPluginType( ValueMetaPluginType.class );

  Map<Class<?>, String> classes = new HashMap<Class<?>, String>();
  classes.put( ValueMetaInterface.class, "org.pentaho.di.core.row.value.ValueMetaString" );
  p1 =
      new Plugin( new String[] { "2" }, ValueMetaPluginType.class, ValueMetaInterface.class, "", "", "", "", false,
      true, classes, null, null, null );

  classes = new HashMap<Class<?>, String>();
  classes.put( ValueMetaInterface.class, "org.pentaho.di.core.row.value.ValueMetaInteger" );
  p2 =
      new Plugin( new String[] { "5" }, ValueMetaPluginType.class, ValueMetaInterface.class, "", "", "", "", false,
      true, classes, null, null, null );

  PluginRegistry.getInstance().registerPlugin( ValueMetaPluginType.class, p1 );
  PluginRegistry.getInstance().registerPlugin( ValueMetaPluginType.class, p2 );
}
 
Example #7
Source File: JsonInputTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonInputPathResolution() throws KettleException {
  JsonInputField inputField = new JsonInputField( "value" );
  final String PATH = "$[*].name";
  inputField.setPath( PATH );
  inputField.setType( ValueMetaInterface.TYPE_STRING );
  JsonInputMeta inputMeta = createSimpleMeta( "json", inputField );
  VariableSpace variables = new Variables();
  JsonInput jsonInput = null;
  try {
    jsonInput =
      createJsonInput( "json", inputMeta, variables, new Object[] { getSampleJson() } );

    JsonInputData data = (JsonInputData) Whitebox.getInternalState( jsonInput, "data" );
    FastJsonReader reader = (FastJsonReader) Whitebox.getInternalState( data, "reader" );
    RowSet rowset = reader.parse( new ByteArrayInputStream( getSampleJson().getBytes() ) );
    List results = (List) Whitebox.getInternalState( rowset, "results" );
    JSONArray jsonResult = (JSONArray) results.get( 0 );

    assertEquals( 1, jsonResult.size() );
    assertEquals( "United States of America", jsonResult.get( 0 ) );

  } catch ( InvalidPathException pathException ) {
    assertNull( jsonInput );
  }
}
 
Example #8
Source File: PhysicalTableImporter.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static DataType getDataType( ValueMetaInterface v ) {
  switch ( v.getType() ) {
    case ValueMetaInterface.TYPE_BIGNUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_NUMBER:
      return DataType.NUMERIC;
    case ValueMetaInterface.TYPE_BINARY:
      return DataType.BINARY;
    case ValueMetaInterface.TYPE_BOOLEAN:
      return DataType.BOOLEAN;
    case ValueMetaInterface.TYPE_DATE:
    case ValueMetaInterface.TYPE_TIMESTAMP:
      return DataType.DATE;
    case ValueMetaInterface.TYPE_STRING:
      return DataType.STRING;
    case ValueMetaInterface.TYPE_NONE:
    default:
      return DataType.UNKNOWN;
  }
  // the enum data type no longer supports length and precision
  // dataTypeSettings.setLength(v.getLength());
  // dataTypeSettings.setPrecision(v.getPrecision());

}
 
Example #9
Source File: CommonHadoopShim.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
@Override
public Class<? extends Writable> getHadoopWritableCompatibleClass( ValueMetaInterface kettleType ) {
  if ( kettleType == null ) {
    return NullWritable.class;
  }
  switch ( kettleType.getType() ) {
    case ValueMetaInterface.TYPE_STRING:
    case ValueMetaInterface.TYPE_BIGNUMBER:
    case ValueMetaInterface.TYPE_DATE:
      return Text.class;
    case ValueMetaInterface.TYPE_INTEGER:
      return LongWritable.class;
    case ValueMetaInterface.TYPE_NUMBER:
      return DoubleWritable.class;
    case ValueMetaInterface.TYPE_BOOLEAN:
      return BooleanWritable.class;
    case ValueMetaInterface.TYPE_BINARY:
      return BytesWritable.class;
    default:
      return Text.class;
  }
}
 
Example #10
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 #11
Source File: RulesAccumulatorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void loadXML( Node stepnode, List<DatabaseMeta> _databases, IMetaStore metaStore ) throws KettleXMLException {
  try {
    Node fields = XMLHandler.getSubNode( stepnode, StorageKeys.NODE_FIELDS.toString() );
    int nrfields = XMLHandler.countNodes( fields, StorageKeys.SUBNODE_FIELD.toString() );

    ValueMetaInterface vm = null;
    for ( int i = 0; i < nrfields; i++ ) {
      Node fnode = XMLHandler.getSubNodeByNr( fields, StorageKeys.SUBNODE_FIELD.toString(), i );

      String name = XMLHandler.getTagValue( fnode, StorageKeys.COLUMN_NAME.toString() );
      int type = ValueMeta.getType( XMLHandler.getTagValue( fnode, StorageKeys.COLUMN_TYPE.toString() ) );
      vm = ValueMetaFactory.createValueMeta( name, type );

      getRuleResultColumns().add( vm );
    }

    setRuleFile( XMLHandler.getTagValue( stepnode, StorageKeys.RULE_FILE.toString() ) );
    setRuleDefinition( XMLHandler.getTagValue( stepnode, StorageKeys.RULE_DEFINITION.toString() ) );
  } catch ( Exception e ) {
    throw new KettleXMLException( BaseMessages.getString( PKG, "RulesMeta.Error.LoadFromXML" ), e );
  }
}
 
Example #12
Source File: ConstantMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  for ( int i = 0; i < fieldName.length; i++ ) {
    if ( fieldName[i] != null && fieldName[i].length() != 0 ) {
      int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] );
      if ( type == ValueMetaInterface.TYPE_NONE ) {
        type = ValueMetaInterface.TYPE_STRING;
      }
      try {
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type );
        v.setLength( fieldLength[i] );
        v.setPrecision( fieldPrecision[i] );
        v.setOrigin( name );
        v.setConversionMask( fieldFormat[i] );
        rowMeta.addValueMeta( v );
      } catch ( Exception e ) {
        throw new KettleStepException( e );
      }
    }
  }
}
 
Example #13
Source File: CPythonRowMetaInterfaceValidator.java    From pentaho-cpython-plugin with Apache License 2.0 6 votes vote down vote up
@Override public boolean validateTestObject( RowMetaInterface testObject, Object other ) {
  if ( other == null || !( other instanceof RowMetaInterface ) ) {
    return false;
  }
  RowMetaInterface otherRow = (RowMetaInterface) other;
  if ( testObject.size() != otherRow.size() ) {
    return false;
  }
  for ( int i = 0; i < testObject.size(); i++ ) {
    ValueMetaInterface testVmi = testObject.getValueMeta( i );
    ValueMetaInterface otherVmi = otherRow.getValueMeta( i );
    if ( !testVmi.getName().equals( otherVmi.getName() ) ) {
      return false;
    }
    if ( !testVmi.getTypeDesc().equals( otherVmi.getTypeDesc() ) ) {
      return false;
    }
  }
  return true;
}
 
Example #14
Source File: BaseFileField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void guessTrimType() {
  boolean spaces_before = false;
  boolean spaces_after = false;

  for ( int i = 0; i < samples.length; i++ ) {
    spaces_before |= Const.nrSpacesBefore( samples[i] ) > 0;
    spaces_after |= Const.nrSpacesAfter( samples[i] ) > 0;
    samples[i] = Const.trim( samples[i] );
  }

  trimtype = ValueMetaInterface.TRIM_TYPE_NONE;

  if ( spaces_before ) {
    trimtype |= ValueMetaInterface.TRIM_TYPE_LEFT;
  }
  if ( spaces_after ) {
    trimtype |= ValueMetaInterface.TRIM_TYPE_RIGHT;
  }
}
 
Example #15
Source File: MySQLBulkLoaderDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void getUpdate() {
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) {
          if ( v.getType() == ValueMetaInterface.TYPE_DATE ) {
            // The default is : format is OK for dates, see if this sticks later on...
            //
            tableItem.setText( 3, "Y" );
          } else {
            tableItem.setText( 3, "Y" ); // default is OK too...
          }
          return true;
        }
      };
      BaseStepDialog.getFieldsFromPrevious( r, wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "MySQLBulkLoaderDialog.FailedToGetFields.DialogTitle" ),
      BaseMessages.getString( PKG, "MySQLBulkLoaderDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #16
Source File: StringCutIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface createResultRowMetaInterface2() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
  {
    new ValueMetaString( "field1" ), new ValueMetaString( "field2" ),
    new ValueMetaString( "outf3" ), new ValueMetaString( "outf4" ),

  };

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

  return rm;
}
 
Example #17
Source File: ValueMetaBaseTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testVerticaTimeType() throws Exception {
  // PDI-12244
  ResultSetMetaData metaData = mock( ResultSetMetaData.class );
  ValueMetaInterface valueMetaInterface = mock( ValueMetaInternetAddress.class );

  when( resultSet.getMetaData() ).thenReturn( metaData );
  when( metaData.getColumnType( 1 ) ).thenReturn( Types.TIME );
  when( resultSet.getTime( 1 ) ).thenReturn( new Time( 0 ) );
  when( valueMetaInterface.getOriginalColumnType() ).thenReturn( Types.TIME );
  when( valueMetaInterface.getType() ).thenReturn( ValueMetaInterface.TYPE_DATE );

  DatabaseInterface databaseInterface = new Vertica5DatabaseMeta();
  Object ret = databaseInterface.getValueFromResultSet( resultSet, valueMetaInterface, 0 );
  assertEquals( new Time( 0 ), ret );
}
 
Example #18
Source File: ValueMetaTimestamp.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the specified data to the data type specified in this object.
 *
 * @param meta2 the metadata of the object to be converted
 * @param data2 the data of the object to be converted
 * @return the object in the data type of this value metadata object
 * @throws KettleValueException in case there is a data conversion error
 */
@Override
public Object convertData( ValueMetaInterface meta2, Object data2 ) throws KettleValueException {
  switch ( meta2.getType() ) {
    case TYPE_TIMESTAMP:
      return ( (ValueMetaTimestamp) meta2 ).getTimestamp( data2 );
    case TYPE_STRING:
      return convertStringToTimestamp( meta2.getString( data2 ) );
    case TYPE_INTEGER:
      return convertIntegerToTimestamp( meta2.getInteger( data2 ) );
    case TYPE_NUMBER:
      return convertNumberToTimestamp( meta2.getNumber( data2 ) );
    case TYPE_DATE:
      return convertDateToTimestamp( meta2.getDate( data2 ) );
    case TYPE_BIGNUMBER:
      return convertBigNumberToTimestamp( meta2.getBigNumber( data2 ) );
    default:
      throw new KettleValueException( meta2.toStringMeta() + " : can't be converted to a timestamp" );
  }
}
 
Example #19
Source File: MonetDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface updateFields( RowMetaInterface prev, MonetDBBulkLoaderData data ) {
  // update the field table from the fields coming from the previous step
  RowMetaInterface tableFields = new RowMeta();
  List<ValueMetaInterface> fields = prev.getValueMetaList();
  fieldTable = new String[fields.size()];
  fieldStream = new String[fields.size()];
  fieldFormatOk = new boolean[fields.size()];
  int idx = 0;
  for ( ValueMetaInterface field : fields ) {
    ValueMetaInterface tableField = field.clone();
    tableFields.addValueMeta( tableField );
    fieldTable[idx] = field.getName();
    fieldStream[idx] = field.getName();
    fieldFormatOk[idx] = true;
    idx++;
  }

  data.keynrs = new int[getFieldStream().length];
  for ( int i = 0; i < data.keynrs.length; i++ ) {
    data.keynrs[i] = i;
  }
  return tableFields;
}
 
Example #20
Source File: RegexEvalMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFieldsAddsFieldIfDoesntExist() throws KettleStepException {
  RegexEvalMeta regexEvalMeta = new RegexEvalMeta();
  String name = "TEST_NAME";
  regexEvalMeta.allocate( 1 );
  String fieldName = "fieldname";
  regexEvalMeta.getFieldName()[0] = fieldName;
  when( mockInputRowMeta.indexOfValue( fieldName ) ).thenReturn( -1 );
  ValueMetaInterface mockValueMeta = mock( ValueMetaInterface.class );
  String mockName = "MOCK_NAME";
  when( mockVariableSpace.environmentSubstitute( fieldName ) ).thenReturn( mockName );
  when( mockInputRowMeta.getValueMeta( 0 ) ).thenReturn( mockValueMeta );
  regexEvalMeta.setReplacefields( true );
  regexEvalMeta.setAllowCaptureGroupsFlag( true );
  regexEvalMeta.getFields( mockInputRowMeta, name, null, null, mockVariableSpace, null, null );
  ArgumentCaptor<ValueMetaInterface> captor = ArgumentCaptor.forClass( ValueMetaInterface.class );
  verify( mockInputRowMeta ).addValueMeta( captor.capture() );
  assertEquals( fieldName, captor.getValue().getName() );
}
 
Example #21
Source File: MQTTConsumerMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void rowMetaUsesMessageDataType() {
  MQTTConsumerMeta meta = new MQTTConsumerMeta();
  meta.messageDataType = ValueMetaInterface.getTypeDescription( ValueMetaInterface.TYPE_BINARY );
  assertEquals( ValueMetaInterface.TYPE_BINARY, meta.getRowMeta( "", new Variables() ).getValueMeta( 0 ).getType() );
  meta.messageDataType = ValueMetaInterface.getTypeDescription( ValueMetaInterface.TYPE_STRING );
  assertEquals( ValueMetaInterface.TYPE_STRING, meta.getRowMeta( "", new Variables() ).getValueMeta( 0 ).getType() );
}
 
Example #22
Source File: MetaInjectTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void setEntryValue_date() throws KettleValueException {
  StepInjectionMetaEntry entry = mock( StepInjectionMetaEntry.class );
  doReturn( ValueMetaInterface.TYPE_DATE ).when( entry ).getValueType();
  RowMetaAndData row = createRowMetaAndData( new ValueMetaDate( TEST_FIELD ), null );
  SourceStepField sourceField = new SourceStepField( TEST_SOURCE_STEP_NAME, TEST_FIELD );

  MetaInject.setEntryValue( entry, row, sourceField );

  verify( entry ).setValue( null );
}
 
Example #23
Source File: XMLJoinMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  ValueMetaInterface v = new ValueMeta( this.getValueXMLfield(), ValueMetaInterface.TYPE_STRING );
  v.setOrigin( name );

  TransMeta transMeta = (TransMeta) space;
  try {
    // Row should only include fields from the target and not the source. During the preview table generation
    // the fields from all previous steps (source and target) are included in the row so lets remove the
    // source fields.
    List<String> targetFieldNames = null;
    RowMetaInterface targetRowMeta = transMeta.getStepFields( transMeta.findStep( getTargetXMLstep() ),
      null,
      null );
    if ( targetRowMeta != null ) {
      targetFieldNames = Arrays.asList( targetRowMeta.getFieldNames() );
    }
    for ( String fieldName : transMeta.getStepFields( transMeta.findStep( getSourceXMLstep() ),
                                                                          null,
                                                                          null ).getFieldNames() ) {
      if ( targetFieldNames == null || !targetFieldNames.contains( fieldName ) ) {
        row.removeValueMeta( fieldName );
      }
    }
  } catch ( KettleValueException e ) {
    // Pass
  }

  row.addValueMeta( v );
}
 
Example #24
Source File: JoinRowsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
BlockingRowSet getRowSetWithData( int size, String dataPrefix, boolean isMainStep ) {
  BlockingRowSet blockingRowSet = new BlockingRowSet( size );
  RowMeta rowMeta = new RowMeta();

  ValueMetaInterface valueMetaString = new ValueMetaString( dataPrefix + " first value name" );
  ValueMetaInterface valueMetaInteger = new ValueMetaString( dataPrefix + " second value name" );
  ValueMetaInterface valueMetaBoolean = new ValueMetaString( dataPrefix + " third value name" );

  rowMeta.addValueMeta( valueMetaString );
  rowMeta.addValueMeta( valueMetaInteger );
  rowMeta.addValueMeta( valueMetaBoolean );

  blockingRowSet.setRowMeta( rowMeta );

  for ( int i = 0; i < size; i++ ) {
    Object[] rowData = new Object[3];
    rowData[0] = dataPrefix + " row[" + i + "]-first value";
    rowData[1] = dataPrefix + " row[" + i + "]-second value";
    rowData[2] = dataPrefix + " row[" + i + "]-third value";
    blockingRowSet.putRow( rowMeta, rowData );
  }

  if ( isMainStep ) {
    blockingRowSet.setThreadNameFromToCopy( "main step name", 0, null, 0 );
  } else {
    blockingRowSet.setThreadNameFromToCopy( "secondary step name", 0, null, 0 );
  }

  blockingRowSet.setDone();

  return blockingRowSet;
}
 
Example #25
Source File: AvroToPdiConverter.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
private Object convertToPentahoType( int pentahoType, byte[] avroData, Schema field ) {
  Object pentahoData = null;
  if ( avroData != null ) {
    try {
      switch ( pentahoType ) {
        case ValueMetaInterface.TYPE_BINARY:
          pentahoData = avroData;
          break;
      }
    } catch ( Exception e ) {
      // If unable to do the type conversion just ignore. null will be returned.
    }
  }
  return pentahoData;
}
 
Example #26
Source File: Formula.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private Object convertDataToTargetValueMeta( int i, Object formulaResult ) throws KettleException {
  if ( formulaResult == null ) {
    return formulaResult;
  }
  ValueMetaInterface target = data.outputRowMeta.getValueMeta( i );
  ValueMetaInterface actual = ValueMetaFactory.guessValueMetaInterface( formulaResult );
  Object value = target.convertData( actual, formulaResult );
  return value;
}
 
Example #27
Source File: MetaInjectTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void setEntryValue_integer() throws KettleValueException {
  StepInjectionMetaEntry entry = mock( StepInjectionMetaEntry.class );
  doReturn( ValueMetaInterface.TYPE_INTEGER ).when( entry ).getValueType();
  RowMetaAndData row = createRowMetaAndData( new ValueMetaInteger( TEST_FIELD ), new Long( 1 ) );
  SourceStepField sourceField = new SourceStepField( TEST_SOURCE_STEP_NAME, TEST_FIELD );

  MetaInject.setEntryValue( entry, row, sourceField );

  verify( entry ).setValue( 1L );
}
 
Example #28
Source File: CiviStep.java    From civicrm-data-integration with GNU General Public License v3.0 5 votes vote down vote up
protected Object getObjectValue(String field, String object) {
    try {
        if (object == null || object.equals("")) {
            return null;
        }

        CiviField cf = ((CiviMeta) civiMeta).getCiviCrmListingFields().get(field);

        int metaType =  ValueMetaInterface.TYPE_STRING;
        if (cf != null)
           metaType = cf.getMetaInterfaceType();

        switch (metaType) {
        case ValueMetaInterface.TYPE_INTEGER:
            return Long.parseLong(object);
        case ValueMetaInterface.TYPE_STRING:
            return object.toString();
        case ValueMetaInterface.TYPE_NUMBER:
            return Double.parseDouble(object);
        case ValueMetaInterface.TYPE_DATE:
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            return formatter.parse(object);
        case ValueMetaInterface.TYPE_BIGNUMBER:
            return new BigDecimal(object.toString());
        case ValueMetaInterface.TYPE_BOOLEAN:
            return Boolean.parseBoolean(object);
        case ValueMetaInterface.TYPE_BINARY:
            throw new KettleValueException(toString() + " : I don't know how to convert binary values to integers.");
        case ValueMetaInterface.TYPE_SERIALIZABLE:
            throw new KettleValueException(toString()
                    + " : I don't know how to convert serializable values to integers.");
        default:
            throw new KettleValueException(toString() + " : Unknown type " + metaType + " specified.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #29
Source File: MemoryGroupBy.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void initGroupMeta( RowMetaInterface previousRowMeta ) throws KettleValueException {
  data.groupMeta = new RowMeta();
  data.entryMeta = new RowMeta();

  for ( int i = 0; i < data.groupnrs.length; i++ ) {
    ValueMetaInterface valueMeta = previousRowMeta.getValueMeta( data.groupnrs[i] );
    data.groupMeta.addValueMeta( valueMeta );

    ValueMetaInterface normalMeta = valueMeta.clone();
    normalMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
  }

  return;
}
 
Example #30
Source File: SwitchCase.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @see StepInterface#init(org.pentaho.di.trans.step.StepMetaInterface , org.pentaho.di.trans.step.StepDataInterface)
 */
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (SwitchCaseMeta) smi;
  data = (SwitchCaseData) sdi;

  if ( !super.init( smi, sdi ) ) {
    return false;
  }
  data.outputMap = meta.isContains() ? new ContainsKeyToRowSetMap() : new KeyToRowSetMap();

  if ( Utils.isEmpty( meta.getFieldname() ) ) {
    logError( BaseMessages.getString( PKG, "SwitchCase.Log.NoFieldSpecifiedToSwitchWith" ) );
    return false;
  }

  try {
    data.valueMeta = ValueMetaFactory.createValueMeta( meta.getFieldname(), meta.getCaseValueType() );
    data.valueMeta.setConversionMask( meta.getCaseValueFormat() );
    data.valueMeta.setGroupingSymbol( meta.getCaseValueGroup() );
    data.valueMeta.setDecimalSymbol( meta.getCaseValueDecimal() );
    data.stringValueMeta = ValueMetaFactory.cloneValueMeta( data.valueMeta, ValueMetaInterface.TYPE_STRING );
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "SwitchCase.Log.UnexpectedError", e ) );
  }

  return true;
}