Allow to use closure in QueryExpression

Allow to use closure in QueryExpression. Fixes #3852