Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#setStringEncoding()
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#setStringEncoding() .
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: GoogleSpreadsheetInputMeta.java From pdi-google-spreadsheet-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 2
Source File: FixedInputMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
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 3
Source File: TextFileOutputMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@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 4
Source File: ValueMetaFactory.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static void cloneInfo( ValueMetaInterface source, ValueMetaInterface target ) throws KettlePluginException { target.setConversionMask( source.getConversionMask() ); target.setDecimalSymbol( source.getDecimalSymbol() ); target.setGroupingSymbol( source.getGroupingSymbol() ); target.setStorageType( source.getStorageType() ); if ( source.getStorageMetadata() != null ) { target.setStorageMetadata( cloneValueMeta( source.getStorageMetadata(), source .getStorageMetadata().getType() ) ); } target.setStringEncoding( source.getStringEncoding() ); target.setTrimType( source.getTrimType() ); target.setDateFormatLenient( source.isDateFormatLenient() ); target.setDateFormatLocale( source.getDateFormatLocale() ); target.setDateFormatTimeZone( source.getDateFormatTimeZone() ); target.setLenientStringToNumber( source.isLenientStringToNumber() ); target.setLargeTextField( source.isLargeTextField() ); target.setComments( source.getComments() ); target.setCaseInsensitive( source.isCaseInsensitive() ); target.setCollatorDisabled( source.isCollatorDisabled() ); target.setCollatorStrength( source.getCollatorStrength() ); target.setIndex( source.getIndex() ); target.setOrigin( source.getOrigin() ); target.setOriginalAutoIncrement( source.isOriginalAutoIncrement() ); target.setOriginalColumnType( source.getOriginalColumnType() ); target.setOriginalColumnTypeName( source.getOriginalColumnTypeName() ); target.setOriginalNullable( source.isOriginalNullable() ); target.setOriginalPrecision( source.getOriginalPrecision() ); target.setOriginalScale( source.getOriginalScale() ); target.setOriginalSigned( source.isOriginalSigned() ); }
Example 5
Source File: ConcatFieldsMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // do not call the super class from TextFileOutputMeta since it modifies the source meta data // see getFieldsModifyInput() instead // remove selected fields from the stream when true if ( removeSelectedFields ) { if ( getOutputFields().length > 0 ) { for ( int i = 0; i < getOutputFields().length; i++ ) { TextFileField field = getOutputFields()[ i ]; try { row.removeValueMeta( field.getName() ); } catch ( KettleValueException e ) { // just ignore exceptions since missing fields are handled in the ConcatFields class } } } else { // no output fields selected, take them all, remove them all row.clear(); } } // Check Target Field Name if ( Utils.isEmpty( targetFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "ConcatFieldsMeta.CheckResult.TargetFieldNameMissing" ) ); } // add targetFieldName ValueMetaInterface vValue = new ValueMetaString( targetFieldName ); vValue.setLength( targetFieldLength, 0 ); vValue.setOrigin( name ); if ( !Utils.isEmpty( getEncoding() ) ) { vValue.setStringEncoding( getEncoding() ); } row.addValueMeta( vValue ); }
Example 6
Source File: SelectValuesMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
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 7
Source File: SelectValues.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * 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 8
Source File: ParGzipCsvInputMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@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 9
Source File: CsvInputMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@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 ); } }