This custom transformation propagates all columns from the input reader, but assigns additional metadata to all real columns.
Two new metadata properties are added for each real column:
Custom.Lamba: A real value, randomly calculated,
between 0 and 1
Custom.Propagate: A boolean value specifying if
the columns should be propagated from a custom transformation
later in the transformation chain.
The data source is very similar to the
Transformation: Simple Example
and this is the reader.
private class LambdaTransformationReader : CustomDataRowReader
{
private DataRowReader inputReader;
private List<DataRowReaderColumn> columns;
public LambdaTransformationReader(
ImportContext importContext, DataRowReader inputReader)
{
Random random = new Random();
this.inputReader = inputReader;
this.columns = new List<DataRowReaderColumn>();
foreach (DataRowReaderColumn col in inputReader.Columns)
{
DataColumnProperties properties = col.Properties;
if (col.DataType == DataType.Real)
{
double lambda = random.NextDouble();
bool propagate = random.Next(0, 2) != 0;
// we need to clone the input properties to be able to set
// new properties.
properties = properties.Propagate(importContext);
properties.SetProperty("Custom.Lambda", lambda);
properties.SetProperty("Custom.Propagate", propagate);
}
// keep Name, DataType and Cursor since we do not modify the
// values in the columns.
this.columns.Add(
new DataRowReaderColumn(
col.Name,
col.DataType,
properties,
col.Cursor));
}
}
protected override IEnumerable<DataRowReaderColumn> GetColumnsCore()
{
return this.columns;
}
protected override ResultProperties GetResultPropertiesCore()
{
return this.inputReader.ResultProperties;
}
protected override void ResetCore()
{
this.inputReader.Reset();
}
protected override bool MoveNextCore()
{
return this.inputReader.MoveNext();
}
}