Normalizer

I have a source table that has flattened data fields which I need to store in a normalized table.
I have a record which looks like this

date,event_id,field1,field2,field3,session,token

For each row, date, event_id and session,token are populated but field1 and field2 and field 3 may not be populated all at the same time. I have to look for non zero value in those fields and ppulate the table where the table structure is
date
field1 type
field1 value
session
token

I can’t find any example where I can get some idea .
Any help will be greatly appreciated.
Thanks,
Kasturi

Perhaps this example will help you. It will produce one output record for every non-empty value in the field1-field3 fields. Use this code in your Normalizer component.


//#CTL2
// This transformation defines the way in which a single input record is normalized
// into multiple output records.
string[] values;

// This function is called for all input records.
// It parses each single input record and returns the number of records
// that should be created from such input record.
function integer count() {
	integer notNulls = 0;
	if ($0.field1 != null) {
		values[notNulls] = $0.field1;
		notNulls++;
	}
	if ($0.field2 != null) {
		values[notNulls] = $0.field2;
		notNulls++;
	}
	if ($0.field3 != null) {
		values[notNulls] = $0.field3;
		notNulls++;
	}

	return notNulls;
}

// This function creates new records for the output, based on single input record
// that has been parsed by the count() function.
// It is called count() times for each input record.
// The idx argument specifies which output record is being created,
// its values range is from 0 to count() - 1.
function integer transform(integer idx) {
  $0.date = $0.date;
  $0.session = $0.session;
  $0.field1_type = "string";
  $0.field1_value = values[idx];
  
  return 0;
}

Or you can use the approach presented in this thread.

Hi Jan,
Thank you so much for the help. I really appreciate it. It worked . I added the types also along with the values. It woks perfectly.
Thanks again.
Kasturi