@Override public Object clone() { ValueMetaAndData vmad = new ValueMetaAndData(); try { vmad.valueData = valueMeta.cloneValueData( valueData ); } catch ( KettleValueException e ) { vmad.valueData = null; // TODO: should we really do this? Is it safe? } vmad.valueMeta = valueMeta.clone(); return vmad; }
@Override public ValueMetaBase clone() { try { ValueMetaBase valueMeta = (ValueMetaBase) super.clone(); valueMeta.dateFormat = null; valueMeta.decimalFormat = null; if ( dateFormatLocale != null ) { valueMeta.dateFormatLocale = (Locale) dateFormatLocale.clone(); } if ( dateFormatTimeZone != null ) { valueMeta.dateFormatTimeZone = (TimeZone) dateFormatTimeZone.clone(); } if ( storageMetadata != null ) { valueMeta.storageMetadata = storageMetadata.clone(); } if ( conversionMetadata != null ) { valueMeta.conversionMetadata = conversionMetadata.clone(); } valueMeta.compareStorageAndActualFormat(); return valueMeta; } catch ( CloneNotSupportedException e ) { return null; } }
public RowMetaInterface updateFields( RowMetaInterface prev, MonetDBBulkLoaderData data ) { // update the field table from the fields coming from the previous step RowMetaInterface tableFields = new RowMeta(); List<ValueMetaInterface> fields = prev.getValueMetaList(); fieldTable = new String[fields.size()]; fieldStream = new String[fields.size()]; fieldFormatOk = new boolean[fields.size()]; int idx = 0; for ( ValueMetaInterface field : fields ) { ValueMetaInterface tableField = field.clone(); tableFields.addValueMeta( tableField ); fieldTable[idx] = field.getName(); fieldStream[idx] = field.getName(); fieldFormatOk[idx] = true; idx++; } data.keynrs = new int[getFieldStream().length]; for ( int i = 0; i < data.keynrs.length; i++ ) { data.keynrs[i] = i; } return tableFields; }
private void initGroupMeta( RowMetaInterface previousRowMeta ) throws KettleValueException { data.groupMeta = new RowMeta(); data.entryMeta = new RowMeta(); for ( int i = 0; i < data.groupnrs.length; i++ ) { ValueMetaInterface valueMeta = previousRowMeta.getValueMeta( data.groupnrs[i] ); data.groupMeta.addValueMeta( valueMeta ); ValueMetaInterface normalMeta = valueMeta.clone(); normalMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); } return; }
/** * Produce the XML representation of this value. * * @return a String containing the XML to represent this Value. * @throws KettleValueException * in case there is a data conversion error, only throws in case of lazy conversion */ public String getXML() throws KettleValueException { ValueMetaInterface meta = valueMeta.clone(); meta.setDecimalSymbol( "." ); meta.setGroupingSymbol( null ); meta.setCurrencySymbol( null ); StringBuilder retval = new StringBuilder( 128 ); retval.append( "<" + XML_TAG + ">" ); retval.append( XMLHandler.addTagValue( "name", meta.getName(), false ) ); retval.append( XMLHandler.addTagValue( "type", meta.getTypeDesc(), false ) ); try { retval.append( XMLHandler.addTagValue( "text", meta.getCompatibleString( valueData ), false ) ); } catch ( KettleValueException e ) { // LogWriter.getInstance().logError(toString(), Const.getStackTracker(e)); retval.append( XMLHandler.addTagValue( "text", "", false ) ); } retval.append( XMLHandler.addTagValue( "length", meta.getLength(), false ) ); retval.append( XMLHandler.addTagValue( "precision", meta.getPrecision(), false ) ); retval.append( XMLHandler.addTagValue( "isnull", meta.isNull( valueData ), false ) ); retval.append( XMLHandler.addTagValue( "mask", meta.getConversionMask(), false ) ); retval.append( "</" + XML_TAG + ">" ); return retval.toString(); }
public static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ) throws KettlePluginException { ValueMetaInterface target = null; // If we're Cloneable and not changing types, call clone() if ( source.getType() == targetType ) { target = source.clone(); } else { target = createValueMeta( source.getName(), targetType, source.getLength(), source.getPrecision() ); } cloneInfo( source, target ); return target; }
private void initReturnMeta() { // We also want to know the metadata of the return values beforehand (null handling) data.returnMeta = new RowMeta(); for ( int i = 0; i < meta.getReturnValueField().length; i++ ) { ValueMetaInterface v = data.outputRowMeta.getValueMeta( getInputRowMeta().size() + i ).clone(); data.returnMeta.addValueMeta( v ); } }
private ValueMetaInterface renameValueMetaIfInRow( ValueMetaInterface valueMeta, String originStep ) { // We want to rename the field to Name[2], Name[3], ... // int index = 1; String name = valueMeta.getName() + "_" + index; while ( searchValueMeta( name ) != null ) { index++; name = valueMeta.getName() + "_" + index; } // Create a copy of the valueMeta object to make sure we don't rename any other value meta objects. // It's only being renamed because of the addition to THIS row metadata object, not another. // ValueMetaInterface copy = valueMeta.clone(); // OK, this is the new name and origin to pick // copy.setName( name ); if ( originStep != null ) { copy.setOrigin( originStep ); } return copy; }
ValueMetaInterface v = prev.searchValueMeta( keyStream[i] ); if ( v != null ) { ValueMetaInterface tableField = v.clone(); tableField.setName( keyLookup[i] ); tableFields.addValueMeta( tableField ); ValueMetaInterface vk = tableFields.searchValueMeta( updateLookup[i] ); if ( vk == null ) { // do not add again when already added as key fields ValueMetaInterface tableField = v.clone(); tableField.setName( updateLookup[i] ); tableFields.addValueMeta( tableField );
public RowMetaInterface getParameterMetaData( String sql, RowMetaInterface inform, Object[] data ) { // The database couldn't handle it: try manually! int q = countParameters( sql ); RowMetaInterface par = new RowMeta(); if ( inform != null && q == inform.size() ) { for ( int i = 0; i < q; i++ ) { ValueMetaInterface inf = inform.getValueMeta( i ); ValueMetaInterface v = inf.clone(); par.addValueMeta( v ); } } else { for ( int i = 0; i < q; i++ ) { ValueMetaInterface v = new ValueMetaNumber( "name" + i ); par.addValueMeta( v ); } } return par; }
@Override public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // Remove the key value (there will be different entries for each output row) // if ( fieldName != null && fieldName.length() > 0 ) { int idx = row.indexOfValue( fieldName ); if ( idx < 0 ) { throw new KettleStepException( BaseMessages.getString( PKG, "FlattenerMeta.Exception.UnableToLocateFieldInInputFields", fieldName ) ); } ValueMetaInterface v = row.getValueMeta( idx ); row.removeValueMeta( idx ); for ( int i = 0; i < targetField.length; i++ ) { ValueMetaInterface value = v.clone(); value.setName( targetField[i] ); value.setOrigin( name ); row.addValueMeta( value ); } } else { throw new KettleStepException( BaseMessages.getString( PKG, "FlattenerMeta.Exception.FlattenFieldRequired" ) ); } }
@Test public void testUseDefaultSchemaName() throws Exception { String schemaName = ""; String tableName = "tableName"; String schemaTable = "default.tableName"; DatabaseMeta databaseMeta = spy( new DatabaseMeta( databaseXML ) ); doReturn( "someValue" ).when( databaseMeta ) .getFieldDefinition( any( ValueMetaInterface.class ), anyString(), anyString(), anyBoolean() ); doReturn( schemaTable ).when( databaseMeta ).getQuotedSchemaTableCombination( schemaName, tableName ); ValueMetaInterface valueMeta = mock( ValueMetaInterface.class ); when( valueMeta.clone() ).thenReturn( mock( ValueMetaInterface.class ) ); RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class ); when( rowMetaInterface.size() ).thenReturn( 1 ); when( rowMetaInterface.searchValueMeta( anyString() ) ).thenReturn( valueMeta ); UpdateMeta updateMeta = new UpdateMeta(); updateMeta.setDatabaseMeta( databaseMeta ); updateMeta.setTableName( tableName ); updateMeta.setSchemaName( schemaName ); updateMeta.setKeyLookup( new String[] { "KeyLookup1", "KeyLookup2" } ); updateMeta.setKeyStream( new String[] { "KeyStream1", "KeyStream2" } ); updateMeta.setUpdateLookup( new String[] { "updateLookup1", "updateLookup2" } ); updateMeta.setUpdateStream( new String[] { "UpdateStream1", "UpdateStream2" } ); SQLStatement sqlStatement = updateMeta.getSQLStatements( new TransMeta(), mock( StepMeta.class ), rowMetaInterface, mock( Repository.class ), mock( IMetaStore.class ) ); String sql = sqlStatement.getSQL(); assertTrue( StringUtils.countMatches( sql, schemaTable ) == 2 ); }
ValueMetaInterface vmi = r.getValueMeta( index_of_subject ).clone(); vmi.setOrigin( origin ); vmi.setName( aggregateField[i] );
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // It's best that this method doesn't change anything by itself. // Eventually it's the Mapping step that's going to tell this step how to behave meta-data wise. // It is the mapping step that tells the mapping output step what fields to rename. // if ( inputValueRenames != null ) { for ( MappingValueRename valueRename : inputValueRenames ) { ValueMetaInterface valueMeta = r.searchValueMeta( valueRename.getTargetValueName() ); if ( valueMeta != null ) { valueMeta.setName( valueRename.getSourceValueName() ); } } } // This is the optionally entered stuff in the output tab of the mapping dialog. // if ( outputValueRenames != null ) { for ( MappingValueRename valueRename : outputValueRenames ) { int valueMetaRenameIndex = r.indexOfValue( valueRename.getSourceValueName() ); if ( valueMetaRenameIndex >= 0 ) { ValueMetaInterface valueMetaRename = r.getValueMeta( valueMetaRenameIndex ).clone(); valueMetaRename.setName( valueRename.getTargetValueName() ); // must maintain the same columns order. Noticed when implementing the Mapping step in AEL (BACKLOG-23372) r.removeValueMeta( valueMetaRenameIndex ); r.addValueMeta( valueMetaRenameIndex, valueMetaRename ); } } } }
@Override public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( Utils.isEmpty( info ) || info[0] == null ) { // null or length 0 : no info from database for ( int i = 0; i < getReturnValueNewName().length; i++ ) { try { ValueMetaInterface v = ValueMetaFactory.createValueMeta( getReturnValueNewName()[i], getReturnValueDefaultType()[i] ); v.setOrigin( name ); row.addValueMeta( v ); } catch ( Exception e ) { throw new KettleStepException( e ); } } } else { for ( int i = 0; i < returnValueNewName.length; i++ ) { ValueMetaInterface v = info[0].searchValueMeta( returnValueField[i] ); if ( v != null ) { ValueMetaInterface copy = v.clone(); // avoid renaming other value meta - PDI-9844 copy.setName( returnValueNewName[i] ); copy.setOrigin( name ); row.addValueMeta( copy ); } } } }
data.lookupReturnRowMeta.addValueMeta( rowMeta.searchValueMeta( meta.getUpdateStream()[i] ).clone() );
ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] ); if ( v != null ) { ValueMetaInterface tableField = v.clone(); tableField.setName( fieldTable[i] ); tableFields.addValueMeta( tableField );
ValueMetaInterface v = row.getValueMeta( index ).clone(); v.setLength( fn.getValueLength(), fn.getValuePrecision() ); v.setOrigin( name );
ValueMetaInterface v = row.getValueMeta( index ).clone(); v.setLength( fn.getValueLength(), fn.getValuePrecision() ); v.setOrigin( name );