to what degree is this different from the one in pig? Is everything essentially the same?

I think we should add some tests for this (maybe grab the tests for this from pig), there's a lot that goes on in here.