2012-12-04 24 views
2

我有一個excel工作手冊,其中有多張工作表具有相同的數據模式。我有工作實現來加載單張紙上的數據。Rhino.ETL - 工會運營

有沒有辦法使用JoinOperation或任何此類操作將類似記錄(模式)合併到單個集合(行)中?

我的理解是JoinOperation可以用於左,右,外部和內部聯接,但不能用於聯合,因爲MergeRows的返回類型是Row。

在此先感謝。

回答

3

您可以實現AbstractOperation多個輸入操作結合起來是這樣的:

public class UnionAllOperation : AbstractOperation  { 
    private readonly List<IOperation> _operations = new List<IOperation>(); 

    public override IEnumerable<Row> Execute(IEnumerable<Row> rows) 
    { 
     foreach (var operation in _operations) 
      foreach (var row in operation.Execute(null)) 
       yield return row; 
    } 

    public UnionAllOperation Add(IOperation operation) { 
     _operations.Add(operation); 
     return this; 
    } 
} 

更新:請參閱並行版本上here

使用它在這樣一個過程:

public class Process : EtlProcess { 
    protected override void Initialize() { 

     Register(
      new UnionAllOperation() 
       .Add(new ExtractFromExcel("WorkBook1.xls")) 
       .Add(new ExtractFromExcel("WorkBook2.xls")) 
     ); 
    } 
} 

此執行UNION ALL操作。如果您需要返回不同行的聯合,請在所有列上實施AbstractAggregationOperation和組。