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

The following examples show how to use org.pentaho.di.core.row.ValueMeta. 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: XMLInputField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public XMLInputField( Node fnode ) throws KettleValueException {
  setName( XMLHandler.getTagValue( fnode, "name" ) );
  setType( ValueMeta.getType( XMLHandler.getTagValue( fnode, "type" ) ) );
  setFormat( XMLHandler.getTagValue( fnode, "format" ) );
  setCurrencySymbol( XMLHandler.getTagValue( fnode, "currency" ) );
  setDecimalSymbol( XMLHandler.getTagValue( fnode, "decimal" ) );
  setGroupSymbol( XMLHandler.getTagValue( fnode, "group" ) );
  setLength( Const.toInt( XMLHandler.getTagValue( fnode, "length" ), -1 ) );
  setPrecision( Const.toInt( XMLHandler.getTagValue( fnode, "precision" ), -1 ) );
  setTrimType( getTrimTypeByCode( XMLHandler.getTagValue( fnode, "trim_type" ) ) );
  setRepeated( !"N".equalsIgnoreCase( XMLHandler.getTagValue( fnode, "repeat" ) ) );

  Node positions = XMLHandler.getSubNode( fnode, "positions" );
  int nrPositions = XMLHandler.countNodes( positions, "position" );

  fieldPosition = new XMLInputFieldPosition[nrPositions];

  for ( int i = 0; i < nrPositions; i++ ) {
    Node positionnode = XMLHandler.getSubNodeByNr( positions, "position", i );
    String encoded = XMLHandler.getNodeValue( positionnode );
    fieldPosition[i] = new XMLInputFieldPosition( encoded );
  }
}
 
Example #2
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 #3
Source File: HBaseValueMetaInterfaceImplTest.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
private void verifyXml( HBaseValueMetaInterfaceImpl toVerify, StringBuilder result, boolean isIndexedStorageType )
  throws KettleXMLException, ParserConfigurationException {
  assertNotEquals( 0, result.length() );

  Document document = loadDocumentFromString( result );

  Node node = XMLHandler.getSubNode( document, XML_TAG_FIELD );
  assertEquals( hBaseValueMetaInterface.getTableName(), XMLHandler.getTagValue( node, "table_name" ) );
  assertEquals( hBaseValueMetaInterface.getMappingName(), XMLHandler.getTagValue( node, "mapping_name" ) );
  assertEquals( hBaseValueMetaInterface.getAlias(), XMLHandler.getTagValue( node, "alias" ) );
  assertEquals( hBaseValueMetaInterface.getColumnFamily(), XMLHandler.getTagValue( node, "family" ) );
  assertEquals( hBaseValueMetaInterface.getColumnName(), XMLHandler.getTagValue( node, "column" ) );
  assertEquals( hBaseValueMetaInterface.isKey() ? "Y" : "N", XMLHandler.getTagValue( node, "key" ) );
  assertEquals( ValueMeta.getTypeDesc( hBaseValueMetaInterface.getType() ), XMLHandler.getTagValue( node, "type" ) );
  assertEquals( hBaseValueMetaInterface.getConversionMask(), XMLHandler.getTagValue( node, "format" ) );
  assertEquals( isIndexedStorageType ? EXPECTED_INDEXES_ROW : null, XMLHandler.getTagValue( node, "index_values" ) );
}
 
