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

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setCurrencySymbol() . 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: DataGridMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
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++ ) {
    try {
      if ( !Utils.isEmpty( fieldName[i] ) ) {
        int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] );
        if ( type == ValueMetaInterface.TYPE_NONE ) {
          type = ValueMetaInterface.TYPE_STRING;
        }
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type );
        v.setLength( fieldLength[i] );
        v.setPrecision( fieldPrecision[i] );
        v.setOrigin( name );
        v.setConversionMask( fieldFormat[i] );
        v.setCurrencySymbol( currency[i] );
        v.setGroupingSymbol( group[i] );
        v.setDecimalSymbol( decimal[i] );

        rowMeta.addValueMeta( v );
      }
    } catch ( Exception e ) {
      throw new KettleStepException( "Unable to create value of type " + fieldType[i], e );
    }
  }
}
 
Example 2
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 3
Source File: CalculatorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ValueMetaInterface getValueMeta( CalculatorMetaFunction fn, String origin ) {
  ValueMetaInterface v;
  // What if the user didn't specify a data type?
  // In that case we look for the default data type
  //
  int defaultResultType = fn.getValueType();
  if ( defaultResultType == ValueMetaInterface.TYPE_NONE ) {
    defaultResultType = CalculatorMetaFunction.getCalcFunctionDefaultResultType( fn.getCalcType() );
  }
  try {
    v = ValueMetaFactory.createValueMeta( fn.getFieldName(), defaultResultType );
  } catch ( Exception ex ) {
    return null;
  }
  v.setLength( fn.getValueLength() );
  v.setPrecision( fn.getValuePrecision() );
  v.setOrigin( origin );
  v.setComments( fn.getCalcTypeDesc() );
  v.setConversionMask( fn.getConversionMask() );
  v.setDecimalSymbol( fn.getDecimalSymbol() );
  v.setGroupingSymbol( fn.getGroupingSymbol() );
  v.setCurrencySymbol( fn.getCurrencySymbol() );

  return v;
}
 
Example 4
Source File: JsonInputField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public ValueMetaInterface toValueMeta( String fieldOriginStepName, VariableSpace vspace ) throws KettlePluginException {
  int type = getType();
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    type = ValueMetaInterface.TYPE_STRING;
  }
  ValueMetaInterface v =
      ValueMetaFactory.createValueMeta( vspace != null ? vspace.environmentSubstitute( getName() ) : getName(), type );
  v.setLength( getLength() );
  v.setPrecision( getPrecision() );
  v.setOrigin( fieldOriginStepName );
  v.setConversionMask( getFormat() );
  v.setDecimalSymbol( getDecimalSymbol() );
  v.setGroupingSymbol( getGroupSymbol() );
  v.setCurrencySymbol( getCurrencySymbol() );
  v.setTrimType( getTrimType() );
  return v;
}
 
Example 5
Source File: GoogleSpreadsheetInputMeta.java    From pdi-google-spreadsheet-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        inputRowMeta.clear(); // Start with a clean slate, eats the input

        for (TextFileInputField field : inputFields) {
            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());
            valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            valueMeta.setDateFormatLenient(true);
            valueMeta.setStringEncoding("UTF-8");

            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(name);

            inputRowMeta.addValueMeta(valueMeta);
        }
    } catch (Exception e) {

    }
}
 
Example 6
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 7
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 8
Source File: TextFileOutputMeta.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 {
  // No values are added to the row in this type of step
  // However, in case of Fixed length records,
  // the field precisions and lengths are altered!

  for ( int i = 0; i < outputFields.length; i++ ) {
    TextFileField field = outputFields[i];
    ValueMetaInterface v = row.searchValueMeta( field.getName() );
    if ( v != null ) {
      v.setLength( field.getLength() );
      v.setPrecision( field.getPrecision() );
      if ( field.getFormat() != null ) {
        v.setConversionMask( field.getFormat() );
      }
      v.setDecimalSymbol( field.getDecimalSymbol() );
      v.setGroupingSymbol( field.getGroupingSymbol() );
      v.setCurrencySymbol( field.getCurrencySymbol() );
      v.setOutputPaddingEnabled( isPadded() );
      v.setTrimType( field.getTrimType() );
      if ( !Utils.isEmpty( getEncoding() ) ) {
        v.setStringEncoding( getEncoding() );
      }

      // enable output padding by default to be compatible with v2.5.x
      //
      v.setOutputPaddingEnabled( true );
    }
  }
}
 
Example 9
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 );
        }
      }
    }
  }
}
 
Example 10
Source File: SelectValues.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Change the meta-data of certain fields.
 * <p/>
 * This, we can do VERY fast.
 * <p/>
 *
 * @param row The row to manipulate
 * @return the altered RowData array
 * @throws KettleValueException
 */
