Java Code Examples for org.pentaho.di.core.row.value.ValueMetaFactory#cloneValueMeta()
The following examples show how to use
org.pentaho.di.core.row.value.ValueMetaFactory#cloneValueMeta() .
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 |
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: EnterValueDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private ValueMetaAndData getValue( String valuename ) throws KettleValueException { try { int valtype = ValueMetaFactory.getIdForValueMeta( wValueType.getText() ); ValueMetaAndData val = new ValueMetaAndData( valuename, wInputString.getText() ); ValueMetaInterface valueMeta = ValueMetaFactory.cloneValueMeta( val.getValueMeta(), valtype ); Object valueData = val.getValueData(); int formatIndex = wFormat.getSelectionIndex(); valueMeta.setConversionMask( formatIndex >= 0 ? wFormat.getItem( formatIndex ) : wFormat.getText() ); valueMeta.setLength( Const.toInt( wLength.getText(), -1 ) ); valueMeta.setPrecision( Const.toInt( wPrecision.getText(), -1 ) ); val.setValueMeta( valueMeta ); ValueMetaInterface stringValueMeta = new ValueMetaString( valuename ); stringValueMeta.setConversionMetadata( valueMeta ); Object targetData = stringValueMeta.convertDataUsingConversionMetaData( valueData ); val.setValueData( targetData ); return val; } catch ( Exception e ) { throw new KettleValueException( e ); } }
Example 3
Source File: EditRowsDialog.java From pentaho-pdi-dataset with Apache License 2.0 | 5 votes |
private void ok() { try { stringRowMeta = new RowMeta(); for ( ValueMetaInterface valueMeta : rowMeta.getValueMetaList() ) { ValueMetaInterface stringValueMeta = ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING ); stringRowMeta.addValueMeta( stringValueMeta ); } List<Object[]> list = new ArrayList<Object[]>(); // Now read all the rows in the dialog, including the empty rows... // for ( int i = 0; i < wFields.getItemCount(); i++ ) { TableItem item = wFields.getTable().getItem( i ); Object[] row = getRowForData( item, i + 1 ); list.add( row ); } outputList = list; dispose(); } catch ( Exception e ) { new ErrorDialog( shell, "Error", BaseMessages.getString( PKG, "EditRowsDialog.ErrorConvertingData" ), e ); } }
Example 4
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 5
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 6
Source File: SwitchCase.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * @see StepInterface#init(org.pentaho.di.trans.step.StepMetaInterface , org.pentaho.di.trans.step.StepDataInterface) */ public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SwitchCaseMeta) smi; data = (SwitchCaseData) sdi; if ( !super.init( smi, sdi ) ) { return false; } data.outputMap = meta.isContains() ? new ContainsKeyToRowSetMap() : new KeyToRowSetMap(); if ( Utils.isEmpty( meta.getFieldname() ) ) { logError( BaseMessages.getString( PKG, "SwitchCase.Log.NoFieldSpecifiedToSwitchWith" ) ); return false; } try { data.valueMeta = ValueMetaFactory.createValueMeta( meta.getFieldname(), meta.getCaseValueType() ); data.valueMeta.setConversionMask( meta.getCaseValueFormat() ); data.valueMeta.setGroupingSymbol( meta.getCaseValueGroup() ); data.valueMeta.setDecimalSymbol( meta.getCaseValueDecimal() ); data.stringValueMeta = ValueMetaFactory.cloneValueMeta( data.valueMeta, ValueMetaInterface.TYPE_STRING ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "SwitchCase.Log.UnexpectedError", e ) ); } return true; }
Example 7
Source File: EditRowsDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void ok() { try { stringRowMeta = new RowMeta(); for ( ValueMetaInterface valueMeta : rowMeta.getValueMetaList() ) { ValueMetaInterface stringValueMeta = ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING ); stringRowMeta.addValueMeta( stringValueMeta ); } List<Object[]> list = new ArrayList<Object[]>(); // Now read all the rows in the dialog, including the empty rows... // for ( int i = 0; i < wFields.getItemCount(); i++ ) { TableItem item = wFields.getTable().getItem( i ); Object[] row = getRowForData( item, i + 1 ); list.add( row ); } outputList = list; dispose(); } catch ( Exception e ) { new ErrorDialog( shell, "Error", BaseMessages.getString( PKG, "EditRowsDialog.ErrorConvertingData" ), e ); } }
Example 8
Source File: Validator.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected ValueMetaInterface cloneValueMeta( ValueMetaInterface valueMeta, int type ) throws KettlePluginException { return ValueMetaFactory.cloneValueMeta( valueMeta, type ); }
Example 9
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 10
Source File: ScriptValuesMetaMod.java From pentaho-kettle with Apache License 2.0 | 4 votes |
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 11
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 12
Source File: TableInputMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; // TODO: throw an exception here } if ( cachedRowMetaActive ) { row.addRowMeta( cachedRowMeta ); return; } boolean param = false; Database db = getDatabase(); super.databases = new Database[] { db }; // keep track of it for canceling purposes... // First try without connecting to the database... (can be S L O W) String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { attachOrigin( add, origin ); row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length > 0 && info[ 0 ] != null ) { paramRowMeta = info[ 0 ]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } attachOrigin( add, origin ); row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } }
Example 13
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 ); } }