feat(etl): implement TransformingDataReader and DataTransformerBase
Add core transformer infrastructure for the ETL pipeline: - DataTransformerBase: abstract base class with virtual methods for field count, names, types, values, ordinals, and null checking - TransformingDataReader: IDataReader wrapper that delegates to transformer, enabling on-the-fly data transformations
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System.Data;
|
||||
using JdeScoping.DataSync.Etl.Contracts;
|
||||
|
||||
namespace JdeScoping.DataSync.Etl.Transformers;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for data transformers that modify data during the ETL process.
|
||||
/// Derived classes can override specific methods to customize transformation behavior.
|
||||
/// </summary>
|
||||
public abstract class DataTransformerBase : IDataTransformer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public abstract string TransformerName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDataReader Transform(IDataReader source)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
OnInitialize(source);
|
||||
return new TransformingDataReader(source, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the transformer is initialized with a source reader.
|
||||
/// Override to perform initialization logic.
|
||||
/// </summary>
|
||||
/// <param name="source">The source data reader.</param>
|
||||
protected virtual void OnInitialize(IDataReader source) { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the field count from the source reader.
|
||||
/// Override to add or remove fields.
|
||||
/// </summary>
|
||||
public virtual int GetFieldCount(IDataReader source) => source.FieldCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of a field at the specified ordinal.
|
||||
/// Override to rename fields.
|
||||
/// </summary>
|
||||
public virtual string GetName(int ordinal, IDataReader source) => source.GetName(ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of a field at the specified ordinal.
|
||||
/// Override to change field types.
|
||||
/// </summary>
|
||||
public virtual Type GetFieldType(int ordinal, IDataReader source) => source.GetFieldType(ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a field at the specified ordinal.
|
||||
/// Override to transform values.
|
||||
/// </summary>
|
||||
public virtual object GetValue(int ordinal, IDataReader source) => source.GetValue(ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ordinal of a field by name.
|
||||
/// Override to support renamed fields.
|
||||
/// </summary>
|
||||
public virtual int GetOrdinal(string name, IDataReader source) => source.GetOrdinal(name);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a field value is DBNull.
|
||||
/// Override to handle null transformations.
|
||||
/// </summary>
|
||||
public virtual bool IsDBNull(int ordinal, IDataReader source) => source.IsDBNull(ordinal);
|
||||
}
|
||||
Reference in New Issue
Block a user