Skip to content

Commit

Permalink
[#7171] Support parsing MySQL's FIELD() function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed May 16, 2018
1 parent b405aeb commit f9b63e1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
Expand Up @@ -630,6 +630,7 @@ term =
| 'EXP' '(' sum ')'
| 'EVERY' '(' field ')' [ filter ] [ over ]
| 'FLOOR' '(' sum ')'
| 'FIELD' '(' field ',' field { ',' field } ')'
| 'FIRST_VALUE' '(' field ')' over
| 'GETDATE' '(' ')'
| 'GREATEST' '(' fields ')'
Expand Down
56 changes: 46 additions & 10 deletions jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
Expand Up @@ -4352,6 +4352,8 @@ else if (parseFunctionNameIf(ctx, "EXP"))

if ((field = parseFieldFirstValueIf(ctx)) != null)
return field;
else if ((field = parseFieldFieldIf(ctx)) != null)
return field;

break;

Expand Down Expand Up @@ -5322,12 +5324,14 @@ else if (parseKeywordIf(ctx, "DW"))
if (parseKeywordIf(ctx, "MINUTE") ||
parseKeywordIf(ctx, "MI"))
return DatePart.MINUTE;
else if (parseKeywordIf(ctx, "MICROSECOND") ||
parseKeywordIf(ctx, "MCS"))
return DatePart.MICROSECOND;
else if (parseKeywordIf(ctx, "MILLISECOND") ||
parseKeywordIf(ctx, "MS"))
return DatePart.MILLISECOND;








else if (parseKeywordIf(ctx, "MONTH") ||
parseKeywordIf(ctx, "MM") ||
parseKeywordIf(ctx, "M"))
Expand All @@ -5337,12 +5341,14 @@ else if (parseKeywordIf(ctx, "MONTH") ||

case 'n':
case 'N':
if (parseKeywordIf(ctx, "NANOSECOND") ||
parseKeywordIf(ctx, "NS"))
return DatePart.NANOSECOND;
else if (parseKeywordIf(ctx, "N"))
if (parseKeywordIf(ctx, "N"))
return DatePart.MINUTE;






break;

case 'q':
Expand Down Expand Up @@ -5996,6 +6002,36 @@ private static final Field<?> parseFieldCoalesceIf(ParserContext ctx) {
return null;
}

private static final <T, Z> Field<?> parseFieldFieldIf(ParserContext ctx) {
if (parseKeywordIf(ctx, "FIELD")) {
parse(ctx, '(');

List<Field<?>> args = new ArrayList<Field<?>>();

args.add(parseField(ctx));
parse(ctx, ',');

int i = 1;
do {
args.add(parseField(ctx));
args.add(inline(i++));
}
while (parseIf(ctx, ','));

args.add(inline(0));
parse(ctx, ')');

return DSL.decode(
(Field<T>) args.get(0),
(Field<T>) args.get(1),
(Field<Z>) args.get(2),
args.subList(3, args.size()).toArray(EMPTY_FIELD)
);
}

return null;
}

private static final Field<?> parseFieldCaseIf(ParserContext ctx) {
if (parseKeywordIf(ctx, "CASE")) {
if (parseKeywordIf(ctx, "WHEN")) {
Expand Down

0 comments on commit f9b63e1

Please sign in to comment.