[#7171] Support parsing Oracle DECODE function
This commit is contained in:
parent
6399be2373
commit
42ee53b027
@ -555,6 +555,7 @@ term =
|
||||
| dateLiteral
|
||||
| 'DATE_TRUNC' '(' stringLiteral ',' field ')'
|
||||
| 'DAY' '(' field ')'
|
||||
| 'DECODE' '(' field ',' field ',' field { ',' field } ')'
|
||||
| 'DENSE_RANK' ( '(' ')' over | '(' fields ')' withinGroup )
|
||||
| ( 'DEG' | 'DEGREE' ) '(' sum ')'
|
||||
| 'EXTRACT' '(' datePart 'FROM' field ')'
|
||||
@ -562,6 +563,7 @@ term =
|
||||
| 'EVERY' '(' field ')' [ filter ] [ over ]
|
||||
| 'FLOOR' '(' sum ')'
|
||||
| 'FIRST_VALUE' '(' field ')' over
|
||||
| 'GETDATE' '(' ')'
|
||||
| 'GREATEST' '(' fields ')'
|
||||
| 'GROUP_CONCAT' '(' [ 'DISTINCT' ] field [ 'ORDER BY' sortFields ] [ 'SEPARATOR' stringLiteral ] ')'
|
||||
| 'GROUP_ID' '(' ')'
|
||||
|
||||
@ -3835,6 +3835,9 @@ final class ParserImpl implements Parser {
|
||||
else if (parseFunctionNameIf(ctx, "DEGREE") || parseFunctionNameIf(ctx, "DEG"))
|
||||
return deg((Field) parseFieldSumParenthesised(ctx));
|
||||
|
||||
if ((field = parseFieldDecodeIf(ctx)) != null)
|
||||
return field;
|
||||
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
@ -4923,6 +4926,27 @@ final class ParserImpl implements Parser {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Field<?> parseFieldDecodeIf(ParserContext ctx) {
|
||||
if (parseFunctionNameIf(ctx, "DECODE")) {
|
||||
parse(ctx, '(');
|
||||
List<Field<?>> fields = parseFields(ctx);
|
||||
int size = fields.size();
|
||||
if (size < 3)
|
||||
throw ctx.expected("At least three arguments to DECODE()");
|
||||
|
||||
parse(ctx, ')');
|
||||
return DSL.decode(
|
||||
(Field<Object>) fields.get(0),
|
||||
(Field<Object>) fields.get(1),
|
||||
(Field<Object>) fields.get(2),
|
||||
(Field<Object>[]) (size == 3 ? EMPTY_FIELD : fields.subList(3, size).toArray(EMPTY_FIELD))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Field<?> parseFieldYearIf(ParserContext ctx) {
|
||||
if (parseFunctionNameIf(ctx, "YEAR")) {
|
||||
parse(ctx, '(');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user