Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#setOrigin()

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setOrigin() . 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: RegexEvalMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ValueMetaInterface constructValueMeta( ValueMetaInterface sourceValueMeta, String fieldName, int i,
  String name ) throws KettlePluginException {
  int type = fieldType[i];
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    type = ValueMetaInterface.TYPE_STRING;
  }
  ValueMetaInterface v;
  if ( sourceValueMeta == null ) {
    v = ValueMetaFactory.createValueMeta( fieldName, type );
  } else {
    v = ValueMetaFactory.cloneValueMeta( sourceValueMeta, type );
  }
  v.setLength( fieldLength[i] );
  v.setPrecision( fieldPrecision[i] );
  v.setOrigin( name );
  v.setConversionMask( fieldFormat[i] );
  v.setDecimalSymbol( fieldDecimal[i] );
  v.setGroupingSymbol( fieldGroup[i] );
  v.setCurrencySymbol( fieldCurrency[i] );
  v.setTrimType( fieldTrimType[i] );

  return v;
}
 
Example 2
Source File: OlapInputMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  RowMetaInterface add = null;

  try {
    initData( space );

    add = data.outputRowMeta;
  } catch ( Exception dbe ) {
    throw new KettleStepException( "Unable to get query result for MDX query: " + Const.CR + mdx, dbe );
  }

  // Set the origin
  //
  for ( int i = 0; i < add.size(); i++ ) {
    ValueMetaInterface v = add.getValueMeta( i );
    v.setOrigin( origin );
  }

  row.addRowMeta( add );
}
 
Example 3
Source File: RowGeneratorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
    RowMetaAndData rowMetaAndData = RowGenerator.buildRow( this, remarks, origin );
    if ( !remarks.isEmpty() ) {
      StringBuilder stringRemarks = new StringBuilder();
      for ( CheckResultInterface remark : remarks ) {
        stringRemarks.append( remark.toString() ).append( Const.CR );
      }
      throw new KettleStepException( stringRemarks.toString() );
    }

    for ( ValueMetaInterface valueMeta : rowMetaAndData.getRowMeta().getValueMetaList() ) {
      valueMeta.setOrigin( origin );
    }

    row.mergeRowMeta( rowMetaAndData.getRowMeta() );
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example 4
Source File: KafkaConsumerMeta.java    From pentaho-kafka-consumer with Apache License 2.0 6 votes vote down vote up
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
                      VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {

    try {
        ValueMetaInterface fieldValueMeta = ValueMetaFactory.createValueMeta(getField(), ValueMetaInterface.TYPE_BINARY);
        fieldValueMeta.setOrigin(origin);
        rowMeta.addValueMeta(fieldValueMeta);

        ValueMetaInterface keyFieldValueMeta = ValueMetaFactory.createValueMeta(getKeyField(), ValueMetaInterface.TYPE_BINARY);
        keyFieldValueMeta.setOrigin(origin);
        rowMeta.addValueMeta(keyFieldValueMeta);

    } catch (KettlePluginException e) {
        throw new KettleStepException("KafkaConsumerMeta.Exception.getFields", e);
    }

}
 
Example 5
Source File: BaseFileInputStepUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Adds <code>String</code> value meta with given name if not present and returns index
 *
 * @param rowMeta
 * @param fieldName
 * @return Index in row meta of value meta with <code>fieldName</code>
 */
public static int addValueMeta( String stepName, RowMetaInterface rowMeta, String fieldName ) {
  ValueMetaInterface valueMeta = new ValueMetaString( fieldName );
  valueMeta.setOrigin( stepName );
  // add if doesn't exist
  int index = -1;
  if ( !rowMeta.exists( valueMeta ) ) {
    index = rowMeta.size();
    rowMeta.addValueMeta( valueMeta );
  } else {
    index = rowMeta.indexOfValue( fieldName );
  }
  return index;
}
 
Example 6
Source File: FileLockedMeta.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 {
  if ( !Utils.isEmpty( resultfieldname ) ) {
    ValueMetaInterface v = new ValueMetaBoolean( resultfieldname );
    v.setOrigin( name );
    inputRowMeta.addValueMeta( v );
  }
}
 
