MARMOTTA-578: bug confirmed with a test
MARMOTTA-578: some code cleanup to fit with our code conventions
MARMOTTA-578: simplified test query to just target the actual issue
MARMOTTA-578: added missing variables to GROUP BY that required to be present by its usage in ORDER BY