DataFieldMetadata: possible to overwrite programatically?

Hi,

In my Transform java class, is it possible to overwrite the metadata of a field? something like this:

public boolean transform(DataRecord _source, DataRecord _target) {

DataRecord newRec = target.duplicate();

System.out.println("old metadata : " + newRec.getMetadata());

newRec.getField(“REF”).getMetadata().setSize(10);
newRec.getField(“REF”).getMetadata().setType(LocalField.STRING);
newRec.getField(“REF”).getMetadata().setNullable(true);

System.out.println("new metadata : " + newRec.getMetadata());

… perform data conversions and save the non-numeric value to “REF” …

}

and my system output is:

old metadata : DataRecordMetadata[fields = [org.jetel.metadata.DataFieldMetadata@53, org.jetel.metadata.DataFieldMetadata@4e, org.jetel.metadata.DataFieldMetadata@53, org.jetel.metadata.DataFieldMetadata@53], fieldNames = {REF=0}, fieldTypes = {0=N}, name = achan_output_1_txt_, recType = D, localeStr = null, skipFirstLine = false, recordProperties = {}, DELIMITED_RECORD = D, FIXEDLEN_RECORD = F]

new metadata : DataRecordMetadata[fields = [org.jetel.metadata.DataFieldMetadata@53, org.jetel.metadata.DataFieldMetadata@53, org.jetel.metadata.DataFieldMetadata@53, org.jetel.metadata.DataFieldMetadata@53], fieldNames = {REF=0}, fieldTypes = {0=N}, name = achan_output_1_txt_, recType = D, localeStr = null, skipFirstLine = false, recordProperties = {}, DELIMITED_RECORD = D, FIXEDLEN_RECORD = F]

so the metadata was not changed (from Numeric to String, etc)…

any ideas on how to change the metadata of a field inside my java class so that i can save non-numeric value to “REF”?

thanks,
al

Hello,
what you are trying to do is very unconventional and danger. But if you want to change record metadata you have to call init() method:

newRec.init()

But why are you trying to do this? Rather create temporary record in init method of your transformation:


	public boolean init(Properties parameters,
			DataRecordMetadata[] sourceRecordsMetadata,
			DataRecordMetadata[] targetRecordsMetadata)
			throws ComponentNotReadyException {
		tMetadata = targetRecordsMetadata[0].duplicate();
		tMetadata.getField("REF").setSize((short) 10);
		tMetadata.getField("REF").setType(DataFieldMetadata.STRING_FIELD);
		tMetadata.getField("REF").setNullable(true);
		tmpRecord = new DataRecord(tMetadata);
		tmpRecord.init();
		return super.init(parameters, sourceRecordsMetadata, targetRecordsMetadata);
	}

Then you can store anything in such temporary record.