forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWithItemTest.java
More file actions
56 lines (51 loc) · 1.85 KB
/
WithItemTest.java
File metadata and controls
56 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2025 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.select;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class WithItemTest {
@Test
void testNotMaterializedIssue2251() throws JSQLParserException {
String sqlStr = "WITH devices AS NOT MATERIALIZED (\n"
+ " SELECT\n"
+ " d.uuid AS device_uuid\n"
+ " FROM active_devices d\n"
+ ")\n"
+ "SELECT 1;";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@ParameterizedTest
@ValueSource(strings = {
"WITH\n" +
" FUNCTION doubleup(x integer)\n" +
" RETURNS integer\n" +
" RETURN x * 2\n" +
"SELECT doubleup(21);\n",
"WITH\n" +
" FUNCTION doubleup(x integer)\n" +
" RETURNS integer\n" +
" RETURN x * 2,\n" +
" FUNCTION doubleupplusone(x integer)\n" +
" RETURNS integer\n" +
" RETURN doubleup(x) + 1\n" +
"SELECT doubleupplusone(21);",
"WITH\n" +
" FUNCTION takesArray(x array<double>)\n" +
" RETURNS double\n" +
" RETURN x[1] + x[2] + x[3]\n" +
"SELECT takesArray(ARRAY[1.0, 2.0, 3.0]);"
})
void testWithFunction(String sqlStr) throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}