Example #4
Source File: GoogleSpreadsheetInputMeta.java    From pdi-google-spreadsheet-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {
    try {
        rep.saveStepAttribute(id_transformation, id_step, "serviceEmail", this.serviceEmail);
        rep.saveStepAttribute(id_transformation, id_step, "spreadsheetKey", this.spreadsheetKey);
        rep.saveStepAttribute(id_transformation, id_step, "worksheetId", this.worksheetId);
        rep.saveStepAttribute(id_transformation, id_step, "privateKeyStore", GoogleSpreadsheet.base64EncodePrivateKeyStore(this.privateKeyStore));

        for (int i = 0; i < inputFields.length; i++) {
            TextFileInputField field = inputFields[i];

            rep.saveStepAttribute(id_transformation, id_step, i, "field_name", field.getName());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_type", ValueMeta.getTypeDesc(field.getType()));
            rep.saveStepAttribute(id_transformation, id_step, i, "field_format", field.getFormat());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_currency", field.getCurrencySymbol());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_decimal", field.getDecimalSymbol());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_group", field.getGroupSymbol());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_length", field.getLength());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_precision", field.getPrecision());
            rep.saveStepAttribute(id_transformation, id_step, i, "field_trim_type", ValueMeta.getTrimTypeCode(field.getTrimType()));
        }

    } catch (Exception e) {
        throw new KettleException("Unable to save step information to the repository for id_step=" + id_step, e);
    }
}
 
Example #5
Source File: CiviMeta.java    From civicrm-data-integration with GNU General Public License v3.0 6 votes vote down vote up
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) {

    /*
     * Adicionar los campos de salida, estos son los que se toman luego en el
     * metodo processRow en la clase CiviInput. Note que esta clase es tambien
     * un atributo privado de CiviInput Aqui decimos el tipo de dato del campo
     */

        for (String cField : civiCrmKeyList) {
            try {
                // Añadido una verifición para evitar que campos ----------> Line no existentes queden fuera de la salida del paso al
                // no encontrarse en el listado de campos devuelto por CiviCRM. En este caso se asume
                // que el campo es una cadena automáticamente
                ValueMetaInterface v = new ValueMeta(outputMap.get(cField), (civiCrmListingFields.get(cField) != null) ? civiCrmListingFields.get(cField).getMetaInterfaceType() : ValueMetaInterface.TYPE_STRING);
                v.setOrigin(origin);
                r.addValueMeta(v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
Example #6
Source File: HBaseValueMetaInterfaceImplTest.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
private void verifyRepo( ObjectId arg0, ObjectId arg1, int arg2, boolean isIndexedStorageType )
  throws KettleException {
  verify( repMock, times( 1 ) )
    .saveStepAttribute( arg0, arg1, NUMBER, "table_name", hBaseValueMetaInterface.getTableName() );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "mapping_name", hBaseValueMetaInterface.getMappingName() );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "alias", hBaseValueMetaInterface.getAlias() );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "family", hBaseValueMetaInterface.getColumnFamily() );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "column", hBaseValueMetaInterface.getColumnName() );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "key", hBaseValueMetaInterface.isKey() );
  verify( repMock )
    .saveStepAttribute( arg0, arg1, NUMBER, "type", ValueMeta.getTypeDesc( hBaseValueMetaInterface.getType() ) );
  verify( repMock ).saveStepAttribute( arg0, arg1, NUMBER, "format", hBaseValueMetaInterface.getConversionMask() );
  int i = isIndexedStorageType ? 1 : 0;
  verify( repMock, times( i ) )
    .saveStepAttribute( arg0, arg1, NUMBER, "index_values", isIndexedStorageType ? EXPECTED_INDEXES_ROW : null );
}
 
Example #7
Source File: RulesExecutorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId idStep, List<DatabaseMeta> _databases ) throws KettleException {

  int nrfields = rep.countNrStepAttributes( idStep, StorageKeys.COLUMN_NAME.toString() );

  ValueMetaInterface vm = null;
  for ( int i = 0; i < nrfields; i++ ) {

    String name = rep.getStepAttributeString( idStep, i, StorageKeys.COLUMN_NAME.toString() );
    int type = ValueMeta.getType( rep.getStepAttributeString( idStep, i, StorageKeys.COLUMN_TYPE.toString() ) );

    vm = ValueMetaFactory.createValueMeta( name, type );
    getRuleResultColumns().add( vm );
  }

  setRuleFile( rep.getStepAttributeString( idStep, StorageKeys.RULE_FILE.toString() ) );
  setRuleDefinition( rep.getStepAttributeString( idStep, StorageKeys.RULE_DEFINITION.toString() ) );
}
 
