Skip to content

Commit

Permalink
[#7171] Parse and fail clauses available only in the pro edition
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Mar 9, 2018
1 parent a6ac44d commit 26673d4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
5 changes: 4 additions & 1 deletion jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.11.txt
Expand Up @@ -431,10 +431,13 @@ tableFactor =
'LATERAL' '(' select ')' [ correlationName ]
| '(' select ')' [ correlationName ]
| values [ correlationName ]
| tableName [ versions ] [ correlationName ]
| tableName [ tableHints ] [ versions ] [ correlationName ]
| '(' table ')' [ correlationName ]
;

tableHints = 'WITH' '(' tableHint { ',' tableHint } ')'
;

pivot = todo
;

Expand Down
94 changes: 56 additions & 38 deletions jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
Expand Up @@ -775,10 +775,11 @@ else if (peekKeyword(ctx, "FETCH"))
if (offsetPostgres) {
result.addLimit(limit);

if (parseKeywordIf(ctx, "PERCENT") && ctx.requireProEdition())




;

if (parseKeywordIf(ctx, "WITH TIES"))
result.setWithTies(true);
Expand All @@ -788,10 +789,11 @@ else if (parseIf(ctx, ',')) {
}
else {

if (parseKeywordIf(ctx, "PERCENT") && ctx.requireProEdition())




;

if (parseKeywordIf(ctx, "WITH TIES"))
result.setWithTies(true);
Expand All @@ -806,10 +808,11 @@ else if (!offsetPostgres && parseKeywordIf(ctx, "FETCH")) {
parseAndGetKeyword(ctx, "FIRST", "NEXT");
result.addLimit(inline((int) (long) defaultIfNull(parseUnsignedIntegerIf(ctx), 1L)));

if (parseKeywordIf(ctx, "PERCENT") && ctx.requireProEdition())




;

parseAndGetKeyword(ctx, "ROW", "ROWS");
if (parseKeywordIf(ctx, "WITH TIES"))
Expand All @@ -831,10 +834,11 @@ else if (parseKeywordIf(ctx, "UPDATE")) {

if (parseKeywordIf(ctx, "NOWAIT"))
result.setForUpdateNoWait();
else if (parseKeywordIf(ctx, "WAIT") && ctx.requireProEdition())




;
else if (parseKeywordIf(ctx, "SKIP LOCKED"))
result.setForUpdateSkipLocked();
}
Expand Down Expand Up @@ -923,18 +927,13 @@ private static final SelectQueryImpl<Record> parseQueryPrimary(ParserContext ctx

Long limit = null;
Long offset = null;



boolean percent = false;
boolean withTies = false;

// T-SQL style TOP .. START AT
if (parseKeywordIf(ctx, "TOP")) {
limit = parseUnsignedInteger(ctx);




percent = parseKeywordIf(ctx, "PERCENT") && ctx.requireProEdition();

if (parseKeywordIf(ctx, "START AT"))
offset = parseUnsignedInteger(ctx);
Expand Down Expand Up @@ -1088,10 +1087,11 @@ else if (parseKeywordIf(ctx, "GROUPING SETS")) {
else
result.addLimit((int) (long) limit);

if (percent)




;

if (withTies)
result.setWithTies(true);
Expand Down Expand Up @@ -3060,18 +3060,19 @@ else if (peekKeyword(ctx, "VALUES")) {
else {
result = parseTableName(ctx);

if (parseKeywordIf(ctx, "WITH") && ctx.requireProEdition()) {









}
// TODO Sample clause
}

if (parseKeywordIf(ctx, "VERSIONS") && ctx.requireProEdition()) {



Expand Down Expand Up @@ -3101,6 +3102,8 @@ else if (peekKeyword(ctx, "VALUES")) {



}
else if (parseKeywordIf(ctx, "AS OF") && ctx.requireProEdition()) {



Expand All @@ -3111,7 +3114,9 @@ else if (peekKeyword(ctx, "VALUES")) {



}

if (parseKeywordIf(ctx, "PIVOT") && ctx.requireProEdition()) {



Expand Down Expand Up @@ -3159,12 +3164,9 @@ else if (peekKeyword(ctx, "VALUES")) {




}

// TODO UNPIVOT
// else if (parseKeywordIf(ctx, "UNPIVOT")) {
//
// }

Name alias = null;
List<Name> columnAliases = null;
Expand Down Expand Up @@ -3328,15 +3330,17 @@ private static final Table<?> parseJoinedTableIf(ParserContext ctx, Table<?> lef
case LEFT_OUTER_JOIN:
case FULL_OUTER_JOIN:
case RIGHT_OUTER_JOIN:
if (parseKeywordIf(ctx, "PARTITION BY")) {
ctx.requireProEdition();






}



// No break

case JOIN:
case STRAIGHT_JOIN:
Expand Down Expand Up @@ -3675,10 +3679,11 @@ else if (sign == Sign.PLUS)
else if ((r = parseFieldUnsignedNumericLiteralIf(ctx, Sign.MINUS)) == null)
r = toField(ctx, parseTerm(ctx, type, prefix)).neg();

if (parseIf(ctx, "(+)") && ctx.requireProEdition())




;

while (parseIf(ctx, "::"))
r = cast(toField(ctx, r), parseDataType(ctx));
Expand Down Expand Up @@ -3863,10 +3868,8 @@ else if (parseFunctionNameIf(ctx, "EXP"))
case 'G':
if ((field = parseFieldGreatestIf(ctx)) != null)
return field;




else if (N.is(type) && (field = parseFieldGroupIdIf(ctx)) != null)
return field;
else if (N.is(type) && (field = parseFieldGroupingIdIf(ctx)) != null)
return field;
else if (N.is(type) && (field = parseFieldGroupingIf(ctx)) != null)
Expand Down Expand Up @@ -4433,18 +4436,20 @@ private static final Field<?> parseFieldGroupingIf(ParserContext ctx) {
return null;
}

private static final Field<?> parseFieldGroupIdIf(ParserContext ctx) {
if (parseFunctionNameIf(ctx, "GROUP_ID")) {
ctx.requireProEdition();







}





return null;
}

private static final Field<?> parseFieldGroupingIdIf(ParserContext ctx) {
if (parseFunctionNameIf(ctx, "GROUPING_ID")) {
Expand Down Expand Up @@ -5186,6 +5191,8 @@ private static final Field<?> parseAggregateFunctionIf(ParserContext ctx, boolea
else
return null;

if (keep != null && filter != null && !basic && parseKeywordIf(ctx, "KEEP")) {
ctx.requireProEdition();



Expand All @@ -5204,9 +5211,8 @@ private static final Field<?> parseAggregateFunctionIf(ParserContext ctx, boolea





if (filter != null && !basic && parseKeywordIf(ctx, "FILTER")) {
}
else if (filter != null && !basic && parseKeywordIf(ctx, "FILTER")) {
parse(ctx, '(');
parseKeyword(ctx, "WHERE");
condition = parseCondition(ctx);
Expand Down Expand Up @@ -5590,13 +5596,17 @@ private static final Field<?> parseFieldNthValueIf(ParserContext ctx) {
private static final Field<?> parseWindowFunction(ParserContext ctx, WindowIgnoreNullsStep s1, WindowOverStep<?> s2) {
if (s1 != null) {

if (parseKeywordIf(ctx, "RESPECT NULLS") && ctx.requireProEdition())



;
else if (parseKeywordIf(ctx, "IGNORE NULLS") && ctx.requireProEdition())




;
else
s2 = s1;
}

Expand Down Expand Up @@ -7310,6 +7320,13 @@ static final class ParserContext {
this.bindings = bindings;
}

boolean requireProEdition() {
if (!PRO_EDITION)
throw exception("Feature only supported in pro edition");

return true;
}

String substring(int startPosition, int endPosition) {
return new String(sql, startPosition, endPosition - startPosition);
}
Expand All @@ -7319,7 +7336,7 @@ ParserException internalError() {
}

ParserException expected(String object) {
return new ParserException(mark(), object + " expected");
return init(new ParserException(mark(), object + " expected"));
}

ParserException expected(String... objects) {
Expand All @@ -7333,19 +7350,19 @@ else if (i == objects.length - 1)
else
sb.append(", ").append(objects[i]);

return new ParserException(mark(), sb.toString() + " expected");
return init(new ParserException(mark(), sb.toString() + " expected"));
}

ParserException notImplemented(String feature) {
return new ParserException(mark(), feature + " not yet implemented");
return init(new ParserException(mark(), feature + " not yet implemented"));
}

ParserException unsupportedClause() {
return new ParserException(mark(), "Unsupported clause");
return init(new ParserException(mark(), "Unsupported clause"));
}

ParserException exception(String message) {
return new ParserException(mark(), message);
return init(new ParserException(mark(), message));
}

ParserException init(ParserException e) {
Expand Down Expand Up @@ -7519,6 +7536,7 @@ private static enum BinarySetFunctionType {

private static final Ignore IGNORE = Reflect.on(DSL.query("/* ignored */")).as(Ignore.class);
private static final Ignore IGNORE_NO_DELIMITER = Reflect.on(DSL.query("/* ignored */")).as(Ignore.class);
private static final boolean PRO_EDITION = false ;

private static interface Ignore
extends
Expand Down

0 comments on commit 26673d4

Please sign in to comment.