Ancestor impl

Initial version of ancestor query support, there are probably bugs but I think this is a good foundation. Nested descendents probably don't work properly. Let's target that for 1.0-beta.

This branch also includes several fixes to key handling. The same number of tests pass so hopefully I didn't introduce any regressions.