@SuppressWarnings("unchecked")
    public List<Tuple> calculateGroupByProjection() throws ParseException {
        List<Tuple> new_tlist = new ArrayList<Tuple>();
        StringBuilder sb = new StringBuilder();
        boolean isDistinct;
        selectList = select.getSelectItems();

        // COUNT/SUM for GROUPBY

        String key = getGroupByKey();

        //

        List<Tuple> tlist = instream.get(0);

        for (SelectExpressionItem s : selectList) {

            String col = new String();
            Expression exp = s.getExpression();
            ExpressionEvaluator ee = new ExpressionEvaluator();
            exp.accept(ee);

            if (ee.getUserColumn() != null) {
                col = ee.getUserColumn().getColumnName();

            } else {
                col = ee.getColumn().getWholeColumnName();

            }
            isDistinct = ee.getResult();

            if (col.contains("|")) {
                col = col.split("\\.", 2)[1];
                String fnct = col.split("\\|")[0];
                String expn = col.split("\\|")[1];
                if (fnct.equalsIgnoreCase("COUNT")) {

                    sb.append(new Count(instream, expn, isDistinct, key)
                            .getCount() + "|");

                } else if (fnct.equalsIgnoreCase("SUM")) {
                    sb.append(new Sum(instream, expn, isDistinct).getSum()
                            + "|");

                } else if (fnct.equalsIgnoreCase("AVG")) {
                    sb.append(new Avg(instream, expn, isDistinct).getAvg()
                            + "|");
                }

            } else {

                for (Tuple t : tlist) {

                    String val = t.getColValue(col);

                    if (val != null) {

                        sb.append(val + "|");
                        break;
                    }
                }
            }

        }
        String t = sb.substring(0, sb.length() - 1);
        Tuple tuple = new Tuple(OutputSchema.osTable.getWholeTableName()
                .toLowerCase(), t);

        new_tlist.add(tuple);
        return new_tlist;
    }