class AggregateDataHistogram extends AggregateData {

        private long count;
        private ValueHashMap<AggregateDataHistogram> distinctValues;

        @Override
        public void add(ServerSession session, Value v) {
            if (distinctValues == null) {
                distinctValues = ValueHashMap.newInstance();
            }
            AggregateDataHistogram a = distinctValues.get(v);
            if (a == null) {
                if (distinctValues.size() < Constants.SELECTIVITY_DISTINCT_COUNT) {
                    a = new AggregateDataHistogram();
                    distinctValues.put(v, a);
                }
            }
            if (a != null) {
                a.count++;
            }
        }

        @Override
        Value getValue(ServerSession session) {<FILL_FUNCTION_BODY>}
    }

            ValueArray[] values = new ValueArray[distinctValues.size()];
            int i = 0;
            for (Value dv : distinctValues.keys()) {
                AggregateDataHistogram d = distinctValues.get(dv);
                values[i] = ValueArray.get(new Value[] { dv, ValueLong.get(d.count) });
                i++;
            }
            final CompareMode compareMode = session.getDatabase().getCompareMode();
            Arrays.sort(values, new Comparator<ValueArray>() {
                @Override
                public int compare(ValueArray v1, ValueArray v2) {
                    Value a1 = v1.getList()[0];
                    Value a2 = v2.getList()[0];
                    return a1.compareTo(a2, compareMode);
                }
            });
            Value v = ValueArray.get(values);
            return v.convertTo(dataType);
        
<methods>public void <init>(int, com.lealone.sql.expression.Expression, com.lealone.sql.query.Select, boolean) ,public R accept(ExpressionVisitor<R>) ,public int getAType() ,public com.lealone.sql.expression.aggregate.AggregateData getAggregateData() ,public int getCost() ,public int getDisplaySize() ,public com.lealone.sql.expression.Expression getOn() ,public long getPrecision() ,public int getScale() ,public com.lealone.db.value.Value getValue(com.lealone.db.session.ServerSession) ,public boolean isOptimizable(com.lealone.db.table.Table) ,public com.lealone.sql.expression.Expression optimize(com.lealone.db.session.ServerSession) ,public void updateAggregate(com.lealone.db.session.ServerSession) <variables>protected int displaySize,protected final non-sealed boolean distinct,protected com.lealone.sql.expression.Expression on,protected long precision,protected int scale,protected final non-sealed int type