|
19 | 19 | import net.sf.jsqlparser.expression.JsonFunction; |
20 | 20 | import net.sf.jsqlparser.expression.TernaryExpression; |
21 | 21 | import net.sf.jsqlparser.expression.Function; |
| 22 | +import net.sf.jsqlparser.expression.RowPatternFunction; |
22 | 23 | import net.sf.jsqlparser.expression.WindowElement; |
23 | 24 | import net.sf.jsqlparser.expression.WindowOffset; |
24 | 25 | import net.sf.jsqlparser.expression.XMLSerializeExpr; |
@@ -860,4 +861,44 @@ void testDialectNonReservedKeywordsKeepTheirClauses() throws JSQLParserException |
860 | 861 | assertTrue(((Truncate) assertRoundTrip("TRUNCATE ONLY t", Dialect.POSTGRESQL)) |
861 | 862 | .isOnly()); |
862 | 863 | } |
| 864 | + |
| 865 | + // RUNNING, FINAL and APPROXIMATE start a function call only before a function name. |
| 866 | + public static Stream<Arguments> functionPrefixWordsAsNames() { |
| 867 | + return Stream.of(Arguments.of("running", null), Arguments.of("running", Dialect.MYSQL), |
| 868 | + Arguments.of("running", Dialect.POSTGRESQL), Arguments.of("approximate", null), |
| 869 | + Arguments.of("approximate", Dialect.MYSQL), |
| 870 | + Arguments.of("approximate", Dialect.POSTGRESQL), |
| 871 | + Arguments.of("final", Dialect.MYSQL), Arguments.of("final", Dialect.POSTGRESQL)); |
| 872 | + } |
| 873 | + |
| 874 | + @ParameterizedTest(name = "{1} {0}") |
| 875 | + @MethodSource("functionPrefixWordsAsNames") |
| 876 | + void testFunctionPrefixWordBeforeParenthesis(String word, Dialect dialect) |
| 877 | + throws JSQLParserException { |
| 878 | + PlainSelect select = (PlainSelect) assertRoundTrip( |
| 879 | + "SELECT * FROM t WHERE " + word + " IN (1, 2)", dialect); |
| 880 | + assertEquals(word, assertInstanceOf(Column.class, |
| 881 | + assertInstanceOf(InExpression.class, select.getWhere()).getLeftExpression()) |
| 882 | + .getColumnName()); |
| 883 | + assertRoundTrip("SELECT * FROM t WHERE " + word + " LIKE ('a%')", dialect); |
| 884 | + assertRoundTrip("SELECT " + word + " = (1) FROM t", dialect); |
| 885 | + assertRoundTrip("CREATE TABLE t (" + word + " INT, CHECK (" + word + " IN (1, 2)))", |
| 886 | + dialect); |
| 887 | + } |
| 888 | + |
| 889 | + @Test |
| 890 | + void testFunctionPrefixWordsKeepTheirFunctionCalls() throws JSQLParserException { |
| 891 | + assertRoundTrip("CREATE TABLE t (running INT) PARTITION BY RANGE (running)" |
| 892 | + + " (PARTITION p0 VALUES LESS THAN (10))", Dialect.MYSQL); |
| 893 | + assertEquals("approximate", assertInstanceOf(Function.class, ((PlainSelect) assertRoundTrip( |
| 894 | + "SELECT approximate(x) FROM t", null)).getSelectItem(0).getExpression()).getName()); |
| 895 | + assertInstanceOf(Function.class, ((PlainSelect) assertRoundTrip( |
| 896 | + "SELECT APPROXIMATE COUNT(DISTINCT a) FROM t", null)).getSelectItem(0) |
| 897 | + .getExpression()); |
| 898 | + assertSqlCanBeParsedAndDeparsed("SELECT * FROM t MATCH_RECOGNIZE (ORDER BY a" |
| 899 | + + " MEASURES FINAL COUNT(*) AS c, RUNNING LAST(a) AS l PATTERN (x+)" |
| 900 | + + " DEFINE x AS a > 0)", true); |
| 901 | + assertInstanceOf(RowPatternFunction.class, |
| 902 | + CCJSqlParserUtil.parseExpression("FINAL COUNT(*)")); |
| 903 | + } |
863 | 904 | } |
0 commit comments