use of org.jooq.WindowSpecificationExcludeStep 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;
}
Aggregations