OmniSciDB  2e3a973ef4
ForeignTableTest.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
5 
6 import com.google.gson.Gson;
7 import com.google.gson.JsonObject;
9 import com.omnisci.thrift.calciteserver.InvalidParseRequest;
10 import com.omnisci.thrift.calciteserver.TPlanResult;
11 
12 import org.junit.Test;
13 
14 public class ForeignTableTest extends DDLTest {
15  public ForeignTableTest() {
16  resourceDirPath = ForeignTableTest.class.getClassLoader().getResource("").getPath();
17  jsonTestDir = "foreigntable";
18  }
19 
20  @Test
21  public void createForeignTableOneCol() throws Exception {
22  final JsonObject expectedJsonObject = getJsonFromFile("cft_OneCol.json");
23  final TPlanResult result = processDdlCommand(
24  "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER) SERVER test_server;");
25  final JsonObject actualJsonObject =
26  gson.fromJson(result.plan_result, JsonObject.class);
27  assertEquals(expectedJsonObject, actualJsonObject);
28  }
29 
30  @Test
31  public void createForeignTableDecimal() throws Exception {
32  final JsonObject expectedJsonObject = getJsonFromFile("cft_Decimal.json");
33  final TPlanResult result = processDdlCommand(
34  "CREATE FOREIGN TABLE test_table (test_column_1 DECIMAL(10, 6)) SERVER test_server;");
35  final JsonObject actualJsonObject =
36  gson.fromJson(result.plan_result, JsonObject.class);
37  assertEquals(expectedJsonObject, actualJsonObject);
38  }
39 
40  @Test(expected = InvalidParseRequest.class)
41  public void createForeignTableDoubleDecimal() throws Exception {
42  final JsonObject expectedJsonObject = getJsonFromFile("cft_Decimal.json");
43  final TPlanResult result = processDdlCommand(
44  "CREATE FOREIGN TABLE test_table (test_column_1 DECIMAL(10, 6)(11,5)) SERVER test_server;");
45  final JsonObject actualJsonObject =
46  gson.fromJson(result.plan_result, JsonObject.class);
47  assertEquals(expectedJsonObject, actualJsonObject);
48  }
49 
50  @Test
51  public void createForeignTableIfNotExists() throws Exception {
52  final JsonObject expectedJsonObject = getJsonFromFile("cft_IfNotExists.json");
53  final TPlanResult result = processDdlCommand(
54  "CREATE FOREIGN TABLE IF NOT EXISTS test_table (test_column_1 INTEGER) "
55  + "SERVER test_server;");
56  final JsonObject actualJsonObject =
57  gson.fromJson(result.plan_result, JsonObject.class);
58  assertEquals(expectedJsonObject, actualJsonObject);
59  }
60 
61  @Test
62  public void createForeignTableTwoCol() throws Exception {
63  final JsonObject expectedJsonObject = getJsonFromFile("cft_TwoCol.json");
64  final TPlanResult result = processDdlCommand(
65  "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER, test_column_2 TEXT) "
66  + "SERVER test_server;");
67  final JsonObject actualJsonObject =
68  gson.fromJson(result.plan_result, JsonObject.class);
69  assertEquals(expectedJsonObject, actualJsonObject);
70  }
71 
72  @Test
73  public void createForeignTableNotNull() throws Exception {
74  final JsonObject expectedJsonObject = getJsonFromFile("cft_NotNull.json");
75  final TPlanResult result = processDdlCommand(
76  "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER NOT NULL) "
77  + "SERVER test_server;");
78  final JsonObject actualJsonObject =
79  gson.fromJson(result.plan_result, JsonObject.class);
80  assertEquals(expectedJsonObject, actualJsonObject);
81  }
82 
83  @Test
84  public void createForeignTableEncodingDict8() throws Exception {
85  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_Dict8.json");
86  final TPlanResult result = processDdlCommand(
87  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DICT(8)) "
88  + "SERVER test_server");
89  final JsonObject actualJsonObject =
90  gson.fromJson(result.plan_result, JsonObject.class);
91  assertEquals(expectedJsonObject, actualJsonObject);
92  }
93 
94  @Test
95  public void createForeignTableEncodingDict() throws Exception {
96  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_Dict.json");
97  final TPlanResult result = processDdlCommand(
98  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DICT) "
99  + "SERVER test_server");
100  final JsonObject actualJsonObject =
101  gson.fromJson(result.plan_result, JsonObject.class);
102  assertEquals(expectedJsonObject, actualJsonObject);
103  }
104 
105  @Test
106  public void createForeignTableEncodingNone() throws Exception {
107  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_None.json");
108  final TPlanResult result = processDdlCommand(
109  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING NONE) "
110  + "SERVER test_server");
111  final JsonObject actualJsonObject =
112  gson.fromJson(result.plan_result, JsonObject.class);
113  assertEquals(expectedJsonObject, actualJsonObject);
114  }
115 
116  @Test
117  public void createForeignTableEncodingFixed1() throws Exception {
118  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_Fixed1.json");
119  final TPlanResult result = processDdlCommand(
120  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING FIXED(1)) "
121  + "SERVER test_server");
122  final JsonObject actualJsonObject =
123  gson.fromJson(result.plan_result, JsonObject.class);
124  assertEquals(expectedJsonObject, actualJsonObject);
125  }
126 
127  @Test
128  public void createForeignTableEncodingDays1() throws Exception {
129  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_Days1.json");
130  final TPlanResult result = processDdlCommand(
131  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DAYS(1)) "
132  + "SERVER test_server");
133  final JsonObject actualJsonObject =
134  gson.fromJson(result.plan_result, JsonObject.class);
135  assertEquals(expectedJsonObject, actualJsonObject);
136  }
137 
138  @Test
139  public void createForeignTableEncodingCompressed32() throws Exception {
140  final JsonObject expectedJsonObject =
141  getJsonFromFile("cft_Encoding_Compressed32.json");
142  final TPlanResult result = processDdlCommand(
143  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING COMPRESSED(32)) "
144  + "SERVER test_server");
145  final JsonObject actualJsonObject =
146  gson.fromJson(result.plan_result, JsonObject.class);
147  assertEquals(expectedJsonObject, actualJsonObject);
148  }
149 
150  @Test
151  public void createForeignTableEncodingCompressed() throws Exception {
152  final JsonObject expectedJsonObject = getJsonFromFile("cft_Encoding_Compressed.json");
153  final TPlanResult result = processDdlCommand(
154  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING COMPRESSED) "
155  + "SERVER test_server");
156  final JsonObject actualJsonObject =
157  gson.fromJson(result.plan_result, JsonObject.class);
158  assertEquals(expectedJsonObject, actualJsonObject);
159  }
160 
161  @Test(expected = InvalidParseRequest.class)
162  public void createForeignTableEncodingNone1() throws Exception {
163  final TPlanResult result = processDdlCommand(
164  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING NONE(1)) "
165  + "SERVER test_server");
166  }
167 
168  @Test(expected = InvalidParseRequest.class)
169  public void createForeignTableEncodingFixedWithoutSize() throws Exception {
170  final TPlanResult result = processDdlCommand(
171  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING FIXED) "
172  + "SERVER test_server");
173  }
174 
175  @Test(expected = InvalidParseRequest.class)
176  public void createForeignTableEncodingDaysWithoutSize() throws Exception {
177  final TPlanResult result = processDdlCommand(
178  "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DAYS) "
179  + "SERVER test_server");
180  }
181 
182  @Test
183  public void createForeignTableColOptions() throws Exception {
184  final JsonObject expectedJsonObject = getJsonFromFile("cft_ColOptions.json");
185  final TPlanResult result =
186  processDdlCommand("CREATE FOREIGN TABLE test_table (test_column_1 INTEGER "
187  + "WITH ( option_1 = 'value_1', option_2 = 2)) SERVER test_server;");
188  final JsonObject actualJsonObject =
189  gson.fromJson(result.plan_result, JsonObject.class);
190  assertEquals(expectedJsonObject, actualJsonObject);
191  }
192 
193  @Test
194  public void createForeignTableOptions() throws Exception {
195  final JsonObject expectedJsonObject = getJsonFromFile("cft_Options.json");
196  final TPlanResult result =
197  processDdlCommand("CREATE FOREIGN TABLE test_table (test_column_1 INTEGER) "
198  + "SERVER test_server WITH ( option_1 = 'value_1', option_2 = 2);");
199  final JsonObject actualJsonObject =
200  gson.fromJson(result.plan_result, JsonObject.class);
201  assertEquals(expectedJsonObject, actualJsonObject);
202  }
203 
204  @Test
205  public void createForeignTableEscapeOption() throws Exception {
206  final JsonObject expectedJsonObject = getJsonFromFile("cft_EscapeOption.json");
207  final TPlanResult result =
208  processDdlCommand("CREATE FOREIGN TABLE test_table (test_column_1 INTEGER) "
209  + "SERVER test_server WITH ( escape = '\\');");
210  final JsonObject actualJsonObject =
211  gson.fromJson(result.plan_result, JsonObject.class);
212  assertEquals(expectedJsonObject, actualJsonObject);
213  }
214 
215  @Test
216  public void createForeignTableSchema() throws Exception {
217  final JsonObject expectedJsonObject = getJsonFromFile("cft_Schema.json");
218  final TPlanResult result =
219  processDdlCommand("CREATE FOREIGN TABLE test_table SCHEMA 'test_schema' "
220  + "SERVER test_server;");
221  final JsonObject actualJsonObject =
222  gson.fromJson(result.plan_result, JsonObject.class);
223  assertEquals(expectedJsonObject, actualJsonObject);
224  }
225 
226  @Test
227  public void createForeignTablePoint() throws Exception {
228  final JsonObject expectedJsonObject = getJsonFromFile("cft_Point.json");
229  final TPlanResult result = processDdlCommand(
230  "CREATE FOREIGN TABLE test_table (test_column_1 POINT) SERVER test_server;");
231  final JsonObject actualJsonObject =
232  gson.fromJson(result.plan_result, JsonObject.class);
233  assertEquals(expectedJsonObject, actualJsonObject);
234  }
235 
236  @Test
237  public void createForeignTableGeoPoint() throws Exception {
238  final JsonObject expectedJsonObject = getJsonFromFile("cft_Point.json");
239  final TPlanResult result = processDdlCommand(
240  "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT)) SERVER test_server;");
241  final JsonObject actualJsonObject =
242  gson.fromJson(result.plan_result, JsonObject.class);
243  assertEquals(expectedJsonObject, actualJsonObject);
244  }
245 
246  @Test
247  public void createForeignTableLinestring() throws Exception {
248  final JsonObject expectedJsonObject = getJsonFromFile("cft_Linestring.json");
249  final TPlanResult result = processDdlCommand(
250  "CREATE FOREIGN TABLE test_table (test_column_1 LINESTRING) SERVER test_server;");
251  final JsonObject actualJsonObject =
252  gson.fromJson(result.plan_result, JsonObject.class);
253  assertEquals(expectedJsonObject, actualJsonObject);
254  }
255 
256  @Test
257  public void createForeignTablePolygon() throws Exception {
258  final JsonObject expectedJsonObject = getJsonFromFile("cft_Polygon.json");
259  final TPlanResult result = processDdlCommand(
260  "CREATE FOREIGN TABLE test_table (test_column_1 POLYGON) SERVER test_server;");
261  final JsonObject actualJsonObject =
262  gson.fromJson(result.plan_result, JsonObject.class);
263  assertEquals(expectedJsonObject, actualJsonObject);
264  }
265 
266  @Test
267  public void createForeignTableMultiPolygon() throws Exception {
268  final JsonObject expectedJsonObject = getJsonFromFile("cft_MultiPolygon.json");
269  final TPlanResult result = processDdlCommand(
270  "CREATE FOREIGN TABLE test_table (test_column_1 MULTIPOLYGON) SERVER test_server;");
271  final JsonObject actualJsonObject =
272  gson.fromJson(result.plan_result, JsonObject.class);
273  assertEquals(expectedJsonObject, actualJsonObject);
274  }
275 
276  @Test
277  public void createForeignTableGeoPointMerc() throws Exception {
278  final JsonObject expectedJsonObject = getJsonFromFile("cft_GeoPointMerc.json");
279  final TPlanResult result = processDdlCommand(
280  "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT, 900913)) SERVER test_server;");
281  final JsonObject actualJsonObject =
282  gson.fromJson(result.plan_result, JsonObject.class);
283  assertEquals(expectedJsonObject, actualJsonObject);
284  }
285 
286  @Test
287  public void createForeignTableGeoPointWG() throws Exception {
288  final JsonObject expectedJsonObject = getJsonFromFile("cft_GeoPointWG.json");
289  final TPlanResult result = processDdlCommand(
290  "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT, 4326)) SERVER test_server;");
291  final JsonObject actualJsonObject =
292  gson.fromJson(result.plan_result, JsonObject.class);
293  assertEquals(expectedJsonObject, actualJsonObject);
294  }
295 
296  @Test
297  public void createForeignTablePointCompressed() throws Exception {
298  final JsonObject expectedJsonObject = getJsonFromFile("cft_PointCompressed.json");
299  final TPlanResult result = processDdlCommand(
300  "CREATE FOREIGN TABLE test_table (test_column_1 POINT ENCODING COMPRESSED(32)) SERVER test_server;");
301  final JsonObject actualJsonObject =
302  gson.fromJson(result.plan_result, JsonObject.class);
303  assertEquals(expectedJsonObject, actualJsonObject);
304  }
305 
306  @Test
307  public void createForeignTableBigInt() throws Exception {
308  final JsonObject expectedJsonObject = getJsonFromFile("cft_BigInt.json");
309  final TPlanResult result = processDdlCommand(
310  "CREATE FOREIGN TABLE test_table (test_column_1 BIGINT) SERVER test_server;");
311  final JsonObject actualJsonObject =
312  gson.fromJson(result.plan_result, JsonObject.class);
313  assertEquals(expectedJsonObject, actualJsonObject);
314  }
315 
316  @Test
317  public void createForeignTableBoolean() throws Exception {
318  final JsonObject expectedJsonObject = getJsonFromFile("cft_Boolean.json");
319  final TPlanResult result = processDdlCommand(
320  "CREATE FOREIGN TABLE test_table (test_column_1 BOOLEAN) SERVER test_server;");
321  final JsonObject actualJsonObject =
322  gson.fromJson(result.plan_result, JsonObject.class);
323  assertEquals(expectedJsonObject, actualJsonObject);
324  }
325 
326  @Test
327  public void createForeignTableDate() throws Exception {
328  final JsonObject expectedJsonObject = getJsonFromFile("cft_Date.json");
329  final TPlanResult result = processDdlCommand(
330  "CREATE FOREIGN TABLE test_table (test_column_1 DATE) SERVER test_server;");
331  final JsonObject actualJsonObject =
332  gson.fromJson(result.plan_result, JsonObject.class);
333  assertEquals(expectedJsonObject, actualJsonObject);
334  }
335 
336  @Test
337  public void createForeignTableDouble() throws Exception {
338  final JsonObject expectedJsonObject = getJsonFromFile("cft_Double.json");
339  final TPlanResult result = processDdlCommand(
340  "CREATE FOREIGN TABLE test_table (test_column_1 DOUBLE) SERVER test_server;");
341  final JsonObject actualJsonObject =
342  gson.fromJson(result.plan_result, JsonObject.class);
343  assertEquals(expectedJsonObject, actualJsonObject);
344  }
345 
346  @Test
347  public void createForeignTableEpoch() throws Exception {
348  final JsonObject expectedJsonObject = getJsonFromFile("cft_Epoch.json");
349  final TPlanResult result = processDdlCommand(
350  "CREATE FOREIGN TABLE test_table (test_column_1 EPOCH) SERVER test_server;");
351  final JsonObject actualJsonObject =
352  gson.fromJson(result.plan_result, JsonObject.class);
353  assertEquals(expectedJsonObject, actualJsonObject);
354  }
355 
356  @Test
357  public void createForeignTableFloat() throws Exception {
358  final JsonObject expectedJsonObject = getJsonFromFile("cft_Float.json");
359  final TPlanResult result = processDdlCommand(
360  "CREATE FOREIGN TABLE test_table (test_column_1 FLOAT) SERVER test_server;");
361  final JsonObject actualJsonObject =
362  gson.fromJson(result.plan_result, JsonObject.class);
363  assertEquals(expectedJsonObject, actualJsonObject);
364  }
365 
366  @Test
367  public void createForeignTableSmallInt() throws Exception {
368  final JsonObject expectedJsonObject = getJsonFromFile("cft_SmallInt.json");
369  final TPlanResult result = processDdlCommand(
370  "CREATE FOREIGN TABLE test_table (test_column_1 SMALLINT) SERVER test_server;");
371  final JsonObject actualJsonObject =
372  gson.fromJson(result.plan_result, JsonObject.class);
373  assertEquals(expectedJsonObject, actualJsonObject);
374  }
375 
376  @Test
377  public void createForeignTableTime() throws Exception {
378  final JsonObject expectedJsonObject = getJsonFromFile("cft_Time.json");
379  final TPlanResult result = processDdlCommand(
380  "CREATE FOREIGN TABLE test_table (test_column_1 TIME) SERVER test_server;");
381  final JsonObject actualJsonObject =
382  gson.fromJson(result.plan_result, JsonObject.class);
383  assertEquals(expectedJsonObject, actualJsonObject);
384  }
385 
386  @Test
387  public void createForeignTableTimestamp() throws Exception {
388  final JsonObject expectedJsonObject = getJsonFromFile("cft_TimeStamp.json");
389  final TPlanResult result = processDdlCommand(
390  "CREATE FOREIGN TABLE test_table (test_column_1 TIMESTAMP) SERVER test_server;");
391  final JsonObject actualJsonObject =
392  gson.fromJson(result.plan_result, JsonObject.class);
393  assertEquals(expectedJsonObject, actualJsonObject);
394  }
395 
396  @Test
397  public void createForeignTableTinyInt() throws Exception {
398  final JsonObject expectedJsonObject = getJsonFromFile("cft_TinyInt.json");
399  final TPlanResult result = processDdlCommand(
400  "CREATE FOREIGN TABLE test_table (test_column_1 TINYINT) SERVER test_server;");
401  final JsonObject actualJsonObject =
402  gson.fromJson(result.plan_result, JsonObject.class);
403  assertEquals(expectedJsonObject, actualJsonObject);
404  }
405 
406  @Test
407  public void createForeignTableArraySized() throws Exception {
408  final JsonObject expectedJsonObject = getJsonFromFile("cft_ArraySized.json");
409  final TPlanResult result = processDdlCommand(
410  "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER[5]) SERVER test_server;");
411  final JsonObject actualJsonObject =
412  gson.fromJson(result.plan_result, JsonObject.class);
413  assertEquals(expectedJsonObject, actualJsonObject);
414  }
415 
416  @Test
417  public void createForeignTableArrayUnsized() throws Exception {
418  final JsonObject expectedJsonObject = getJsonFromFile("cft_ArrayUnsized.json");
419  final TPlanResult result = processDdlCommand(
420  "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER[]) SERVER test_server;");
421  final JsonObject actualJsonObject =
422  gson.fromJson(result.plan_result, JsonObject.class);
423  assertEquals(expectedJsonObject, actualJsonObject);
424  }
425 
426  @Test
427  public void dropForeignTable() throws Exception {
428  final JsonObject expectedJsonObject = getJsonFromFile("dft.json");
429  final TPlanResult result = processDdlCommand("DROP FOREIGN TABLE test_table;");
430  final JsonObject actualJsonObject =
431  gson.fromJson(result.plan_result, JsonObject.class);
432  assertEquals(expectedJsonObject, actualJsonObject);
433  }
434 
435  @Test
436  public void dropForeignTableIfExists() throws Exception {
437  final JsonObject expectedJsonObject = getJsonFromFile("dft_ifExists.json");
438  final TPlanResult result =
439  processDdlCommand("DROP FOREIGN TABLE IF EXISTS test_table;");
440  final JsonObject actualJsonObject =
441  gson.fromJson(result.plan_result, JsonObject.class);
442  assertEquals(expectedJsonObject, actualJsonObject);
443  }
444 
445  @Test
446  public void refresh_foreign_table() throws Exception {
447  final JsonObject expectedJsonObject = getJsonFromFile("refresh_foreign_table.json");
448  final TPlanResult result = processDdlCommand("REFRESH FOREIGN TABLES test_table");
449  final JsonObject actualJsonObject =
450  gson.fromJson(result.plan_result, JsonObject.class);
451  assertEquals(expectedJsonObject, actualJsonObject);
452  }
453 
454  @Test
455  public void refresh_foreign_tables() throws Exception {
456  final JsonObject expectedJsonObject = getJsonFromFile("refresh_foreign_tables.json");
457  final TPlanResult result =
458  processDdlCommand("REFRESH FOREIGN TABLES test_table, test_table2");
459  final JsonObject actualJsonObject =
460  gson.fromJson(result.plan_result, JsonObject.class);
461  assertEquals(expectedJsonObject, actualJsonObject);
462  }
463 
464  @Test
465  public void refresh_foreign_table_with_evict() throws Exception {
466  final JsonObject expectedJsonObject =
467  getJsonFromFile("refresh_foreign_table_with_evict.json");
468  final TPlanResult result =
469  processDdlCommand("REFRESH FOREIGN TABLES test_table WITH (evict = 'true')");
470  final JsonObject actualJsonObject =
471  gson.fromJson(result.plan_result, JsonObject.class);
472  assertEquals(expectedJsonObject, actualJsonObject);
473  }
474 }
JsonObject getJsonFromFile(final String fileName)
Definition: DDLTest.java:37
TPlanResult processDdlCommand(final String ddlCommand)
Definition: DDLTest.java:32