OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignServerTest.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import static org.junit.Assert.assertEquals;
4 
5 import com.google.gson.Gson;
6 import com.google.gson.JsonObject;
8 
9 import org.junit.Test;
10 
11 import ai.heavy.thrift.calciteserver.TPlanResult;
12 
13 public class ForeignServerTest extends DDLTest {
14  public ForeignServerTest() {
15  resourceDirPath = ForeignServerTest.class.getClassLoader().getResource("").getPath();
16  jsonTestDir = "foreignserver";
17  }
18 
19  @Test
20  public void AlterServerSetDataWrapper() throws Exception {
21  final JsonObject expectedJsonObject =
22  getJsonFromFile("alter_foreign_server_set_data_wrapper_csv.json");
23  final TPlanResult result = processDdlCommand(
24  "ALTER SERVER test_server SET FOREIGN DATA WRAPPER DELIMITED_FILE;");
25  final JsonObject actualJsonObject =
26  gson.fromJson(result.plan_result, JsonObject.class);
27 
28  assertEquals(expectedJsonObject, actualJsonObject);
29  }
30 
31  @Test
32  public void AlterServerSetOptions() throws Exception {
33  final JsonObject expectedJsonObject =
34  getJsonFromFile("alter_foreign_server_set_options.json");
35  final TPlanResult result = processDdlCommand(
36  "ALTER SERVER my_csv_server SET (base_path = '/home/my_user/data/new-csv/');");
37  final JsonObject actualJsonObject =
38  gson.fromJson(result.plan_result, JsonObject.class);
39 
40  assertEquals(expectedJsonObject, actualJsonObject);
41  }
42 
43  @Test
44  public void AlterServerChangeOwner() throws Exception {
45  final JsonObject expectedJsonObject =
46  getJsonFromFile("alter_foreign_server_change_owner.json");
47  final TPlanResult result =
48  processDdlCommand("ALTER SERVER my_csv_server OWNER TO Joe;");
49  final JsonObject actualJsonObject =
50  gson.fromJson(result.plan_result, JsonObject.class);
51 
52  assertEquals(expectedJsonObject, actualJsonObject);
53  }
54 
55  @Test
56  public void AlterServerRenameServer() throws Exception {
57  final JsonObject expectedJsonObject =
58  getJsonFromFile("alter_foreign_server_rename_server.json");
59  final TPlanResult result =
60  processDdlCommand("ALTER SERVER my_csv_server RENAME TO my_new_csv_server;");
61  final JsonObject actualJsonObject =
62  gson.fromJson(result.plan_result, JsonObject.class);
63 
64  assertEquals(expectedJsonObject, actualJsonObject);
65  }
66 
67  @Test
68  public void CreateServerDdlCommand() throws Exception {
69  final JsonObject expectedJsonObject = getJsonFromFile("create_foreign_server.json");
70  final TPlanResult result = processDdlCommand(
71  "CREATE SERVER test_server FOREIGN DATA WRAPPER test_data_wrapper "
72  + "WITH (attribute_1 = 'value_1', attribute_2 = 2);");
73  final JsonObject actualJsonObject =
74  gson.fromJson(result.plan_result, JsonObject.class);
75 
76  assertEquals(expectedJsonObject, actualJsonObject);
77  }
78 
79  @Test
80  public void CreateServerDdlCommandWithIfNotExists() throws Exception {
81  final JsonObject expectedJsonObject =
82  getJsonFromFile("create_foreign_server_w_if_not_exists.json");
83  final TPlanResult result = processDdlCommand(
84  "CREATE SERVER IF NOT EXISTS test_server FOREIGN DATA WRAPPER test_data_wrapper "
85  + "WITH (attribute_1 = 'value_1', attribute_2 = 2);");
86  final JsonObject actualJsonObject =
87  gson.fromJson(result.plan_result, JsonObject.class);
88 
89  assertEquals(expectedJsonObject, actualJsonObject);
90  }
91 
92  @Test
93  public void DropServerDdlCommand() throws Exception {
94  final JsonObject expectedJsonObject = getJsonFromFile("drop_foreign_server.json");
95  final TPlanResult result = processDdlCommand("DROP SERVER test_server;");
96  final JsonObject actualJsonObject =
97  gson.fromJson(result.plan_result, JsonObject.class);
98 
99  assertEquals(expectedJsonObject, actualJsonObject);
100  }
101 
102  @Test
103  public void DropServerDdlCommandWithIfExists() throws Exception {
104  final JsonObject expectedJsonObject =
105  getJsonFromFile("drop_foreign_server_w_if_exists.json");
106  final TPlanResult result = processDdlCommand("DROP SERVER IF EXISTS test_server;");
107  final JsonObject actualJsonObject =
108  gson.fromJson(result.plan_result, JsonObject.class);
109 
110  assertEquals(expectedJsonObject, actualJsonObject);
111  }
112 
113  @Test
114  public void ShowForeignServers() throws Exception {
115  final JsonObject expectedJsonObject = getJsonFromFile("show_foreign_server.json");
116  final TPlanResult result = processDdlCommand("SHOW SERVERS;");
117  final JsonObject actualJsonObject =
118  gson.fromJson(result.plan_result, JsonObject.class);
119  assertEquals(expectedJsonObject, actualJsonObject);
120  }
121 
122  @Test
123  public void ShowForeignServersWhere() throws Exception {
124  final JsonObject expectedJsonObject =
125  getJsonFromFile("show_foreign_server_where.json");
126  final TPlanResult result =
127  processDdlCommand("SHOW SERVERS WHERE data_wrapper = 'delimited_file';");
128  final JsonObject actualJsonObject =
129  gson.fromJson(result.plan_result, JsonObject.class);
130  assertEquals(expectedJsonObject, actualJsonObject);
131  }
132 
133  @Test
134  public void ShowForeignServersLike() throws Exception {
135  final JsonObject expectedJsonObject =
136  getJsonFromFile("show_foreign_server_like.json");
137  final TPlanResult result =
138  processDdlCommand("SHOW SERVERS WHERE data_wrapper LIKE 'omnisci_%';");
139  final JsonObject actualJsonObject =
140  gson.fromJson(result.plan_result, JsonObject.class);
141  assertEquals(expectedJsonObject, actualJsonObject);
142  }
143 
144  @Test
145  public void ShowForeignServersLikeAnd() throws Exception {
146  final JsonObject expectedJsonObject =
147  getJsonFromFile("show_foreign_server_like_and.json");
148  final TPlanResult result = processDdlCommand(
149  "SHOW SERVERS WHERE data_wrapper LIKE 'omnisci_%' AND data_wrapper LIKE '%_csv';");
150  final JsonObject actualJsonObject =
151  gson.fromJson(result.plan_result, JsonObject.class);
152  assertEquals(expectedJsonObject, actualJsonObject);
153  }
154 
155  @Test
156  public void ShowForeignServersEqOr() throws Exception {
157  final JsonObject expectedJsonObject =
158  getJsonFromFile("show_foreign_server_eq_or.json");
159  final TPlanResult result = processDdlCommand(
160  "SHOW SERVERS WHERE data_wrapper LIKE 'omnisci_%' OR data_wrapper = 'test';");
161  final JsonObject actualJsonObject =
162  gson.fromJson(result.plan_result, JsonObject.class);
163  assertEquals(expectedJsonObject, actualJsonObject);
164  }
165 
166  @Test
167  public void ShowForeignServersLikeAndLikeOrEq() throws Exception {
168  final JsonObject expectedJsonObject =
169  getJsonFromFile("show_foreign_server_like_and_like_or_eq.json");
170  final TPlanResult result = processDdlCommand(
171  "SHOW SERVERS WHERE data_wrapper LIKE 'omnisci_%' AND created_at LIKE '2020%' OR data_wrapper = 'test';");
172  final JsonObject actualJsonObject =
173  gson.fromJson(result.plan_result, JsonObject.class);
174  assertEquals(expectedJsonObject, actualJsonObject);
175  }
176 }
JsonObject getJsonFromFile(final String fileName)
Definition: DDLTest.java:51
TPlanResult processDdlCommand(final String ddlCommand)
Definition: DDLTest.java:35