-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtestPresto.java
More file actions
85 lines (76 loc) · 3.28 KB
/
Copy pathtestPresto.java
File metadata and controls
85 lines (76 loc) · 3.28 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gettablecolumn;
import demos.gettablecolumns.TGetTableColumn;
import gudusoft.gsqlparser.EDbVendor;
import junit.framework.TestCase;
public class testPresto extends TestCase {
static void doTest(String inputQuery, String desireResult){
TGetTableColumn getTableColumn = new TGetTableColumn(EDbVendor.dbvpresto);
getTableColumn.isConsole = false;
getTableColumn.showTableEffect = false;
getTableColumn.showColumnLocation = false;
getTableColumn.showTreeStructure = false;
getTableColumn.showDatatype = true;
getTableColumn.runText(inputQuery);
// System.out.println(getTableColumn.outList.toString().trim());
assertTrue(getTableColumn.outList.toString().trim().equalsIgnoreCase(desireResult));
}
public static void testUnnest1() {
doTest("SELECT student, score\n" +
"FROM tests\n" +
"CROSS JOIN UNNEST(scores) AS t (score);",
"Tables:\n" +
"t(unnest table)\n" +
"tests\n" +
"\n" +
"Fields:\n" +
"(unnest-table:t).score\n" +
"tests.scores\n" +
"tests.student");
}
public static void testUnnest2() {
doTest("SELECT numbers, animals, n, a\n" +
"FROM (\n" +
" VALUES\n" +
" (ARRAY[2, 5], ARRAY['dog', 'cat', 'bird']),\n" +
" (ARRAY[7, 8, 9], ARRAY['cow', 'pig'])\n" +
") AS x (numbers, animals)\n" +
"CROSS JOIN UNNEST(numbers, animals) AS t (n, a);",
"Tables:\n" +
"t(unnest table)\n" +
"\n" +
"Fields:\n" +
"(unnest-table:t).a\n" +
"(unnest-table:t).n");
}
public static void testUnnest3() {
doTest("SELECT numbers, n, a\n" +
"FROM (\n" +
" VALUES\n" +
" (ARRAY[2, 5]),\n" +
" (ARRAY[7, 8, 9])\n" +
") AS x (numbers)\n" +
"CROSS JOIN UNNEST(numbers) WITH ORDINALITY AS t (n, a);",
"Tables:\n" +
"t(unnest table)\n" +
"\n" +
"Fields:\n" +
"(unnest-table:t).a\n" +
"(unnest-table:t).n");
}
public static void testUnnest4() {
doTest("SELECT\n" +
" animals, a, n\n" +
"FROM (\n" +
" VALUES\n" +
" (MAP(ARRAY['dog', 'cat', 'bird'], ARRAY[1, 2, 0])),\n" +
" (MAP(ARRAY['dog', 'cat'], ARRAY[4, 5]))\n" +
") AS x (animals)\n" +
"CROSS JOIN UNNEST(animals) AS t (a, n);",
"Tables:\n" +
"t(unnest table)\n" +
"\n" +
"Fields:\n" +
"(unnest-table:t).a\n" +
"(unnest-table:t).n");
}
}