1 package com.mapd.parser.extension.ddl;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
6 import com.google.gson.Gson;
7 import com.google.gson.JsonObject;
10 import org.junit.Test;
12 import ai.heavy.thrift.calciteserver.InvalidParseRequest;
13 import ai.heavy.thrift.calciteserver.TPlanResult;
17 resourceDirPath = ForeignTableTest.class.getClassLoader().getResource(
"").getPath();
23 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_OneCol.json");
25 "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER) SERVER test_server;");
26 final JsonObject actualJsonObject =
27 gson.fromJson(result.plan_result, JsonObject.class);
28 assertEquals(expectedJsonObject, actualJsonObject);
33 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Decimal.json");
35 "CREATE FOREIGN TABLE test_table (test_column_1 DECIMAL(10, 6)) SERVER test_server;");
36 final JsonObject actualJsonObject =
37 gson.fromJson(result.plan_result, JsonObject.class);
38 assertEquals(expectedJsonObject, actualJsonObject);
41 @Test(expected = InvalidParseRequest.class)
43 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Decimal.json");
45 "CREATE FOREIGN TABLE test_table (test_column_1 DECIMAL(10, 6)(11,5)) SERVER test_server;");
46 final JsonObject actualJsonObject =
47 gson.fromJson(result.plan_result, JsonObject.class);
48 assertEquals(expectedJsonObject, actualJsonObject);
53 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_IfNotExists.json");
55 "CREATE FOREIGN TABLE IF NOT EXISTS test_table (test_column_1 INTEGER) "
56 +
"SERVER test_server;");
57 final JsonObject actualJsonObject =
58 gson.fromJson(result.plan_result, JsonObject.class);
59 assertEquals(expectedJsonObject, actualJsonObject);
64 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_TwoCol.json");
66 "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER, test_column_2 TEXT) "
67 +
"SERVER test_server;");
68 final JsonObject actualJsonObject =
69 gson.fromJson(result.plan_result, JsonObject.class);
70 assertEquals(expectedJsonObject, actualJsonObject);
75 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_NotNull.json");
77 "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER NOT NULL) "
78 +
"SERVER test_server;");
79 final JsonObject actualJsonObject =
80 gson.fromJson(result.plan_result, JsonObject.class);
81 assertEquals(expectedJsonObject, actualJsonObject);
86 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_Dict8.json");
88 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DICT(8)) "
89 +
"SERVER test_server");
90 final JsonObject actualJsonObject =
91 gson.fromJson(result.plan_result, JsonObject.class);
92 assertEquals(expectedJsonObject, actualJsonObject);
97 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_Dict.json");
99 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DICT) "
100 +
"SERVER test_server");
101 final JsonObject actualJsonObject =
102 gson.fromJson(result.plan_result, JsonObject.class);
103 assertEquals(expectedJsonObject, actualJsonObject);
108 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_None.json");
110 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING NONE) "
111 +
"SERVER test_server");
112 final JsonObject actualJsonObject =
113 gson.fromJson(result.plan_result, JsonObject.class);
114 assertEquals(expectedJsonObject, actualJsonObject);
119 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_Fixed1.json");
121 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING FIXED(1)) "
122 +
"SERVER test_server");
123 final JsonObject actualJsonObject =
124 gson.fromJson(result.plan_result, JsonObject.class);
125 assertEquals(expectedJsonObject, actualJsonObject);
130 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_Days1.json");
132 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DAYS(1)) "
133 +
"SERVER test_server");
134 final JsonObject actualJsonObject =
135 gson.fromJson(result.plan_result, JsonObject.class);
136 assertEquals(expectedJsonObject, actualJsonObject);
141 final JsonObject expectedJsonObject =
144 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING COMPRESSED(32)) "
145 +
"SERVER test_server");
146 final JsonObject actualJsonObject =
147 gson.fromJson(result.plan_result, JsonObject.class);
148 assertEquals(expectedJsonObject, actualJsonObject);
153 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Encoding_Compressed.json");
155 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING COMPRESSED) "
156 +
"SERVER test_server");
157 final JsonObject actualJsonObject =
158 gson.fromJson(result.plan_result, JsonObject.class);
159 assertEquals(expectedJsonObject, actualJsonObject);
162 @Test(expected = InvalidParseRequest.class)
165 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING NONE(1)) "
166 +
"SERVER test_server");
169 @Test(expected = InvalidParseRequest.class)
172 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING FIXED) "
173 +
"SERVER test_server");
176 @Test(expected = InvalidParseRequest.class)
179 "CREATE FOREIGN TABLE test_table (test_column_1 TEXT ENCODING DAYS) "
180 +
"SERVER test_server");
185 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_ColOptions.json");
186 final TPlanResult
result =
188 +
"WITH ( option_1 = 'value_1', option_2 = 2)) SERVER test_server;");
189 final JsonObject actualJsonObject =
190 gson.fromJson(result.plan_result, JsonObject.class);
191 assertEquals(expectedJsonObject, actualJsonObject);
196 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Options.json");
197 final TPlanResult
result =
199 +
"SERVER test_server WITH ( option_1 = 'value_1', option_2 = 2);");
200 final JsonObject actualJsonObject =
201 gson.fromJson(result.plan_result, JsonObject.class);
202 assertEquals(expectedJsonObject, actualJsonObject);
207 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_EscapeOption.json");
208 final TPlanResult
result =
210 +
"SERVER test_server WITH ( escape = '\\');");
211 final JsonObject actualJsonObject =
212 gson.fromJson(result.plan_result, JsonObject.class);
213 assertEquals(expectedJsonObject, actualJsonObject);
218 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Schema.json");
219 final TPlanResult
result =
221 +
"SERVER test_server;");
222 final JsonObject actualJsonObject =
223 gson.fromJson(result.plan_result, JsonObject.class);
224 assertEquals(expectedJsonObject, actualJsonObject);
229 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Point.json");
231 "CREATE FOREIGN TABLE test_table (test_column_1 POINT) SERVER test_server;");
232 final JsonObject actualJsonObject =
233 gson.fromJson(result.plan_result, JsonObject.class);
234 assertEquals(expectedJsonObject, actualJsonObject);
239 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Point.json");
241 "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT)) SERVER test_server;");
242 final JsonObject actualJsonObject =
243 gson.fromJson(result.plan_result, JsonObject.class);
244 assertEquals(expectedJsonObject, actualJsonObject);
249 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_MultiPoint.json");
251 "CREATE FOREIGN TABLE test_table (test_column_1 MULTIPOINT) SERVER test_server;");
252 final JsonObject actualJsonObject =
253 gson.fromJson(result.plan_result, JsonObject.class);
254 assertEquals(expectedJsonObject, actualJsonObject);
259 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Linestring.json");
261 "CREATE FOREIGN TABLE test_table (test_column_1 LINESTRING) SERVER test_server;");
262 final JsonObject actualJsonObject =
263 gson.fromJson(result.plan_result, JsonObject.class);
264 assertEquals(expectedJsonObject, actualJsonObject);
269 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_MultiLinestring.json");
271 "CREATE FOREIGN TABLE test_table (test_column_1 MULTILINESTRING) SERVER test_server;");
272 final JsonObject actualJsonObject =
273 gson.fromJson(result.plan_result, JsonObject.class);
274 assertEquals(expectedJsonObject, actualJsonObject);
279 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Polygon.json");
281 "CREATE FOREIGN TABLE test_table (test_column_1 POLYGON) SERVER test_server;");
282 final JsonObject actualJsonObject =
283 gson.fromJson(result.plan_result, JsonObject.class);
284 assertEquals(expectedJsonObject, actualJsonObject);
289 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_MultiPolygon.json");
291 "CREATE FOREIGN TABLE test_table (test_column_1 MULTIPOLYGON) SERVER test_server;");
292 final JsonObject actualJsonObject =
293 gson.fromJson(result.plan_result, JsonObject.class);
294 assertEquals(expectedJsonObject, actualJsonObject);
299 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_GeoPointMerc.json");
301 "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT, 900913)) SERVER test_server;");
302 final JsonObject actualJsonObject =
303 gson.fromJson(result.plan_result, JsonObject.class);
304 assertEquals(expectedJsonObject, actualJsonObject);
309 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_GeoPointWG.json");
311 "CREATE FOREIGN TABLE test_table (test_column_1 GEOMETRY(POINT, 4326)) SERVER test_server;");
312 final JsonObject actualJsonObject =
313 gson.fromJson(result.plan_result, JsonObject.class);
314 assertEquals(expectedJsonObject, actualJsonObject);
319 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_PointCompressed.json");
321 "CREATE FOREIGN TABLE test_table (test_column_1 POINT ENCODING COMPRESSED(32)) SERVER test_server;");
322 final JsonObject actualJsonObject =
323 gson.fromJson(result.plan_result, JsonObject.class);
324 assertEquals(expectedJsonObject, actualJsonObject);
329 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_BigInt.json");
331 "CREATE FOREIGN TABLE test_table (test_column_1 BIGINT) SERVER test_server;");
332 final JsonObject actualJsonObject =
333 gson.fromJson(result.plan_result, JsonObject.class);
334 assertEquals(expectedJsonObject, actualJsonObject);
339 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Boolean.json");
341 "CREATE FOREIGN TABLE test_table (test_column_1 BOOLEAN) SERVER test_server;");
342 final JsonObject actualJsonObject =
343 gson.fromJson(result.plan_result, JsonObject.class);
344 assertEquals(expectedJsonObject, actualJsonObject);
349 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Date.json");
351 "CREATE FOREIGN TABLE test_table (test_column_1 DATE) SERVER test_server;");
352 final JsonObject actualJsonObject =
353 gson.fromJson(result.plan_result, JsonObject.class);
354 assertEquals(expectedJsonObject, actualJsonObject);
359 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Double.json");
361 "CREATE FOREIGN TABLE test_table (test_column_1 DOUBLE) SERVER test_server;");
362 final JsonObject actualJsonObject =
363 gson.fromJson(result.plan_result, JsonObject.class);
364 assertEquals(expectedJsonObject, actualJsonObject);
369 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Epoch.json");
371 "CREATE FOREIGN TABLE test_table (test_column_1 EPOCH) SERVER test_server;");
372 final JsonObject actualJsonObject =
373 gson.fromJson(result.plan_result, JsonObject.class);
374 assertEquals(expectedJsonObject, actualJsonObject);
379 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Float.json");
381 "CREATE FOREIGN TABLE test_table (test_column_1 FLOAT) SERVER test_server;");
382 final JsonObject actualJsonObject =
383 gson.fromJson(result.plan_result, JsonObject.class);
384 assertEquals(expectedJsonObject, actualJsonObject);
389 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_SmallInt.json");
391 "CREATE FOREIGN TABLE test_table (test_column_1 SMALLINT) SERVER test_server;");
392 final JsonObject actualJsonObject =
393 gson.fromJson(result.plan_result, JsonObject.class);
394 assertEquals(expectedJsonObject, actualJsonObject);
399 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_Time.json");
401 "CREATE FOREIGN TABLE test_table (test_column_1 TIME) SERVER test_server;");
402 final JsonObject actualJsonObject =
403 gson.fromJson(result.plan_result, JsonObject.class);
404 assertEquals(expectedJsonObject, actualJsonObject);
409 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_TimeStamp.json");
411 "CREATE FOREIGN TABLE test_table (test_column_1 TIMESTAMP) SERVER test_server;");
412 final JsonObject actualJsonObject =
413 gson.fromJson(result.plan_result, JsonObject.class);
414 assertEquals(expectedJsonObject, actualJsonObject);
419 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_TinyInt.json");
421 "CREATE FOREIGN TABLE test_table (test_column_1 TINYINT) SERVER test_server;");
422 final JsonObject actualJsonObject =
423 gson.fromJson(result.plan_result, JsonObject.class);
424 assertEquals(expectedJsonObject, actualJsonObject);
429 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_ArraySized.json");
431 "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER[5]) SERVER test_server;");
432 final JsonObject actualJsonObject =
433 gson.fromJson(result.plan_result, JsonObject.class);
434 assertEquals(expectedJsonObject, actualJsonObject);
439 final JsonObject expectedJsonObject =
getJsonFromFile(
"cft_ArrayUnsized.json");
441 "CREATE FOREIGN TABLE test_table (test_column_1 INTEGER[]) SERVER test_server;");
442 final JsonObject actualJsonObject =
443 gson.fromJson(result.plan_result, JsonObject.class);
444 assertEquals(expectedJsonObject, actualJsonObject);
451 final JsonObject actualJsonObject =
452 gson.fromJson(result.plan_result, JsonObject.class);
453 assertEquals(expectedJsonObject, actualJsonObject);
458 final JsonObject expectedJsonObject =
getJsonFromFile(
"dft_ifExists.json");
459 final TPlanResult
result =
461 final JsonObject actualJsonObject =
462 gson.fromJson(result.plan_result, JsonObject.class);
463 assertEquals(expectedJsonObject, actualJsonObject);
468 final JsonObject expectedJsonObject =
getJsonFromFile(
"refresh_foreign_table.json");
470 final JsonObject actualJsonObject =
471 gson.fromJson(result.plan_result, JsonObject.class);
472 assertEquals(expectedJsonObject, actualJsonObject);
477 final JsonObject expectedJsonObject =
getJsonFromFile(
"refresh_foreign_tables.json");
478 final TPlanResult
result =
480 final JsonObject actualJsonObject =
481 gson.fromJson(result.plan_result, JsonObject.class);
482 assertEquals(expectedJsonObject, actualJsonObject);
487 final JsonObject expectedJsonObject =
489 final TPlanResult
result =
491 final JsonObject actualJsonObject =
492 gson.fromJson(result.plan_result, JsonObject.class);
493 assertEquals(expectedJsonObject, actualJsonObject);
498 final JsonObject expectedJsonObject =
501 "ALTER FOREIGN TABLE test_table SET (base_path = '/home/my_user/data/new-csv/');");
502 final JsonObject actualJsonObject =
503 gson.fromJson(result.plan_result, JsonObject.class);
504 assertEquals(expectedJsonObject, actualJsonObject);
509 final JsonObject expectedJsonObject =
511 final TPlanResult
result =
513 final JsonObject actualJsonObject =
514 gson.fromJson(result.plan_result, JsonObject.class);
515 assertEquals(expectedJsonObject, actualJsonObject);
520 final JsonObject expectedJsonObject =
523 "ALTER FOREIGN TABLE test_table RENAME COLUMN old_column TO new_column;");
524 final JsonObject actualJsonObject =
525 gson.fromJson(result.plan_result, JsonObject.class);
526 assertEquals(expectedJsonObject, actualJsonObject);
JsonObject getJsonFromFile(final String fileName)
void createForeignTableEncodingFixed1()
void createForeignTableMultiLinestring()
void createForeignTableMultiPoint()
void createForeignTableBoolean()
void createForeignTableColOptions()
void createForeignTableGeoPoint()
void createForeignTableDecimal()
void createForeignTableEncodingDict8()
void createForeignTableBigInt()
void createForeignTableEncodingFixedWithoutSize()
void createForeignTableEpoch()
void createForeignTableEncodingDaysWithoutSize()
void createForeignTableEncodingDays1()
void createForeignTablePoint()
void refresh_foreign_tables()
void alterForeignTableSetOptions()
void createForeignTableGeoPointWG()
void createForeignTableLinestring()
void alterForeignTableRenameTable()
void createForeignTableEncodingNone()
void createForeignTableTinyInt()
void createForeignTableEncodingCompressed32()
void dropForeignTableIfExists()
void createForeignTableDate()
void alterForeignTableRenameColumn()
void createForeignTableEncodingNone1()
void createForeignTableTimestamp()
void createForeignTableDouble()
void createForeignTableEncodingDict()
void createForeignTableGeoPointMerc()
TPlanResult processDdlCommand(final String ddlCommand)
void createForeignTableTime()
void createForeignTableFloat()
void createForeignTableEncodingCompressed()
void createForeignTableSmallInt()
void createForeignTableMultiPolygon()
void createForeignTableArrayUnsized()
void createForeignTableDoubleDecimal()
void createForeignTableIfNotExists()
void refresh_foreign_table()
void refresh_foreign_table_with_evict()
void createForeignTableSchema()
void createForeignTablePointCompressed()
void createForeignTableOptions()
void createForeignTablePolygon()
void createForeignTableTwoCol()
void createForeignTableArraySized()
void createForeignTableNotNull()
void createForeignTableEscapeOption()
void createForeignTableOneCol()