Impala Query Failed with ERROR “AnalysisException: ORDER BY expression not produced by aggregation output”

Recently, I discovered a bug in Impala that when you are using Expression in the ORDER BY clause, the query will fail with below error message: Customer used a very complicated query, and I managed to simplify it to look something like below: This can be re-produced from CDH5.13.x onward. …