Java Code Examples for org.pentaho.di.core.row.ValueMeta#getType()

The following examples show how to use org.pentaho.di.core.row.ValueMeta#getType() . 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: 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 2
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 3
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 4
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 5
Source File: HBaseValueMeta.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
/**
 * Set the type for this field from a string
 *
 * @param hbaseType the type for this field as a string
 * @throws IllegalArgumentException if the type is unknown
 */
public void setHBaseTypeFromString( String hbaseType )
  throws IllegalArgumentException {
  if ( hbaseType.equalsIgnoreCase( "Integer" ) ) {
    setType( ValueMeta.getType( hbaseType ) );
    setIsLongOrDouble( false );
    return;
  }
  if ( hbaseType.equalsIgnoreCase( "Long" ) ) {
    setType( ValueMeta.getType( "Integer" ) );
    setIsLongOrDouble( true );
    return;
  }
  if ( hbaseType.equals( "Float" ) ) {
    setType( ValueMeta.getType( "Number" ) );
    setIsLongOrDouble( false );
    return;
  }
  if ( hbaseType.equals( "Double" ) ) {
    setType( ValueMeta.getType( "Number" ) );
    setIsLongOrDouble( true );
    return;
  }

  // default
  int type = ValueMeta.getType( hbaseType );
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    throw new IllegalArgumentException( BaseMessages.getString( PKG,
      "HBaseValueMeta.Error.UnknownType", hbaseType ) );
  }

  setType( type );
}
 
Example 6
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 );
}
 
Example 7
Source File: MongoDbInputDataTest.java    From pentaho-mongodb-plugin with Apache License 2.0 5 votes vote down vote up
@Test public void testArrayUnwindArrayFieldsOnly() throws KettleException {
  Object mongoO = JSON.parse( s_testData2 );
  assertTrue( mongoO instanceof DBObject );

  List<MongoField> fields = new ArrayList<MongoField>();

  MongoField mm = new MongoField();
  mm.m_fieldName = "test";
  mm.m_fieldPath = "$.one.two[*].rec1.f1";
  mm.m_kettleType = "String";

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

  MongoDbInputData data = new MongoDbInputData();
  data.outputRowMeta = rowMeta;
  data.setMongoFields( fields );
  data.init();
  Variables vars = new Variables();

  Object[][] result = data.mongoDocumentToKettle( (DBObject) mongoO, vars );

  assertTrue( result != null );
  assertEquals( 2, result.length );

  // should be two rows returned due to the array expansion
  assertTrue( result[0] != null );
  assertTrue( result[1] != null );
  assertEquals( "bob", result[0][0] );
  assertEquals( "sid", result[1][0] );
}
 
Example 8
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 9
Source File: XMLOutputDialog.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 ValueMeta.TYPE_STRING:
        item.setText( 4, "" );
        break;
      case ValueMeta.TYPE_INTEGER:
        item.setText( 4, "0" );
        break;
      case ValueMeta.TYPE_NUMBER:
        item.setText( 4, "0.#####" );
        break;
      case ValueMeta.TYPE_DATE:
        break;
      default:
        break;
    }
  }
  wFields.optWidth( true );
}
 
Example 10
Source File: MongoDbInputDataTest.java    From pentaho-mongodb-plugin with Apache License 2.0 4 votes vote down vote up
@Test public void testArrayUnwindOneArrayExpandFieldAndOneNormalField() throws KettleException {
  Object mongoO = JSON.parse( s_testData2 );
  assertTrue( mongoO instanceof DBObject );

  List<MongoField> fields = new ArrayList<MongoField>();

  MongoField mm = new MongoField();
  mm.m_fieldName = "test";
  mm.m_fieldPath = "$.one.two[*].rec1.f1";
  mm.m_kettleType = "String";
  fields.add( mm );

  mm = new MongoField();
  mm.m_fieldName = "test2";
  mm.m_fieldPath = "$.name";
  mm.m_kettleType = "String";
  fields.add( mm );

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

  MongoDbInputData data = new MongoDbInputData();
  data.outputRowMeta = rowMeta;
  data.setMongoFields( fields );
  data.init();
  Variables vars = new Variables();

  Object[][] result = data.mongoDocumentToKettle( (DBObject) mongoO, vars );

  assertTrue( result != null );
  assertEquals( 2, result.length );

  // each row should have two entries
  assertEquals( 2 + RowDataUtil.OVER_ALLOCATE_SIZE, result[0].length );

  // should be two rows returned due to the array expansion
  assertTrue( result[0] != null );
  assertTrue( result[1] != null );
  assertEquals( "bob", result[0][0] );
  assertEquals( "sid", result[1][0] );

  // george should be the name in both rows
  assertEquals( "george", result[0][1] );
  assertEquals( "george", result[1][1] );
}
 
Example 11
Source File: MongoDbInputDataTest.java    From pentaho-mongodb-plugin with Apache License 2.0 4 votes vote down vote up
@Test public void testArrayUnwindWithOneExistingAndOneNonExistingField() throws KettleException {
  Object mongoO = JSON.parse( s_testData2 );
  assertTrue( mongoO instanceof DBObject );

  List<MongoField> fields = new ArrayList<MongoField>();

  MongoField mm = new MongoField();
  mm.m_fieldName = "test";
  mm.m_fieldPath = "$.one.two[*].rec1.f1";
  mm.m_kettleType = "String";
  fields.add( mm );

  mm = new MongoField();
  mm.m_fieldName = "test2";
  mm.m_fieldPath = "$.one.two[*].rec6.nonExistent";
  mm.m_kettleType = "String";
  fields.add( mm );

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

  MongoDbInputData data = new MongoDbInputData();
  data.outputRowMeta = rowMeta;
  data.setMongoFields( fields );
  data.init();
  Variables vars = new Variables();

  Object[][] result = data.mongoDocumentToKettle( (DBObject) mongoO, vars );

  assertTrue( result != null );
  assertEquals( 2, result.length );

  // should be two rows returned due to the array expansion
  assertTrue( result[0] != null );
  assertTrue( result[1] != null );
  assertEquals( "bob", result[0][0] );
  assertEquals( "sid", result[1][0] );

  // each row should have two entries
  assertEquals( 2 + RowDataUtil.OVER_ALLOCATE_SIZE, result[0].length );

  // this field doesn't exist in the doc structure, so we expect null
  assertTrue( result[0][1] == null );
  assertTrue( result[1][1] == null );
}
 
Example 12
Source File: XMLField.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Injection( name = "OUTPUT_TYPE", group = "OUTPUT_FIELDS" )
public void setType( String typeDesc ) {
  this.type = ValueMeta.getType( typeDesc );
}
 
Example 13
Source File: XMLField.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Injection( name = "OUTPUT_TYPE", group = "OUTPUT_FIELDS" )
public void setType( String typeDesc ) {
  this.type = ValueMeta.getType( typeDesc );
}