use of org.jooq.QualifiedAsterisk in project jOOQ by jOOQ.
the class DefaultParseContext method parseCountIf.
private final AggregateFunction<?> parseCountIf() {
if (parseFunctionNameIf("COUNT")) {
parse('(');
boolean distinct = parseSetQuantifier();
if (parseIf('*') && parse(')'))
if (distinct)
return countDistinct(asterisk());
else
return count();
Field<?>[] fields = null;
QualifiedAsterisk asterisk = null;
Row row = parseRowIf();
if (row != null)
fields = row.fields();
else if ((asterisk = parseQualifiedAsteriskIf()) == null)
fields = distinct ? parseList(',', c -> c.parseField()).toArray(EMPTY_FIELD) : new Field[] { parseField() };
parse(')');
if (distinct)
if (fields == null)
return countDistinct(asterisk);
else if (fields.length == 1)
return countDistinct(fields[0]);
else
return countDistinct(fields);
else if (fields == null)
return count(asterisk);
else
return count(fields[0]);
}
return null;
}
use of org.jooq.QualifiedAsterisk in project jOOQ by jOOQ.
the class DefaultParseContext method parseSelectList.
private final List<SelectFieldOrAsterisk> parseSelectList() {
List<SelectFieldOrAsterisk> result = new ArrayList<>();
do {
QualifiedAsterisk qa;
if (parseIf('*')) {
if (parseKeywordIf("EXCEPT")) {
parse('(');
result.add(DSL.asterisk().except(parseList(',', c -> parseFieldName()).toArray(EMPTY_FIELD)));
parse(')');
} else
result.add(DSL.asterisk());
} else if ((qa = parseQualifiedAsteriskIf()) != null) {
if (parseKeywordIf("EXCEPT")) {
parse('(');
result.add(qa.except(parseList(',', c -> parseFieldName()).toArray(EMPTY_FIELD)));
parse(')');
} else
result.add(qa);
} else {
Name alias = null;
SelectField<?> field = null;
if (field == null) {
field = parseSelectField();
if (parseKeywordIf("AS"))
alias = parseIdentifier(true, false);
else if (!peekKeyword(KEYWORDS_IN_SELECT) && !peekKeyword(KEYWORDS_IN_STATEMENTS))
alias = parseIdentifierIf(true, false);
}
result.add(alias == null ? field : field.as(alias));
}
} while (parseIf(','));
return result;
}
use of org.jooq.QualifiedAsterisk in project jOOQ by jOOQ.
the class SelectQueryImpl method getSelectResolveSomeAsterisks0.
private final SelectFieldList<SelectFieldOrAsterisk> getSelectResolveSomeAsterisks0(Configuration c, boolean resolveSupported) {
SelectFieldList<SelectFieldOrAsterisk> result = new SelectFieldList<>();
// [#7921] Only H2 supports the * EXCEPT (..) syntax
boolean resolveExcept = resolveSupported || !SUPPORT_NATIVE_EXCEPT.contains(c.dialect());
boolean resolveUnqualifiedCombined = resolveSupported || NO_SUPPORT_UNQUALIFIED_COMBINED.contains(c.dialect());
// [#7921] TODO Find a better, more efficient way to resolve asterisks
SelectFieldList<SelectFieldOrAsterisk> list = getSelectResolveImplicitAsterisks();
for (SelectFieldOrAsterisk s : list) if (s instanceof Field)
result.add(getResolveProjection(c, (Field<?>) s));
else if (s instanceof QualifiedAsteriskImpl) {
QualifiedAsteriskImpl q = (QualifiedAsteriskImpl) s;
if (q.fields.isEmpty())
if (resolveSupported)
result.addAll(Arrays.asList(q.qualifier().fields()));
else
result.add(s);
else if (resolveExcept)
result.addAll(subtract(Arrays.asList(((QualifiedAsterisk) s).qualifier().fields()), (((QualifiedAsteriskImpl) s).fields)));
else
result.add(s);
} else if (s instanceof AsteriskImpl) {
AsteriskImpl a = (AsteriskImpl) s;
if (a.fields.isEmpty())
if (resolveSupported || resolveUnqualifiedCombined && list.size() > 1)
result.addAll(resolveAsterisk(new QueryPartList<>()));
else
result.add(s);
else if (resolveExcept)
result.addAll(resolveAsterisk(new QueryPartList<>(), a.fields));
else
result.add(s);
} else if (s instanceof Row)
result.add(getResolveProjection(c, new RowAsField<Row, Record>((Row) s)));
else if (s instanceof Table)
result.add(getResolveProjection(c, new TableAsField<>((Table<?>) s)));
else
throw new AssertionError("Type not supported: " + s);
return result;
}
Aggregations