Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#convertBinaryStringToNativeType()
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#convertBinaryStringToNativeType() .
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: 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; }