Example #8
Source File: RulesExecutorMeta.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 #9
Source File: RulesAccumulatorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId idStep, List<DatabaseMeta> _databases ) throws KettleException {

  int nrfields = rep.countNrStepAttributes( idStep, StorageKeys.COLUMN_NAME.toString() );

  ValueMetaInterface vm = null;
  for ( int i = 0; i < nrfields; i++ ) {

    String name = rep.getStepAttributeString( idStep, i, StorageKeys.COLUMN_NAME.toString() );
    int type = ValueMeta.getType( rep.getStepAttributeString( idStep, i, StorageKeys.COLUMN_TYPE.toString() ) );

    vm = ValueMetaFactory.createValueMeta( name, type );
    getRuleResultColumns().add( vm );
  }

  setRuleFile( rep.getStepAttributeString( idStep, StorageKeys.RULE_FILE.toString() ) );
  setRuleDefinition( rep.getStepAttributeString( idStep, StorageKeys.RULE_DEFINITION.toString() ) );
}
 
Example #10
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 #11
Source File: HBaseValueMetaInterfaceImpl.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
@Override public void getXml( StringBuilder retval ) {
  retval.append( "\n        " ).append( XMLHandler.openTag( "field" ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "table_name", getTableName() ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "mapping_name", getMappingName() ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "alias", getAlias() ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "family", getColumnFamily() ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "column", getColumnName() ) );
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "key", isKey() ) );
  retval.append( "\n            " ).append(
    XMLHandler.addTagValue( "type", ValueMeta.getTypeDesc( getType() ) ) );
  String format = getConversionMask();
  retval.append( "\n            " ).append( XMLHandler.addTagValue( "format", format ) );
  if ( getStorageType() == ValueMetaInterface.STORAGE_TYPE_INDEXED ) {
    retval.append( "\n            " ).append( XMLHandler.addTagValue( "index_values", getIndexValues() ) );
  }
  retval.append( "\n        " ).append( XMLHandler.closeTag( "field" ) );
}
 
Example #12
Source File: XMLInputSaxField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public XMLInputSaxField( Node fnode ) throws KettleValueException {
  setName( XMLHandler.getTagValue( fnode, "name" ) );
  setType( ValueMeta.getType( XMLHandler.getTagValue( fnode, "type" ) ) );
  setFormat( XMLHandler.getTagValue( fnode, "format" ) );
  setCurrencySymbol( XMLHandler.getTagValue( fnode, "currency" ) );
  setDecimalSymbol( XMLHandler.getTagValue( fnode, "decimal" ) );
  setGroupSymbol( XMLHandler.getTagValue( fnode, "group" ) );
  setLength( Const.toInt( XMLHandler.getTagValue( fnode, "length" ), -1 ) );
  setPrecision( Const.toInt( XMLHandler.getTagValue( fnode, "precision" ), -1 ) );
  setTrimType( getTrimType( XMLHandler.getTagValue( fnode, "trim_type" ) ) );
  setRepeated( !"N".equalsIgnoreCase( XMLHandler.getTagValue( fnode, "repeat" ) ) );

  Node positions = XMLHandler.getSubNode( fnode, "positions" );
  int nrPositions = XMLHandler.countNodes( positions, "position" );

  fieldPosition = new XMLInputSaxFieldPosition[nrPositions];

  for ( int i = 0; i < nrPositions; i++ ) {
    Node positionnode = XMLHandler.getSubNodeByNr( positions, "position", i );
    String encoded = XMLHandler.getNodeValue( positionnode );
    fieldPosition[i] = new XMLInputSaxFieldPosition( encoded );
  }
}
 
Example #13
Source File: XMLOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException {
  RowMeta row = new RowMeta();
  for ( int i = 0; i < outputFields.length; i++ ) {
    XMLField field = outputFields[i];
    row.addValueMeta( new ValueMeta( field.getFieldName(), field.getType(), field.getLength(), field.getPrecision() ) );
  }
  return row;
}
 
