use of org.jooq.WindowSpecification in project jOOQ by jOOQ.
the class DefaultParseContext method parseWindowFunction.
private final Field<?> parseWindowFunction(WindowFromFirstLastStep s1, WindowIgnoreNullsStep s2, WindowOverStep<?> s3) {
s2 = parseWindowFromFirstLast(s1, s2);
s3 = parseWindowRespectIgnoreNulls(s2, s3);
parseKeyword("OVER");
Object nameOrSpecification = parseWindowNameOrSpecification(true);
return nameOrSpecification instanceof Name ? s3.over((Name) nameOrSpecification) : nameOrSpecification instanceof WindowSpecification ? s3.over((WindowSpecification) nameOrSpecification) : s3.over();
}
use of org.jooq.WindowSpecification in project jOOQ by jOOQ.
the class ParserImpl method parseAggregateFunctionIf.
private static final Field<?> parseAggregateFunctionIf(ParserContext ctx) {
AggregateFunction<?> agg;
WindowBeforeOverStep<?> over;
Field<?> result;
Condition filter;
over = agg = parseCountIf(ctx);
if (agg == null)
over = agg = parseGeneralSetFunctionIf(ctx);
if (agg == null)
over = agg = parseBinarySetFunctionIf(ctx);
if (agg == null)
over = parseOrderedSetFunctionIf(ctx);
if (agg == null && over == null)
return null;
if (agg != null && parseKeywordIf(ctx, "FILTER")) {
parse(ctx, '(');
parseKeyword(ctx, "WHERE");
filter = parseCondition(ctx);
parse(ctx, ')');
result = over = agg.filterWhere(filter);
} else if (agg != null)
result = agg;
else
result = over;
// TODO parse WITHIN GROUP (ORDER BY) where applicable
if (parseKeywordIf(ctx, "OVER")) {
Object nameOrSpecification = parseWindowNameOrSpecification(ctx, agg != null);
if (nameOrSpecification instanceof Name)
result = over.over((Name) nameOrSpecification);
else if (nameOrSpecification instanceof WindowSpecification)
result = over.over((WindowSpecification) nameOrSpecification);
else
result = over.over();
}
return result;
}
use of org.jooq.WindowSpecification in project jOOQ by jOOQ.
the class DefaultParseContext method parseWindowSpecificationIf.
private final WindowSpecification parseWindowSpecificationIf(Name windowName, boolean orderByAllowed) {
final WindowSpecificationOrderByStep s1;
final WindowSpecificationRowsStep s2;
final WindowSpecificationRowsAndStep s3;
final WindowSpecificationExcludeStep s4;
final WindowSpecification result;
s1 = windowName != null ? windowName.as() : parseKeywordIf("PARTITION BY") ? partitionBy(parseList(',', c -> c.parseField())) : null;
if (parseKeywordIf("ORDER BY"))
if (orderByAllowed)
s2 = s1 == null ? orderBy(parseList(',', c -> c.parseSortField())) : s1.orderBy(parseList(',', c -> c.parseSortField()));
else
throw exception("ORDER BY not allowed");
else
s2 = s1;
boolean rows = parseKeywordIf("ROWS");
boolean range = !rows && parseKeywordIf("RANGE");
boolean groups = !rows && !range && parseKeywordIf("GROUPS");
if ((rows || range || groups) && !orderByAllowed)
throw exception("ROWS, RANGE, or GROUPS not allowed");
if (rows || range || groups) {
Long n;
if (parseKeywordIf("BETWEEN")) {
if (parseKeywordIf("UNBOUNDED"))
if (parseKeywordIf("PRECEDING"))
s3 = s2 == null ? rows ? rowsBetweenUnboundedPreceding() : range ? rangeBetweenUnboundedPreceding() : groupsBetweenUnboundedPreceding() : rows ? s2.rowsBetweenUnboundedPreceding() : range ? s2.rangeBetweenUnboundedPreceding() : s2.groupsBetweenUnboundedPreceding();
else if (parseKeywordIf("FOLLOWING"))
s3 = s2 == null ? rows ? rowsBetweenUnboundedFollowing() : range ? rangeBetweenUnboundedFollowing() : groupsBetweenUnboundedFollowing() : rows ? s2.rowsBetweenUnboundedFollowing() : range ? s2.rangeBetweenUnboundedFollowing() : s2.groupsBetweenUnboundedFollowing();
else
throw expected("FOLLOWING", "PRECEDING");
else if (parseKeywordIf("CURRENT ROW"))
s3 = s2 == null ? rows ? rowsBetweenCurrentRow() : range ? rangeBetweenCurrentRow() : groupsBetweenCurrentRow() : rows ? s2.rowsBetweenCurrentRow() : range ? s2.rangeBetweenCurrentRow() : s2.groupsBetweenCurrentRow();
else if ((n = parseUnsignedIntegerLiteralIf()) != null)
if (parseKeywordIf("PRECEDING"))
s3 = s2 == null ? rows ? rowsBetweenPreceding(n.intValue()) : range ? rangeBetweenPreceding(n.intValue()) : groupsBetweenPreceding(n.intValue()) : rows ? s2.rowsBetweenPreceding(n.intValue()) : range ? s2.rangeBetweenPreceding(n.intValue()) : s2.groupsBetweenPreceding(n.intValue());
else if (parseKeywordIf("FOLLOWING"))
s3 = s2 == null ? rows ? rowsBetweenFollowing(n.intValue()) : range ? rangeBetweenFollowing(n.intValue()) : groupsBetweenFollowing(n.intValue()) : rows ? s2.rowsBetweenFollowing(n.intValue()) : range ? s2.rangeBetweenFollowing(n.intValue()) : s2.groupsBetweenFollowing(n.intValue());
else
throw expected("FOLLOWING", "PRECEDING");
else
throw expected("CURRENT ROW", "UNBOUNDED", "integer literal");
parseKeyword("AND");
if (parseKeywordIf("UNBOUNDED"))
if (parseKeywordIf("PRECEDING"))
s4 = s3.andUnboundedPreceding();
else if (parseKeywordIf("FOLLOWING"))
s4 = s3.andUnboundedFollowing();
else
throw expected("FOLLOWING", "PRECEDING");
else if (parseKeywordIf("CURRENT ROW"))
s4 = s3.andCurrentRow();
else if (asTrue(n = parseUnsignedIntegerLiteral()))
if (parseKeywordIf("PRECEDING"))
s4 = s3.andPreceding(n.intValue());
else if (parseKeywordIf("FOLLOWING"))
s4 = s3.andFollowing(n.intValue());
else
throw expected("FOLLOWING", "PRECEDING");
else
throw expected("CURRENT ROW", "UNBOUNDED", "integer literal");
} else if (parseKeywordIf("UNBOUNDED"))
if (parseKeywordIf("PRECEDING"))
s4 = s2 == null ? rows ? rowsUnboundedPreceding() : range ? rangeUnboundedPreceding() : groupsUnboundedPreceding() : rows ? s2.rowsUnboundedPreceding() : range ? s2.rangeUnboundedPreceding() : s2.groupsUnboundedPreceding();
else if (parseKeywordIf("FOLLOWING"))
s4 = s2 == null ? rows ? rowsUnboundedFollowing() : range ? rangeUnboundedFollowing() : groupsUnboundedFollowing() : rows ? s2.rowsUnboundedFollowing() : range ? s2.rangeUnboundedFollowing() : s2.groupsUnboundedFollowing();
else
throw expected("FOLLOWING", "PRECEDING");
else if (parseKeywordIf("CURRENT ROW"))
s4 = s2 == null ? rows ? rowsCurrentRow() : range ? rangeCurrentRow() : groupsCurrentRow() : rows ? s2.rowsCurrentRow() : range ? s2.rangeCurrentRow() : s2.groupsCurrentRow();
else if (asTrue(n = parseUnsignedIntegerLiteral()))
if (parseKeywordIf("PRECEDING"))
s4 = s2 == null ? rows ? rowsPreceding(n.intValue()) : range ? rangePreceding(n.intValue()) : groupsPreceding(n.intValue()) : rows ? s2.rowsPreceding(n.intValue()) : range ? s2.rangePreceding(n.intValue()) : s2.groupsPreceding(n.intValue());
else if (parseKeywordIf("FOLLOWING"))
s4 = s2 == null ? rows ? rowsFollowing(n.intValue()) : range ? rangeFollowing(n.intValue()) : groupsFollowing(n.intValue()) : rows ? s2.rowsFollowing(n.intValue()) : range ? s2.rangeFollowing(n.intValue()) : s2.groupsFollowing(n.intValue());
else
throw expected("FOLLOWING", "PRECEDING");
else
throw expected("BETWEEN", "CURRENT ROW", "UNBOUNDED", "integer literal");
if (parseKeywordIf("EXCLUDE"))
if (parseKeywordIf("CURRENT ROW"))
result = s4.excludeCurrentRow();
else if (parseKeywordIf("TIES"))
result = s4.excludeTies();
else if (parseKeywordIf("GROUP"))
result = s4.excludeGroup();
else if (parseKeywordIf("NO OTHERS"))
result = s4.excludeNoOthers();
else
throw expected("CURRENT ROW", "TIES", "GROUP", "NO OTHERS");
else
result = s4;
} else
result = s2;
if (result != null)
return result;
else if (windowName != null)
return null;
else if ((windowName = parseIdentifierIf()) != null)
return parseWindowSpecificationIf(windowName, orderByAllowed);
else
return null;
}
use of org.jooq.WindowSpecification in project jOOQ by jOOQ.
the class DefaultParseContext method parseAggregateFunctionIf.
private final Field<?> parseAggregateFunctionIf(boolean basic, AggregateFunction<?> f) {
AggregateFunction<?> agg = null;
AggregateFilterStep<?> filter = null;
WindowBeforeOverStep<?> over = null;
Object keep = null;
Field<?> result = null;
Condition condition = null;
keep = over = filter = agg = f != null ? f : parseCountIf();
if (filter == null) {
Field<?> field = parseGeneralSetFunctionIf();
if (field != null && !(field instanceof AggregateFunction))
return field;
keep = over = filter = agg = (AggregateFunction<?>) field;
}
if (filter == null && !basic)
over = filter = agg = parseBinarySetFunctionIf();
if (filter == null && !basic)
over = filter = parseOrderedSetFunctionIf();
if (filter == null && !basic)
over = filter = parseArrayAggFunctionIf();
if (filter == null && !basic)
over = filter = parseMultisetAggFunctionIf();
if (filter == null && !basic)
over = filter = parseXMLAggFunctionIf();
if (filter == null && !basic)
over = filter = parseJSONArrayAggFunctionIf();
if (filter == null && !basic)
over = filter = parseJSONObjectAggFunctionIf();
if (filter == null)
over = parseCountIfIf();
if (filter == null && over == null)
if (!basic)
return parseSpecialAggregateFunctionIf();
else
return null;
if (keep != null && filter != null && !basic && !ignoreProEdition() && parseKeywordIf("KEEP")) {
requireProEdition();
} else if (filter != null && !basic && parseKeywordIf("FILTER")) {
parse('(');
parseKeyword("WHERE");
condition = parseCondition();
parse(')');
result = over = filter.filterWhere(condition);
} else if (filter != null)
result = filter;
else
result = over;
if (!basic && parseKeywordIf("OVER")) {
Object nameOrSpecification = parseWindowNameOrSpecification(filter != null);
if (nameOrSpecification instanceof Name)
result = over.over((Name) nameOrSpecification);
else if (nameOrSpecification instanceof WindowSpecification)
result = over.over((WindowSpecification) nameOrSpecification);
else
result = over.over();
}
return result;
}
Aggregations