Fix assertion error, class cast exception in selection
Add unit test coverage for ORDER BY, esp functions