Example #14
Source File: XsltTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
      { new ValueMeta( "XML", ValueMeta.TYPE_STRING ), new ValueMeta( "XSL", ValueMeta.TYPE_STRING ),
        new ValueMeta( "filename", ValueMeta.TYPE_STRING ), };

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

  return rm;
}
 
Example #15
Source File: GetXMLDataField.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public GetXMLDataField( Node fnode ) throws KettleValueException {
  setName( XMLHandler.getTagValue( fnode, "name" ) );
  setXPath( XMLHandler.getTagValue( fnode, "xpath" ) );
  setElementType( getElementTypeByCode( XMLHandler.getTagValue( fnode, "element_type" ) ) );
  setResultType( getResultTypeByCode( XMLHandler.getTagValue( fnode, "result_type" ) ) );
  setType( ValueMeta.getType( XMLHandler.getTagValue( fnode, "type" ) ) );
  setFormat( XMLHandler.getTagValue( fnode, "format" ) );
  setCurrencySymbol( XMLHandler.getTagValue( fnode, "currency" ) );
  setDecimalSymbol( XMLHandler.getTagValue( fnode, "decimal" ) );
  setGroupSymbol( XMLHandler.getTagValue( fnode, "group" ) );
  setLength( Const.toInt( XMLHandler.getTagValue( fnode, "length" ), -1 ) );
  setPrecision( Const.toInt( XMLHandler.getTagValue( fnode, "precision" ), -1 ) );
  setTrimType( getTrimTypeByCode( XMLHandler.getTagValue( fnode, "trim_type" ) ) );
  setRepeated( !"N".equalsIgnoreCase( XMLHandler.getTagValue( fnode, "repeat" ) ) );
}
 
Example #16
Source File: AddXMLDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the output width to minimal width...
 * 
 */
public void setMinimalWidth() {
  int nrNonEmptyFields = wFields.nrNonEmpty();
  for ( int i = 0; i < nrNonEmptyFields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );

    item.setText( 5, "" );
    item.setText( 6, "" );

    int type = ValueMeta.getType( item.getText( 2 ) );
    switch ( type ) {
      case ValueMetaInterface.TYPE_STRING:
        item.setText( 4, "" );
        break;
      case ValueMetaInterface.TYPE_INTEGER:
        item.setText( 4, "0" );
        break;
      case ValueMetaInterface.TYPE_NUMBER:
        item.setText( 4, "0.#####" );
        break;
      case ValueMetaInterface.TYPE_DATE:
        break;
      default:
        break;
    }
  }
  wFields.optWidth( true );
}
 
Example #17
Source File: XsltMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Output field (String)
  ValueMetaInterface v = new ValueMeta( space.environmentSubstitute( getResultfieldname() ), ValueMeta.TYPE_STRING );
  v.setOrigin( name );
  inputRowMeta.addValueMeta( v );
}
 
Example #18
Source File: LucidDBBulkLoader.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (LucidDBBulkLoaderMeta) smi;
  data = (LucidDBBulkLoaderData) sdi;

  if ( super.init( smi, sdi ) ) {
    data.quote = "\"".getBytes();
    data.separator = ",".getBytes();
    data.newline = Const.CR.getBytes();

    data.bulkTimestampMeta = new ValueMeta( "timestampMeta", ValueMetaInterface.TYPE_DATE );
    data.bulkTimestampMeta.setConversionMask( "yyyy-MM-dd HH:mm:ss" );
    data.bulkTimestampMeta.setStringEncoding( meta.getEncoding() );

    data.bulkDateMeta = new ValueMeta( "dateMeta", ValueMetaInterface.TYPE_DATE );
    data.bulkDateMeta.setConversionMask( "yyyy-MM-dd" );
    data.bulkDateMeta.setStringEncoding( meta.getEncoding() );

    data.bulkNumberMeta = new ValueMeta( "numberMeta", ValueMetaInterface.TYPE_NUMBER );
    data.bulkNumberMeta.setConversionMask( "#.#" );
    data.bulkNumberMeta.setGroupingSymbol( "," );
    data.bulkNumberMeta.setDecimalSymbol( "." );
    data.bulkNumberMeta.setStringEncoding( meta.getEncoding() );

    data.bufferSize = Const.toInt( environmentSubstitute( meta.getBufferSize() ), 100000 );

    // Allocate the buffer
    //
    data.rowBuffer = new byte[data.bufferSize][];
    data.bufferIndex = 0;

    // Schema-table combination...
    data.schemaTable =
      meta.getDatabaseMeta().getQuotedSchemaTableCombination(
        environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) );

    return true;
  }
  return false;
}
 
