@Override
    public NumberExpression<Long> countDistinct() {
        if (countDistinct == null) {
            if (primaryKey != null) {
                // TODO handle multiple column primary keys properly
                countDistinct = Expressions.numberOperation(Long.class, Ops.AggOps.COUNT_DISTINCT_AGG,
                        primaryKey.getLocalColumns().get(0));
            } else {
                throw new IllegalStateException("No count distinct expression can be created");
            }
        }
        return countDistinct;
    }
{@code RelationalPathBase} is a base class for {@link RelationalPath} implementations

@author tiwe

@param <T>
           entity type
querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java