/** * Default constructor. */ public PGBulkLoaderData() { super(); db = null; // Let's use ISO 8601 format. This in unambiguous with PostgreSQL dateMeta = new ValueMetaDate( "date" ); dateMeta.setConversionMask( "yyyy-MM-dd" ); dateTimeMeta = new ValueMetaDate( "date" ); // Let's keep milliseconds. Didn't find a way to keep microseconds (max resolution with PG) dateTimeMeta.setConversionMask( "yyyy-MM-dd HH:mm:ss.SSS" ); } }
/** * Get the metadata used for conversion to date format See related PDI-4019 * * @param mask * @return */ private ValueMetaInterface getConversionMeta( String mask ) { ValueMetaInterface meta = null; if ( !Utils.isEmpty( mask ) ) { meta = conversionMetaCache.get( mask ); if ( meta == null ) { meta = new ValueMetaDate(); meta.setConversionMask( mask ); conversionMetaCache.put( mask, meta ); } } return meta; }
public void replaceNull( Object[] row, ValueMetaInterface sourceValueMeta, int i, String realReplaceByValue, String realconversionMask, boolean setEmptystring ) throws Exception { if ( setEmptystring ) { row[i] = StringUtil.EMPTY_STRING; } else { // DO CONVERSION OF THE DEFAULT VALUE ... // Entered by user ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( i ); if ( !Utils.isEmpty( realconversionMask ) ) { sourceValueMeta.setConversionMask( realconversionMask ); } row[i] = targetValueMeta.convertData( sourceValueMeta, realReplaceByValue ); } }
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++ ) { if ( fieldName[i] != null && fieldName[i].length() != 0 ) { int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] ); if ( type == ValueMetaInterface.TYPE_NONE ) { type = ValueMetaInterface.TYPE_STRING; } try { ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type ); v.setLength( fieldLength[i] ); v.setPrecision( fieldPrecision[i] ); v.setOrigin( name ); v.setConversionMask( fieldFormat[i] ); rowMeta.addValueMeta( v ); } catch ( Exception e ) { throw new KettleStepException( e ); } } } }
public StringEvaluationResult build() { ValueMetaInterface meta = new ValueMeta( name, type ); meta.setConversionMask( format ); meta.setTrimType( trimType ); meta.setDecimalSymbol( decimalSymbol ); meta.setGroupingSymbol( groupingSymbol ); meta.setLength( length ); meta.setPrecision( precision ); return new StringEvaluationResult( meta ); }
data.bulkTimestampMeta.setConversionMask( "yyyy-MM-dd HH:mm:ss" ); data.bulkTimestampMeta.setStringEncoding( realEncoding ); data.bulkDateMeta.setConversionMask( "yyyy-MM-dd" ); data.bulkDateMeta.setStringEncoding( realEncoding ); data.bulkNumberMeta.setConversionMask( "#.#" ); data.bulkNumberMeta.setGroupingSymbol( "," ); data.bulkNumberMeta.setDecimalSymbol( "." );
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 ); } }
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; }
@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 ); } } }
private void updateField( Object[] r ) throws Exception { // Loop through fields for ( int i = 0; i < data.getFieldnr(); i++ ) { // DO CONVERSION OF THE DEFAULT VALUE ... // Entered by user ValueMetaInterface targetValueMeta = data.getOutputRowMeta().getValueMeta( data.getFieldnrs()[i] ); ValueMetaInterface sourceValueMeta = data.getConvertRowMeta().getValueMeta( data.getFieldnrs()[i] ); if ( !Utils.isEmpty( meta.getField( i ).getReplaceMask() ) ) { sourceValueMeta.setConversionMask( meta.getField( i ).getReplaceMask() ); } sourceValueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); r[data.getFieldnrs()[i]] = targetValueMeta.convertData( sourceValueMeta, data.getRealReplaceByValues()[i] ); targetValueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); } }
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() );
@Override public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { for ( SasInputField field : outputFields ) { try { ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getRename(), field.getType() ); valueMeta.setLength( field.getLength(), field.getPrecision() ); valueMeta.setDecimalSymbol( field.getDecimalSymbol() ); valueMeta.setGroupingSymbol( field.getGroupingSymbol() ); valueMeta.setConversionMask( field.getConversionMask() ); valueMeta.setTrimType( field.getTrimType() ); valueMeta.setOrigin( name ); row.addValueMeta( valueMeta ); } catch ( Exception e ) { throw new KettleStepException( e ); } } }
@Override public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // Add new field? for ( int i = 0; i < fieldOutStream.length; i++ ) { if ( !Utils.isEmpty( fieldOutStream[i] ) ) { int index = inputRowMeta.indexOfValue( fieldInStream[i] ); if ( index >= 0 ) { ValueMetaInterface in = inputRowMeta.getValueMeta( index ); try { ValueMetaInterface v = ValueMetaFactory.createValueMeta( space.environmentSubstitute( fieldOutStream[i] ), in.getType() ); v.setName( space.environmentSubstitute( fieldOutStream[i] ) ); v.setLength( in.getLength() ); v.setPrecision( in.getPrecision() ); v.setConversionMask( in.getConversionMask() ); v.setOrigin( name ); inputRowMeta.addValueMeta( v ); } catch ( Exception e ) { throw new KettleStepException( e ); } } } } }
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; }
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; }
/** * @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; }
v.setLength( getFieldLength()[i], getFieldPrecision()[i] ); v.setOrigin( name ); v.setConversionMask( getFieldFormat()[i] ); v.setDecimalSymbol( getFieldDecimal()[i] ); v.setGroupingSymbol( getFieldGroup()[i] );
@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 ); } } }
v.setPrecision( field.getPrecision() ); v.setOrigin( name ); v.setConversionMask( field.getFormat() ); v.setDecimalSymbol( field.getDecimalSymbol() ); v.setGroupingSymbol( field.getGroupSymbol() );
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() ); }