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