No need for casts here. Just check:

    if (!queryPlan.getGroupBy().isEmpty()) {