A gift from Alistair

After my series on implementing relational operators on.NET DataTables, I received several requests to post the whole code library.

I was reluctant to do it for 2 reasons
1. The code is already there. <SCREAMING MAN> Just copy and paste it you lazy bastards!</SCREAMING MAN>
2. The initial library was designed for a specific application with many specialised routines.

In the haze of comments received, only one poster choose to donate time and effort to refactor the SQLOps routines into a convenient (and IMO, elegant) set of classes.

Alistair Bayley’s implementation makes significant improvements in functionality and usage.

Here is a short summary from Alistair:

- subclassed DataTable and added the static methods as instance/object methods. This allows nice infix usage of operators, instead of the prefix-style that static methods force.

- added various API overloadings, and a few changes (I think Project is a bit different; Divide too).

- made some of the suggested improvements to GroupBy. I used an additional class "GroupByExpr" to avoid the problem where the array arguments might have different lengths. Also added type inference for
the aggregate expressions.

- added a suite of Nunit tests. These are not complete or exhaustive; they largely test the stuff I've been fiddling with.

- fixed a bug (depending on how you look at it) with Project, where the ordering of the result-set columns was not the same as the specified columns. I needed to be able to re-order columns for output purposes.
This not really in the Relational spirit (where ordering doesn't normally matter), but still useful.

- added a more general Divide.

- added a left-outer-join (OuterJoin), which I needed. Haven't bothered with right- or full- yet.

- added NaturalJoin.

- added Extend (append a literal column).

- added Sort (obvious).

- added Rename, but note that this is different from the other operators, in that it modifies the argument i.e. it's destructive. It seemed overkill to copy the table just to rename a column... I don't like this, because it doesn't return a new table like all of the other operators, and so it destroys the nice closure property.

As a small gesture, I have added operator overloading into the class as well.

The file (zipped VS2003 IDE compatible solution (C#) – 20Kb) can be found at SQLTeam here thanks to graz..

Thankyou Alistair!

Print | posted on Thursday, August 02, 2007 9:10 AM

Feedback

# re: A gift from Alistair

left by Jeff at 8/2/2007 12:06 PM Gravatar
>> added a left-outer-join (OuterJoin), which I needed. Haven't bothered with right- or full- yet.

I think you know my take on right- and full-outer joins; only implementing a left outer join is *perfect*. Tell him not to change a thing!

# re: A gift from Alistair

left by JulienV at 2/14/2008 8:26 PM Gravatar
Thank you David & Alistair !

# re: A gift from Alistair

left by Tecky Lee at 11/1/2009 5:20 PM Gravatar
thank you very much!

# re: A gift from Alistair

left by fur boots at 10/5/2010 11:46 PM Gravatar
This not really in the Relational spirit (where ordering doesn't normally matter), but still useful.

# re: A gift from Alistair

left by Gytha at 7/16/2011 1:28 AM Gravatar
Heck yeah this is exactly what I neeedd.
Comments have been closed on this topic.