Rhino-ETL Conditional Operations

125 views
Skip to first unread message

John Strzempa

unread,
Jun 17, 2012, 12:28:00 AM6/17/12
to rhino-t...@googlegroups.com
I want to check the value of a row field value and depending on the value run a specific operation. Can this be done. Part of the code is below

    public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            foreach (Row row in rows)
            {
                if (row["ProductAction"] == "Update")
                {
                    _updateProductOperation.Execute(rows);
                }
                else
                {
                    _addProductOperation.Execute(rows);
                }

                yield return row;
            }
        }

Simone Busoli

unread,
Jun 17, 2012, 4:31:53 AM6/17/12
to rhino-t...@googlegroups.com
Hello John,

that't not how you'd usually do this, as executing an operation is more involved than just calling Execute on it - and it's why several executors exist in the library.
The idiomatic way to achieve the same is by branching the pipeline in two, whose entry points would be a updateProductOperation and addProductOperation. Their implementation would be the same as in your code except that the first would filter rows by row["ProductAction"] == "Update" and the second by != "Update".

Hope this helps, Simone


--
You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhino-tools-dev/-/pLnVYjhuzqsJ.
To post to this group, send email to rhino-t...@googlegroups.com.
To unsubscribe from this group, send email to rhino-tools-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhino-tools-dev?hl=en.

John Strzempa

unread,
Jun 17, 2012, 10:22:48 AM6/17/12
to rhino-t...@googlegroups.com
Hi Simone,

Thanks. That is what I was thinking but wanted to be sure.


On Sunday, June 17, 2012 3:31:53 AM UTC-5, SimoneB wrote:
Hello John,

that't not how you'd usually do this, as executing an operation is more involved than just calling Execute on it - and it's why several executors exist in the library.
The idiomatic way to achieve the same is by branching the pipeline in two, whose entry points would be a updateProductOperation and addProductOperation. Their implementation would be the same as in your code except that the first would filter rows by row["ProductAction"] == "Update" and the second by != "Update".

Hope this helps, Simone


I want to check the value of a row field value and depending on the value run a specific operation. Can this be done. Part of the code is below

    public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            foreach (Row row in rows)
            {
                if (row["ProductAction"] == "Update")
                {
                    _updateProductOperation.Execute(rows);
                }
                else
                {
                    _addProductOperation.Execute(rows);
                }

                yield return row;
            }
        }

--
You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhino-tools-dev/-/pLnVYjhuzqsJ.
To post to this group, send email to rhino-tools-dev@googlegroups.com.
To unsubscribe from this group, send email to rhino-tools-dev+unsubscribe@googlegroups.com.

Jason Meckley

unread,
Jun 18, 2012, 7:59:22 AM6/18/12
to rhino-t...@googlegroups.com
Register(new BranchingOperation()
     .Add(Partial.Register(new FilterRecordsToAdd()).Register(new OutputCommandOperation{CommandText="insert into ..."}))
     .Add(Partial.Register(new FilterRecordsToUpdate()).Register(new OutputCommandOperation{CommandText="update ..."}));

Where FilterRecordsToAdd/Update are your implementations of AbstractOperation.  OutputCommandOperation (or something like that) is the built in operation to execute a write against the database.
Reply all
Reply to author
Forward
0 new messages