ENG-1565: add support for edge cases and adHoc queries.