[#6485] [#6978] Add support for TRANSLATE() function

This commit is contained in:
lukaseder 2018-01-04 10:41:37 +01:00
parent 07085f3108
commit 6333877662
3 changed files with 41 additions and 3 deletions

View File

@ -598,13 +598,14 @@ term =
| 'STDDEV_POP' '(' field ')' [ over ]
| 'STDDEV_SAMP' '(' field ')' [ over ]
| 'SUM' '(' [ 'DISTINCT' | 'ALL' ] field ')' [ keep | filter ]
| truthValue
| 'TRIM' '(' field ')'
| 'TRUNC' '(' sum ',' sum ')'
| 'TAN' '(' sum ')'
| 'TANH' '(' sum ')'
| timeLiteral
| timestampLiteral
| 'TRANSLATE' '(' field ',' field ',' field ')'
| 'TRIM' '(' field ')'
| 'TRUNC' '(' sum ',' sum ')'
| truthValue
| ( 'UPPER' | 'UCASE' ) '(' field ')'
| 'VAR_POP' '(' field ')' [ over ]
| 'VAR_SAMP' '(' field ')' [ over ]

View File

@ -68,6 +68,7 @@ import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
// ...
// ...
import static org.jooq.impl.Term.ROW_NUMBER;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.EMPTY_QUERYPART;
@ -12541,6 +12542,24 @@ public class DSL {
return new Lpad(nullSafe(field), nullSafe(length), nullSafe(character));
}
/**
* Get the translate(field, from, to) function.
*
* @see #translate(Field, Field, Field)
*/
@Support({ POSTGRES })
public static Field<String> translate(Field<String> text, String from, String to) {
return translate(text, Tools.field(from), Tools.field(to));
}
/**
* Get the translate(field, from, to) function.
*/
@Support({ POSTGRES })
public static Field<String> translate(Field<String> text, Field<String> from, Field<String> to) {
return function("translate", text.getDataType(), text, from, to);
}
/**
* Get the repeat(field, count) function.
*

View File

@ -194,6 +194,7 @@ import static org.jooq.impl.DSL.tan;
import static org.jooq.impl.DSL.tanh;
import static org.jooq.impl.DSL.time;
import static org.jooq.impl.DSL.timestamp;
import static org.jooq.impl.DSL.translate;
import static org.jooq.impl.DSL.trim;
import static org.jooq.impl.DSL.unique;
import static org.jooq.impl.DSL.user;
@ -3448,6 +3449,8 @@ final class ParserImpl implements Parser {
if (S.is(type))
if ((field = parseFieldTrimIf(ctx)) != null)
return field;
else if ((field = parseFieldTranslateIf(ctx)) != null)
return field;
if (N.is(type))
if ((field = parseFieldTruncIf(ctx)) != null)
@ -4058,6 +4061,21 @@ final class ParserImpl implements Parser {
return null;
}
private static final Field<?> parseFieldTranslateIf(ParserContext ctx) {
if (parseFunctionNameIf(ctx, "TRANSLATE")) {
parse(ctx, '(');
Field<String> f1 = (Field) parseField(ctx, S);
parse(ctx, ',');
Field<String> f2 = (Field) parseField(ctx, S);
parse(ctx, ',');
Field<String> f3 = (Field) parseField(ctx, S);
parse(ctx, ')');
return translate(f1, f2, f3);
}
return null;
}
private static final Field<?> parseFieldRtrimIf(ParserContext ctx) {
if (parseFunctionNameIf(ctx, "RTRIM")) {
parse(ctx, '(');