That was my first instinct, I ended up with:
if ( renderingContext.getClauseStack().getCurrent() == Clause.SELECT
&& renderingContext.getFunctionStack().isEmpty() ) {
}
The test passes with that, obviously. But as I said, I don't think it's solid enough: it's different from the literal case as it's not only "it has to be in the SELECT clause" but "it has to be at the root at the SELECT clause". Typically, if you have AVG(name) in your SELECT clause, you don't want the alias to be expanded for name. I foresee quite a lot of corner cases unfortunately and I don't think the "bugfix/improvement" is worth the risk in a x.x.1. Might be a good idea to think about what we would need in 6 to implement this thing properly. |