@VisibleForTesting
synchronized Object[] metadataValues( RowMetaInterface rowMeta, Object[] rowData ) throws KettleException {
  if ( data.firstmetadata ) {
    data.firstmetadata = false;

    data.metanrs = new int[ meta.getMeta().length ];
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      data.metanrs[ i ] = rowMeta.indexOfValue( meta.getMeta()[ i ].getName() );
      if ( data.metanrs[ i ] < 0 ) {
        logError( BaseMessages
          .getString( PKG, "SelectValues.Log.CouldNotFindField", meta.getMeta()[ i ].getName() ) );
        setErrors( 1 );
        stopAll();
        return null;
      }
    }

    // Check for doubles in the selected fields...
    int[] cnt = new int[ meta.getMeta().length ];
    for ( int i = 0; i < meta.getMeta().length; i++ ) {
      cnt[ i ] = 0;
      for ( int j = 0; j < meta.getMeta().length; j++ ) {
        if ( meta.getMeta()[ i ].getName().equals( meta.getMeta()[ j ].getName() ) ) {
          cnt[ i ]++;
        }

        if ( cnt[ i ] > 1 ) {
          logError( BaseMessages.getString( PKG, "SelectValues.Log.FieldCouldNotSpecifiedMoreThanTwice2", meta
            .getMeta()[ i ].getName() ) );
          setErrors( 1 );
          stopAll();
          return null;
        }
      }
    }

    // Also apply the metadata on the row meta to allow us to convert the data correctly, with the correct mask.
    //
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      SelectMetadataChange change = meta.getMeta()[ i ];
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( data.metanrs[ i ] );
      if ( !Utils.isEmpty( change.getConversionMask() ) ) {
        valueMeta.setConversionMask( change.getConversionMask() );
      }

      valueMeta.setDateFormatLenient( change.isDateFormatLenient() );
      valueMeta.setDateFormatLocale( EnvUtil.createLocale( change.getDateFormatLocale() ) );
      valueMeta.setDateFormatTimeZone( EnvUtil.createTimeZone( change.getDateFormatTimeZone() ) );
      valueMeta.setLenientStringToNumber( change.isLenientStringToNumber() );

      if ( !Utils.isEmpty( change.getEncoding() ) ) {
        valueMeta.setStringEncoding( change.getEncoding() );
      }
      if ( !Utils.isEmpty( change.getDecimalSymbol() ) ) {
        valueMeta.setDecimalSymbol( change.getDecimalSymbol() );
      }
      if ( !Utils.isEmpty( change.getGroupingSymbol() ) ) {
        valueMeta.setGroupingSymbol( change.getGroupingSymbol() );
      }
      if ( !Utils.isEmpty( change.getCurrencySymbol() ) ) {
        valueMeta.setCurrencySymbol( change.getCurrencySymbol() );
      }
    }
  }

  //
  // Change the data too
  //
  for ( int i = 0; i < data.metanrs.length; i++ ) {
    int index = data.metanrs[ i ];
    ValueMetaInterface fromMeta = rowMeta.getValueMeta( index );
    ValueMetaInterface toMeta = data.metadataRowMeta.getValueMeta( index );

    // If we need to change from BINARY_STRING storage type to NORMAL...
    //
    try {
      if ( fromMeta.isStorageBinaryString()
        && meta.getMeta()[ i ].getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ) {
        rowData[ index ] = fromMeta.convertBinaryStringToNativeType( (byte[]) rowData[ index ] );
      }
      if ( meta.getMeta()[ i ].getType() != ValueMetaInterface.TYPE_NONE && fromMeta.getType() != toMeta.getType() ) {
        rowData[ index ] = toMeta.convertData( fromMeta, rowData[ index ] );
      }
    } catch ( KettleValueException e ) {
      throw new KettleConversionException( e.getMessage(), Collections.<Exception>singletonList( e ),
        Collections.singletonList( toMeta ), rowData );
    }
  }

  return rowData;
}
 
Example 11
Source File: ParGzipCsvInputMeta.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 12
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 13
Source File: GetVariableMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Determine the maximum length...
  //
  int length = -1;
  for ( int i = 0; i < fieldDefinitions.length; i++ ) {
    String variableString = fieldDefinitions[i].getVariableString();
    if ( variableString != null ) {
      String string = space.environmentSubstitute( variableString );
      if ( string.length() > length ) {
        length = string.length();
      }
    }
  }

  RowMetaInterface row = new RowMeta();
  for ( int i = 0; i < fieldDefinitions.length; i++ ) {
    ValueMetaInterface v;
    try {
      v = ValueMetaFactory.createValueMeta( fieldDefinitions[i].getFieldName(), fieldDefinitions[i].getFieldType() );
    } catch ( KettlePluginException e ) {
      throw new KettleStepException( e );
    }
    int fieldLength = fieldDefinitions[i].getFieldLength();
    if ( fieldLength < 0 ) {
      v.setLength( length );
    } else {
      v.setLength( fieldLength );
    }
    int fieldPrecision = fieldDefinitions[i].getFieldPrecision();
    if ( fieldPrecision >= 0 ) {
      v.setPrecision( fieldPrecision );
    }
    v.setConversionMask( fieldDefinitions[i].getFieldFormat() );
    v.setGroupingSymbol( fieldDefinitions[i].getGroup() );
    v.setDecimalSymbol( fieldDefinitions[i].getDecimal() );
    v.setCurrencySymbol( fieldDefinitions[i].getCurrency() );
    v.setTrimType( fieldDefinitions[i].getTrimType() );
    v.setOrigin( name );

    row.addValueMeta( v );
  }

  inputRowMeta.mergeRowMeta( row, name );
}
 
Example 14
Source File: S3CsvInputMeta.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 {
  rowMeta.clear(); // Start with a clean slate, eats the input

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

    ValueMetaInterface valueMeta = new ValueMeta( 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 );
    }

    // 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 = valueMeta.clone();
    storageMetadata.setType( 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 );
  }
}