Example #19
Source File: SapInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
  try {
    rep.saveDatabaseMetaStepAttribute( id_transformation, id_step, "id_connection", databaseMeta );
    if ( function != null && !Utils.isEmpty( function.getName() ) ) {
      rep.saveStepAttribute( id_transformation, id_step, "function_name", function.getName() );
      rep.saveStepAttribute( id_transformation, id_step, "function_description", function.getDescription() );
      rep.saveStepAttribute( id_transformation, id_step, "function_group", function.getGroup() );
      rep.saveStepAttribute( id_transformation, id_step, "function_application", function.getApplication() );
      rep.saveStepAttribute( id_transformation, id_step, "function_host", function.getHost() );
    }

    for ( int i = 0; i < parameters.size(); i++ ) {
      SapParameter parameter = parameters.get( i );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_field_name", parameter.getFieldName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_sap_type", parameter.getSapType() == null
        ? null : parameter.getSapType().getCode() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_table_name", parameter.getTableName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_name", parameter.getParameterName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_target_type", ValueMeta
        .getTypeDesc( parameter.getTargetType() ) );
    }

    for ( int i = 0; i < outputFields.size(); i++ ) {
      SapOutputField field = outputFields.get( i );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_sap_field_name", field.getSapFieldName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_sap_type", field.getSapType() == null
        ? null : field.getSapType().getCode() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_table_name", field.getTableName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_target_type", ValueMeta.getTypeDesc( field
        .getTargetType() ) );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_new_name", field.getNewName() );
    }
  } catch ( Exception e ) {
    throw new KettleException( "Unable to save step information to the repository for id_step=" + id_step, e );
  }
}
 
Example #20
Source File: XmlJoinMetaGetFieldsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFieldsReturnTargetStepFieldsPlusResultXmlField() throws Exception {
  String sourceXmlStep = "source xml step name";
  String sourceStepField = "source field test name";
  String targetStepField = "target field test name";
  String resultXmlFieldName = "result xml field name";
  RowMeta rowMetaPreviousSteps = new RowMeta();
  rowMetaPreviousSteps.addValueMeta( new ValueMeta( sourceStepField, ValueMetaInterface.TYPE_STRING ) );
  xmlJoinMeta.setSourceXMLstep( sourceXmlStep );
  xmlJoinMeta.setValueXMLfield( "result xml field name" );
  StepMeta sourceStepMeta = new StepMeta();
  sourceStepMeta.setName( sourceXmlStep );

  doReturn( sourceStepMeta ).when( transMeta ).findStep( sourceXmlStep );
  doReturn( rowMetaPreviousSteps ).when( transMeta ).getStepFields( sourceStepMeta, null, null );


  RowMeta rowMeta = new RowMeta();
  ValueMetaString keepValueMeta = new ValueMetaString( targetStepField );
  ValueMetaString removeValueMeta = new ValueMetaString( sourceStepField );
  rowMeta.addValueMeta( keepValueMeta );
  rowMeta.addValueMeta( removeValueMeta );

  xmlJoinMeta.getFields( rowMeta, "testStepName", null, null, transMeta, null, null );
  assertEquals( 2, rowMeta.size() );
  String[] strings = rowMeta.getFieldNames();
  assertEquals( targetStepField, strings[0] );
  assertEquals( resultXmlFieldName, strings[1] );
}
 
