use of org.jooq.WindowSpecificationRowsStep in project jOOQ by jOOQ.
the class ParserImpl method parseWindowNameOrSpecification.
private static Object parseWindowNameOrSpecification(ParserContext ctx, boolean orderByAllowed) {
Object result;
if (parseIf(ctx, '(')) {
WindowSpecificationOrderByStep s1 = null;
WindowSpecificationRowsStep s2 = null;
WindowSpecificationRowsAndStep s3 = null;
s1 = parseKeywordIf(ctx, "PARTITION BY") ? partitionBy(parseFields(ctx)) : null;
s2 = orderByAllowed && parseKeywordIf(ctx, "ORDER BY") ? s1 == null ? orderBy(parseSortSpecification(ctx)) : s1.orderBy(parseSortSpecification(ctx)) : s1;
boolean rows = orderByAllowed && parseKeywordIf(ctx, "ROWS");
if (rows || (orderByAllowed && parseKeywordIf(ctx, "RANGE"))) {
if (parseKeywordIf(ctx, "BETWEEN")) {
if (parseKeywordIf(ctx, "UNBOUNDED")) {
if (parseKeywordIf(ctx, "PRECEDING")) {
s3 = s2 == null ? rows ? rowsBetweenUnboundedPreceding() : rangeBetweenUnboundedPreceding() : rows ? s2.rowsBetweenUnboundedPreceding() : s2.rangeBetweenUnboundedPreceding();
} else {
parseKeyword(ctx, "FOLLOWING");
s3 = s2 == null ? rows ? rowsBetweenUnboundedFollowing() : rangeBetweenUnboundedFollowing() : rows ? s2.rowsBetweenUnboundedFollowing() : s2.rangeBetweenUnboundedFollowing();
}
} else if (parseKeywordIf(ctx, "CURRENT ROW")) {
s3 = s2 == null ? rows ? rowsBetweenCurrentRow() : rangeBetweenCurrentRow() : rows ? s2.rowsBetweenCurrentRow() : s2.rangeBetweenCurrentRow();
} else {
int number = (int) (long) parseUnsignedInteger(ctx);
if (parseKeywordIf(ctx, "PRECEDING")) {
s3 = s2 == null ? rows ? rowsBetweenPreceding(number) : rangeBetweenPreceding(number) : rows ? s2.rowsBetweenPreceding(number) : s2.rangeBetweenPreceding(number);
} else {
parseKeyword(ctx, "FOLLOWING");
s3 = s2 == null ? rows ? rowsBetweenFollowing(number) : rangeBetweenFollowing(number) : rows ? s2.rowsBetweenFollowing(number) : s2.rangeBetweenFollowing(number);
}
}
parseKeyword(ctx, "AND");
if (parseKeywordIf(ctx, "UNBOUNDED")) {
if (parseKeywordIf(ctx, "PRECEDING")) {
result = s3.andUnboundedPreceding();
} else {
parseKeyword(ctx, "FOLLOWING");
result = s3.andUnboundedFollowing();
}
} else if (parseKeywordIf(ctx, "CURRENT ROW")) {
result = s3.andCurrentRow();
} else {
int number = (int) (long) parseUnsignedInteger(ctx);
if (parseKeywordIf(ctx, "PRECEDING")) {
result = s3.andPreceding(number);
} else {
parseKeyword(ctx, "FOLLOWING");
result = s3.andFollowing(number);
}
}
} else {
if (parseKeywordIf(ctx, "UNBOUNDED")) {
if (parseKeywordIf(ctx, "PRECEDING")) {
result = s2 == null ? rows ? rowsUnboundedPreceding() : rangeUnboundedPreceding() : rows ? s2.rowsUnboundedPreceding() : s2.rangeUnboundedPreceding();
} else {
parseKeyword(ctx, "FOLLOWING");
result = s2 == null ? rows ? rowsUnboundedFollowing() : rangeUnboundedFollowing() : rows ? s2.rowsUnboundedFollowing() : s2.rangeUnboundedFollowing();
}
} else if (parseKeywordIf(ctx, "CURRENT ROW")) {
result = s2 == null ? rows ? rowsCurrentRow() : rangeCurrentRow() : rows ? s2.rowsCurrentRow() : s2.rangeCurrentRow();
} else {
int number = (int) (long) parseUnsignedInteger(ctx);
if (parseKeywordIf(ctx, "PRECEDING")) {
result = s2 == null ? rows ? rowsPreceding(number) : rangePreceding(number) : rows ? s2.rowsPreceding(number) : s2.rangePreceding(number);
} else {
parseKeyword(ctx, "FOLLOWING");
result = s2 == null ? rows ? rowsFollowing(number) : rangeFollowing(number) : rows ? s2.rowsFollowing(number) : s2.rangeFollowing(number);
}
}
}
} else {
result = s2;
}
parse(ctx, ')');
} else {
result = name(parseIdentifier(ctx));
}
return result;
}
use of org.jooq.WindowSpecificationRowsStep 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