Example 7
Source File: FixedInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    for ( int i = 0; i < fieldDefinition.length; i++ ) {
      FixedFileInputField field = fieldDefinition[i];

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getName(), field.getType() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setTrimType( field.getTrimType() );
      valueMeta.setLength( field.getLength() );
      valueMeta.setPrecision( field.getPrecision() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setDecimalSymbol( field.getDecimal() );
      valueMeta.setGroupingSymbol( field.getGrouping() );
      valueMeta.setCurrencySymbol( field.getCurrency() );
      valueMeta.setStringEncoding( space.environmentSubstitute( encoding ) );
      if ( lazyConversionActive ) {
        valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
      }

      // In case we want to convert Strings...
      //
      ValueMetaInterface storageMetadata =
        ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING );
      storageMetadata.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

      valueMeta.setStorageMetadata( storageMetadata );

      valueMeta.setOrigin( origin );

      rowMeta.addValueMeta( valueMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example 8
Source File: FieldSplitterMeta.java    From pentaho-kettle with 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 {
  // Remove the field to split
  int idx = r.indexOfValue( getSplitField() );
  if ( idx < 0 ) { // not found
    throw new RuntimeException( BaseMessages.getString(
      PKG, "FieldSplitter.Log.CouldNotFindFieldToSplit", getSplitField() ) );
  }

  // Add the new fields at the place of the index --> replace!
  int count = getFieldsCount();
  for ( int i = 0; i < count; i++ ) {
    try {
      final ValueMetaInterface v = ValueMetaFactory.createValueMeta( getFieldName()[i], getFieldType()[i] );
      v.setLength( getFieldLength()[i], getFieldPrecision()[i] );
      v.setOrigin( name );
      v.setConversionMask( getFieldFormat()[i] );
      v.setDecimalSymbol( getFieldDecimal()[i] );
      v.setGroupingSymbol( getFieldGroup()[i] );
      v.setCurrencySymbol( getFieldCurrency()[i] );
      v.setTrimType( getFieldTrimType()[i] );
      // TODO when implemented in UI
      // v.setDateFormatLenient(dateFormatLenient);
      // TODO when implemented in UI
      // v.setDateFormatLocale(dateFormatLocale);
      if ( i == 0 && idx >= 0 ) {
        // the first valueMeta (splitField) will be replaced
        r.setValueMeta( idx, v );
      } else {
        // other valueMeta will be added
        if ( idx >= r.size() ) {
          r.addValueMeta( v );
        }
        r.addValueMeta( idx + i, v );
      }
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example 9
Source File: GetSlaveSequenceMeta.java    From pentaho-kettle with 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 {
  ValueMetaInterface v = new ValueMetaInteger( valuename );
  v.setOrigin( name );
  row.addValueMeta( v );
}
 
Example 10
Source File: WebServiceAvailableMeta.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 {

  if ( !Utils.isEmpty( resultfieldname ) ) {
    ValueMetaInterface v = new ValueMetaBoolean( resultfieldname );
    v.setOrigin( name );
    inputRowMeta.addValueMeta( v );
  }

}
 
Example 11
Source File: TableOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
                       VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Just add the returning key field...
  if ( returningGeneratedKeys && generatedKeyField != null && generatedKeyField.length() > 0 ) {
    ValueMetaInterface key =
      new ValueMetaInteger( space.environmentSubstitute( generatedKeyField ) );
    key.setOrigin( origin );
    row.addValueMeta( key );
  }
}
 
Example 12
Source File: NumberRangeMeta.java    From pentaho-kettle with 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 {
  ValueMetaInterface mcValue = new ValueMetaString( outputField );
  mcValue.setOrigin( name );
  mcValue.setLength( 255 );
  row.addValueMeta( mcValue );
}
 
Example 13
Source File: JsonOutputMeta.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 {

  if ( getOperationType() != OPERATION_TYPE_WRITE_TO_FILE ) {
    ValueMetaInterface v =
        new ValueMetaString( space.environmentSubstitute( this.getOutputValue() ) );
    v.setOrigin( name );
    row.addValueMeta( v );
  }
}
 
Example 14
Source File: WebServiceMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Input rows and output rows are different in the webservice step
  //
  if ( !isPassingInputData() ) {
    r.clear();
  }

  // Add the output fields...
  //
  for ( WebServiceField field : getFieldsOut() ) {
    int valueType = field.getType();

    // If the type is unrecognized we give back the XML as a String...
    //
    if ( field.getType() == ValueMetaInterface.TYPE_NONE ) {
      valueType = ValueMetaInterface.TYPE_STRING;
    }

    try {
      ValueMetaInterface vValue = ValueMetaFactory.createValueMeta( field.getName(), valueType );
      vValue.setOrigin( name );
      r.addValueMeta( vValue );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example 15
Source File: ShapeFileReaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
                       VariableSpace space ) throws KettleStepException {

  // The filename...
  ValueMetaInterface filename = new ValueMeta( "filename", ValueMetaInterface.TYPE_STRING );
  filename.setOrigin( name );
  filename.setLength( 255 );
  row.addValueMeta( filename );

  // The file type
  ValueMetaInterface ft = new ValueMeta( "filetype", ValueMetaInterface.TYPE_STRING );
  ft.setLength( 50 );
  ft.setOrigin( name );
  row.addValueMeta( ft );

  // The shape nr
  ValueMetaInterface shnr = new ValueMeta( "shapenr", ValueMetaInterface.TYPE_INTEGER );
  shnr.setOrigin( name );
  row.addValueMeta( shnr );

  // The part nr
  ValueMetaInterface pnr = new ValueMeta( "partnr", ValueMetaInterface.TYPE_INTEGER );
  pnr.setOrigin( name );
  row.addValueMeta( pnr );

  // The part nr
  ValueMetaInterface nrp = new ValueMeta( "nrparts", ValueMetaInterface.TYPE_INTEGER );
  nrp.setOrigin( name );
  row.addValueMeta( nrp );

  // The point nr
  ValueMetaInterface ptnr = new ValueMeta( "pointnr", ValueMetaInterface.TYPE_INTEGER );
  ptnr.setOrigin( name );
  row.addValueMeta( ptnr );

  // The nr of points
  ValueMetaInterface nrpt = new ValueMeta( "nrpointS", ValueMetaInterface.TYPE_INTEGER );
  nrpt.setOrigin( name );
  row.addValueMeta( nrpt );

  // The X coordinate
  ValueMetaInterface x = new ValueMeta( "x", ValueMetaInterface.TYPE_NUMBER );
  x.setOrigin( name );
  row.addValueMeta( x );

  // The Y coordinate
  ValueMetaInterface y = new ValueMeta( "y", ValueMetaInterface.TYPE_NUMBER );
  y.setOrigin( name );
  row.addValueMeta( y );

  // The measure
  ValueMetaInterface m = new ValueMeta( "measure", ValueMetaInterface.TYPE_NUMBER );
  m.setOrigin( name );
  row.addValueMeta( m );

  String dbFilename = getDbfFilename();
  if ( dbFilename != null ) {
    if ( space != null ) {
      dbFilename = space.environmentSubstitute( dbFilename );
      if ( dbFilename.startsWith( "file:" ) ) {
        dbFilename = dbFilename.substring( 5 );
      }
    }

    XBase xbase = new XBase( getLog(), dbFilename );
    try {
      xbase.setDbfFile( dbFilename );
      xbase.open();

      //Set encoding
      if ( StringUtils.isNotBlank( encoding ) ) {
        xbase.getReader().setCharactersetName( encoding );
      }

      RowMetaInterface fields = xbase.getFields();
      for ( int i = 0; i < fields.size(); i++ ) {
        fields.getValueMeta( i ).setOrigin( name );
        row.addValueMeta( fields.getValueMeta( i ) );
      }

    } catch ( Throwable e ) {
      throw new KettleStepException( "Unable to read from DBF file", e );
    } finally {
      xbase.close();
    }
  } else {
    throw new KettleStepException( "Unable to read from DBF file: no filename specfied" );
  }
}
 
Example 16
Source File: ScriptValuesMetaMod.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    for ( int i = 0; i < fieldname.length; i++ ) {
      if ( !Utils.isEmpty( fieldname[i] ) ) {
        int valueIndex = -1;
        ValueMetaInterface v;
        if ( replace[i] ) {
          valueIndex = row.indexOfValue( fieldname[i] );
          if ( valueIndex < 0 ) {
            // The field was not found using the "name" field
            if ( Utils.isEmpty( rename[i] ) ) {
              // There is no "rename" field to try; Therefore we cannot find the
              // field to replace
              throw new KettleStepException( BaseMessages.getString(
                PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", fieldname[i] ) );
            } else {
              // Lookup the field to replace using the "rename" field
              valueIndex = row.indexOfValue( rename[i] );
              if ( valueIndex < 0 ) {
                // The field was not found using the "rename" field"; Therefore
                // we cannot find the field to replace
                //
                throw new KettleStepException( BaseMessages.getString(
                  PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", rename[i] ) );
              }
            }
          }

          // Change the data type to match what's specified...
          //
          ValueMetaInterface source = row.getValueMeta( valueIndex );
          v = ValueMetaFactory.cloneValueMeta( source, type[i] );
          row.setValueMeta( valueIndex, v );
        } else {
          if ( !Utils.isEmpty( rename[i] ) ) {
            v = ValueMetaFactory.createValueMeta( rename[i], type[i] );
          } else {
            v = ValueMetaFactory.createValueMeta( fieldname[i], type[i] );
          }
        }
        v.setLength( length[i] );
        v.setPrecision( precision[i] );
        v.setOrigin( originStepname );
        if ( !replace[i] ) {
          row.addValueMeta( v );
        }
      }
    }
  } catch ( KettleException e ) {
    throw new KettleStepException( e );
  }
}
 
Example 17
Source File: CsvInputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    rowMeta.clear(); // Start with a clean slate, eats the input

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

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getName(), field.getType() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setLength( field.getLength() );
      valueMeta.setPrecision( field.getPrecision() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setDecimalSymbol( field.getDecimalSymbol() );
      valueMeta.setGroupingSymbol( field.getGroupSymbol() );
      valueMeta.setCurrencySymbol( field.getCurrencySymbol() );
      valueMeta.setTrimType( field.getTrimType() );
      if ( lazyConversionActive ) {
        valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
      }
      valueMeta.setStringEncoding( space.environmentSubstitute( encoding ) );

      // In case we want to convert Strings...
      // Using a copy of the valueMeta object means that the inner and outer representation format is the same.
      // Preview will show the data the same way as we read it.
      // This layout is then taken further down the road by the metadata through the transformation.
      //
      ValueMetaInterface storageMetadata =
        ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING );
      storageMetadata.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
      storageMetadata.setLength( -1, -1 ); // we don't really know the lengths of the strings read in advance.
      valueMeta.setStorageMetadata( storageMetadata );

      valueMeta.setOrigin( origin );

      rowMeta.addValueMeta( valueMeta );
    }

    if ( !Utils.isEmpty( filenameField ) && includingFilename ) {
      ValueMetaInterface filenameMeta = new ValueMetaString( filenameField );
      filenameMeta.setOrigin( origin );
      if ( lazyConversionActive ) {
        filenameMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
        filenameMeta.setStorageMetadata( new ValueMetaString( filenameField ) );
      }
      rowMeta.addValueMeta( filenameMeta );
    }

    if ( !Utils.isEmpty( rowNumField ) ) {
      ValueMetaInterface rowNumMeta = new ValueMetaInteger( rowNumField );
      rowNumMeta.setLength( 10 );
      rowNumMeta.setOrigin( origin );
      rowMeta.addValueMeta( rowNumMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }

}
 
Example 18
Source File: ScriptMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  for ( int i = 0; i < fieldname.length; i++ ) {
    if ( !Utils.isEmpty( fieldname[i] ) ) {
      String fieldName;
      int replaceIndex;
      int fieldType;

      if ( replace[i] ) {
        // Look up the field to replace...
        //
        if ( row.searchValueMeta( fieldname[i] ) == null && Utils.isEmpty( rename[i] ) ) {
          throw new KettleStepException( BaseMessages.getString(
            PKG, "ScriptMeta.Exception.FieldToReplaceNotFound", fieldname[i] ) );
        }
        replaceIndex = row.indexOfValue( rename[i] );

        // Change the data type to match what's specified...
        //
        fieldType = type[i];
        fieldName = rename[i];
      } else {
        replaceIndex = -1;
        fieldType = type[i];
        if ( rename[i] != null && rename[i].length() != 0 ) {
          fieldName = rename[i];
        } else {
          fieldName = fieldname[i];
        }
      }
      try {
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName, fieldType );
        v.setLength( length[i] );
        v.setPrecision( precision[i] );
        v.setOrigin( originStepname );
        if ( replace[i] && replaceIndex >= 0 ) {
          row.setValueMeta( replaceIndex, v );
        } else {
          row.addValueMeta( v );
        }
      } catch ( KettlePluginException e ) {
        // Ignore errors
      }
    }
  }
}
 
Example 19
Source File: StepMetastructureMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // we create a new output row structure - clear r
  r.clear();

  this.setDefault();
  // create the new fields
  // Position
  ValueMetaInterface positionFieldValue = new ValueMetaInteger( positionName );
  positionFieldValue.setOrigin( name );
  r.addValueMeta( positionFieldValue );
  // field name
  ValueMetaInterface nameFieldValue = new ValueMetaString( fieldName );
  nameFieldValue.setOrigin( name );
  r.addValueMeta( nameFieldValue );
  // comments
  ValueMetaInterface commentsFieldValue = new ValueMetaString( comments );
  nameFieldValue.setOrigin( name );
  r.addValueMeta( commentsFieldValue );
  // Type
  ValueMetaInterface typeFieldValue = new ValueMetaString( typeName );
  typeFieldValue.setOrigin( name );
  r.addValueMeta( typeFieldValue );
  // Length
  ValueMetaInterface lengthFieldValue = new ValueMetaInteger( lengthName );
  lengthFieldValue.setOrigin( name );
  r.addValueMeta( lengthFieldValue );
  // Precision
  ValueMetaInterface precisionFieldValue = new ValueMetaInteger( precisionName );
  precisionFieldValue.setOrigin( name );
  r.addValueMeta( precisionFieldValue );
  // Origin
  ValueMetaInterface originFieldValue = new ValueMetaString( originName );
  originFieldValue.setOrigin( name );
  r.addValueMeta( originFieldValue );

  if ( isOutputRowcount() ) {
    // RowCount
    ValueMetaInterface v = new ValueMetaInteger( this.getRowcountField() );
    v.setOrigin( name );
    r.addValueMeta( v );
  }

}
 
Example 20
Source File: SelectValuesMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ) throws KettlePluginException {
  if ( meta != null && meta.length > 0 ) {
    // METADATA mode: change the meta-data of the values mentioned...

    for ( int i = 0; i < meta.length; i++ ) {
      SelectMetadataChange metaChange = meta[i];

      int idx = inputRowMeta.indexOfValue( metaChange.getName() );
      boolean metaTypeChangeUsesNewTypeDefaults = false; // Normal behavior as of 5.x or so
      if ( space != null ) {
        metaTypeChangeUsesNewTypeDefaults = ValueMetaBase.convertStringToBoolean(
            space.getVariable( Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "N" ) );
      }
      if ( idx >= 0 ) { // We found the value

        // This is the value we need to change:
        ValueMetaInterface v = inputRowMeta.getValueMeta( idx );

        // Do we need to rename ?
        if ( !v.getName().equals( metaChange.getRename() ) && !Utils.isEmpty( metaChange.getRename() ) ) {
          v.setName( metaChange.getRename() );
          v.setOrigin( name );
          // need to reinsert to check name conflicts
          inputRowMeta.setValueMeta( idx, v );
        }
        // Change the type?
        if ( metaChange.getType() != ValueMetaInterface.TYPE_NONE && v.getType() != metaChange.getType() ) {
          // Fix for PDI-16388 - clone copies over the conversion mask instead of using the default for the new type
          if ( !metaTypeChangeUsesNewTypeDefaults ) {
            v = ValueMetaFactory.cloneValueMeta( v, metaChange.getType() );
          } else {
            v = ValueMetaFactory.createValueMeta( v.getName(), metaChange.getType() );
          }

          // This is now a copy, replace it in the row!
          //
          inputRowMeta.setValueMeta( idx, v );

          // This also moves the data to normal storage type
          //
          v.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
        }
        if ( metaChange.getLength() != UNDEFINED ) {
          v.setLength( metaChange.getLength() );
          v.setOrigin( name );
        }
        if ( metaChange.getPrecision() != UNDEFINED ) {
          v.setPrecision( metaChange.getPrecision() );
          v.setOrigin( name );
        }
        if ( metaChange.getStorageType() >= 0 ) {
          v.setStorageType( metaChange.getStorageType() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getConversionMask() ) ) {
          v.setConversionMask( metaChange.getConversionMask() );
          v.setOrigin( name );
        }

        v.setDateFormatLenient( metaChange.isDateFormatLenient() );
        v.setDateFormatLocale( EnvUtil.createLocale( metaChange.getDateFormatLocale() ) );
        v.setDateFormatTimeZone( EnvUtil.createTimeZone( metaChange.getDateFormatTimeZone() ) );
        v.setLenientStringToNumber( metaChange.isLenientStringToNumber() );

        if ( !Utils.isEmpty( metaChange.getEncoding() ) ) {
          v.setStringEncoding( metaChange.getEncoding() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getDecimalSymbol() ) ) {
          v.setDecimalSymbol( metaChange.getDecimalSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getGroupingSymbol() ) ) {
          v.setGroupingSymbol( metaChange.getGroupingSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getCurrencySymbol() ) ) {
          v.setCurrencySymbol( metaChange.getCurrencySymbol() );
          v.setOrigin( name );
        }
      }
    }
  }
}