Example #21
Source File: XMLInputField.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public XMLInputField( String fieldname, XMLInputFieldPosition[] xmlInputFieldPositions ) {
  this.name = fieldname;
  this.fieldPosition = xmlInputFieldPositions;
  this.length = -1;
  this.type = ValueMeta.TYPE_STRING;
  this.format = "";
  this.trimtype = TYPE_TRIM_NONE;
  this.groupSymbol = "";
  this.decimalSymbol = "";
  this.currencySymbol = "";
  this.precision = -1;
  this.repeat = false;
}
 
Example #22
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 #23
Source File: S3CsvInputDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData( S3CsvInputMeta inputMeta ) {
  wStepname.setText( stepname );
  wBucket.setText( Const.NVL( inputMeta.getBucket(), "" ) );

  if ( isReceivingInput ) {
    wFilenameField.setText( Const.NVL( inputMeta.getFilenameField(), "" ) );
    wIncludeFilename.setSelection( inputMeta.isIncludingFilename() );
  } else {
    wFilename.setText( Const.NVL( inputMeta.getFilename(), "" ) );
  }
  wDelimiter.setText( Const.NVL( inputMeta.getDelimiter(), "" ) );
  wEnclosure.setText( Const.NVL( inputMeta.getEnclosure(), "" ) );
  wMaxLineSize.setText( Const.NVL( inputMeta.getMaxLineSize(), "" ) );
  wLazyConversion.setSelection( inputMeta.isLazyConversionActive() );
  wHeaderPresent.setSelection( inputMeta.isHeaderPresent() );
  wRunningInParallel.setSelection( inputMeta.isRunningInParallel() );
  wRowNumField.setText( Const.NVL( inputMeta.getRowNumField(), "" ) );

  for ( int i = 0; i < inputMeta.getInputFields().length; i++ ) {
    TextFileInputField field = inputMeta.getInputFields()[i];

    TableItem item = new TableItem( wFields.table, SWT.NONE );
    int colnr = 1;
    item.setText( colnr++, Const.NVL( field.getName(), "" ) );
    item.setText( colnr++, ValueMeta.getTypeDesc( field.getType() ) );
    item.setText( colnr++, Const.NVL( field.getFormat(), "" ) );
    item.setText( colnr++, field.getLength() >= 0 ? Integer.toString( field.getLength() ) : "" );
    item.setText( colnr++, field.getPrecision() >= 0 ? Integer.toString( field.getPrecision() ) : "" );
    item.setText( colnr++, Const.NVL( field.getCurrencySymbol(), "" ) );
    item.setText( colnr++, Const.NVL( field.getDecimalSymbol(), "" ) );
    item.setText( colnr++, Const.NVL( field.getGroupSymbol(), "" ) );
    item.setText( colnr++, Const.NVL( field.getTrimTypeDesc(), "" ) );
  }
  wFields.removeEmptyRows();
  wFields.setRowNums();
  wFields.optWidth( true );

  wStepname.selectAll();
}
 
Example #24
Source File: StringEvaluator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public StringEvaluationResult build() {
  ValueMetaInterface meta = new ValueMeta( name, type );
  meta.setConversionMask( format );
  meta.setTrimType( trimType );
  meta.setDecimalSymbol( decimalSymbol );
  meta.setGroupingSymbol( groupingSymbol );
  meta.setLength( length );
  meta.setPrecision( precision );
  return new StringEvaluationResult( meta );
}
 
Example #25
Source File: XsltTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public RowMetaInterface createResultRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta =
      { new ValueMeta( "XML", ValueMeta.TYPE_STRING ), new ValueMeta( "XSL", ValueMeta.TYPE_STRING ),
        new ValueMeta( "filename", ValueMeta.TYPE_STRING ), new ValueMeta( "result", ValueMeta.TYPE_STRING ), };

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

  return rm;
}
 
