Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rhino ETL Question 1

Status
Not open for further replies.

dinger2121

Programmer
Sep 11, 2007
439
US
Hello,
I have been using rhino etl to move some data between 2 databases and it has been working perfectly. recently, the requirement has come up that I must insert the data if it does not exist, but update other records if they do already exist. Is there an easy (built-in) way to do this using rhino etl, or will I have to build this myself?

Is this a good place even to use rhino etl, or would I be better just writing my own database access app to handle what I need to do?

Thanks for any thoughts.

carl
MCSD, MCTS:MOSS
 
Code:
Regsiter(new LeftJoinSourceToDestination()
           .Left(new ConventionInputCommand("source")
                          {
                              Command = "select id, ... from [table] where ..."
                          })
           .Right(new ConventionInputCommand("destination")
                          {
                              Command = "select id from [table] where ..."
                          }));
Register(new BranchingOperation()
             .Add(Partial
                       .Register(new Filter{Action = "insert"})
                       .Register(new ConventionOutputCommand("destination")
                                      {
                                         Command = "insert into [table] (...) values (...)"
                                      }))

             .Add(Partial
                       .Register(new Filter{Action = "update"})
                       .Register(new ConventionOutputCommand("destination")
                                      {
                                         Command = "update [table] set [column] = @... where id = @Id"
                                      })));
Code:
new LeftJoinSourceToDestination : JoinOperation
{
   public Row Merge(Row leftrow, Row rightrow)
   {
       var clone = leftrow.Clone();
       clone["Action"] = rightrow.Cotains("id") ? "update" : "insert";
       return clone;
   }

   protected override void SetupJoin()
   {
      LeftJoin.Left("id").Right("id");
   }
}

class Filter : AbstractOperation
{
   public string Action;

   public IEnumerable<Row> Process(IEnumerable<Row> rows)
   {
       foreach(var row in rows)
       {
          if(row["Action"] != Action) continue;

          row.Remove("Action");
          yield return row;
       }
   }
}
that's the idea anyway. the key features are flaging the rows (Action), branching for multiple processing and filtering the results of each branch. the process as usual

in the future rhino.etl questions are best answered on the rhino forum.


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks - and I will use that forum going forward.



carl
MCSD, MCTS:MOSS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top