BUG/FIX: Fix dtype inference issue in query

closes #8568