Add AbstractQuery test, fix bugs in AbstractQuery