Example #26
Source File: XMLOutputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private RowMeta initRowMeta( int count ) {
  RowMeta rm = new RowMeta();
  for ( int i = 0; i < count; i++ ) {
    rm.addValueMeta( new ValueMeta( "string", ValueMetaInterface.TYPE_STRING ) );
  }
  return rm;
}
 
Example #27
Source File: GetXMLDataTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rm = new RowMeta();

  ValueMetaInterface[] valuesMeta = { new ValueMeta( "field1", ValueMeta.TYPE_STRING ) };

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

  return rm;
}
 
Example #28
Source File: CiviOutputMeta.java    From civicrm-data-integration with GNU General Public License v3.0 5 votes vote down vote up
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) {
//    super.getFields(r, origin, info, nextStep, space);
    if (civiCrmResultField != null && !civiCrmResultField.equals("")) {
      ValueMetaInterface v = new ValueMeta(civiCrmResultField, ValueMetaInterface.TYPE_STRING);
      v.setOrigin(origin);
      r.addValueMeta(v);
    }
  }
 
Example #29
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private ValueMetaInterface getValueForLogicalColumn(DatabaseMeta databaseMeta, LogicalColumn column) {
  String columnName = ConceptUtil.getName(column, locale);
  String phColumnName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
  DataType columnType = column.getDataType();
  String lengthString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH);
  int length = Const.toInt(lengthString, -1);
  String precisionString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION);
  int precision = Const.toInt(precisionString, -1);

  int type=ValueMetaInterface.TYPE_STRING;
  switch(columnType) {
  case UNKNOWN:
  case URL:
  case STRING: precision=-1; break;
  case IMAGE:
  case BINARY: type = ValueMetaInterface.TYPE_BINARY; precision=-1; break;
  case BOOLEAN: type = ValueMetaInterface.TYPE_BOOLEAN; length=-1; precision=-1; break;
  case DATE: type = ValueMetaInterface.TYPE_DATE; length=-1; precision=-1; break;
  case NUMERIC:
    if (precision<=0 && length<15) {
      type = ValueMetaInterface.TYPE_INTEGER;
    } else {
      if (length>=15) {
        type = ValueMetaInterface.TYPE_BIGNUMBER;
      } else {
        type = ValueMetaInterface.TYPE_NUMBER;
      }
    }
    break;
    default:
      break;
  }
  ValueMetaInterface value = new ValueMeta(databaseMeta.quoteField(Const.NVL(phColumnName, columnName)), type);
  value.setLength(length, precision);
  return value;
}
 
Example #30
Source File: MongoDbInputDataTest.java    From pentaho-mongodb-plugin with Apache License 2.0 5 votes vote down vote up
@Test public void testGetNonExistentField() throws KettleException {
  Object mongoO = JSON.parse( s_testData );
  assertTrue( mongoO instanceof DBObject );

  List<MongoField> discoveredFields = new ArrayList<MongoField>();
  MongoField mm = new MongoField();
  mm.m_fieldName = "test";
  mm.m_fieldPath = "$.iDontExist";
  mm.m_kettleType = "String";
  discoveredFields.add( mm );

  RowMetaInterface rowMeta = new RowMeta();
  for ( MongoField m : discoveredFields ) {
    ValueMetaInterface vm = new ValueMeta( m.m_fieldName, ValueMeta.getType( m.m_kettleType ) );
    rowMeta.addValueMeta( vm );
  }

  MongoDbInputData data = new MongoDbInputData();
  data.outputRowMeta = rowMeta;
  data.setMongoFields( discoveredFields );
  data.init();
  Variables vars = new Variables();
  Object[] result = data.mongoDocumentToKettle( (DBObject) mongoO, vars )[0];

  assertTrue( result != null );
  assertEquals( 1, result.length - RowDataUtil.OVER_ALLOCATE_SIZE );
  assertTrue( result[0] == null );
}