use of org.jooq.SelectFieldOrAsterisk in project jOOQ by jOOQ.
the class SelectQueryImpl method distinctOnEmulation.
@SuppressWarnings({ "rawtypes", "unchecked" })
private final Select<?> distinctOnEmulation() {
// [#3564] TODO: Extract and merge this with getSelectResolveSomeAsterisks0()
List<Field<?>> partitionBy = new ArrayList<>(distinctOn.size());
for (SelectFieldOrAsterisk s : distinctOn) if (s instanceof Field)
partitionBy.add((Field<?>) s);
Field<Integer> rn = rowNumber().over(partitionBy(partitionBy).orderBy(orderBy)).as("rn");
SelectQueryImpl<R> copy = copy(x -> {
});
copy.distinctOn = null;
copy.select.add(rn);
copy.orderBy.clear();
copy.limit.clear();
SelectLimitStep<?> s1 = DSL.select(new QualifiedSelectFieldList(table(name("t")), select)).from(copy.asTable("t")).where(rn.eq(one())).orderBy(map(orderBy, o -> unqualified(o)));
if (limit.limit != null) {
SelectLimitPercentStep<?> s2 = s1.limit(limit.limit);
SelectWithTiesStep<?> s3 = limit.percent ? s2.percent() : s2;
SelectOffsetStep<?> s4 = limit.withTies ? s3.withTies() : s3;
return limit.offset != null ? s4.offset(limit.offset) : s4;
} else
return limit.offset != null ? s1.offset(limit.offset) : s1;
}
use of org.jooq.SelectFieldOrAsterisk 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.SelectFieldOrAsterisk 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