OmniSciDB  04ee39c94c
com.mapd.parser.server.test.SqlIdentifierCapturerTest Class Reference

Classes

class  MockSchema
 

Public Member Functions

void testSelect (String sql, String[] expectedSelects) throws Exception
 
void testUpdate (String sql, String[] expectedUpdates, String[] expectedSelects) throws Exception
 
void testInsert (String sql, String[] expectedInserts, String[] expectedSelects) throws Exception
 
void testDelete (String sql, String[] expectedDeletes, String[] expectedSelects) throws Exception
 
void testSelects () throws Exception
 
void testSelectsWithSchema () throws Exception
 
void testInserts () throws Exception
 
void testInsertsWithSchema () throws Exception
 
void testUpdates () throws Exception
 
void testUpdatesWithSchema () throws Exception
 
void testDeletes () throws Exception
 
void testDeletesWithSchema () throws Exception
 

Static Public Member Functions

static String [] asArray (String... vals)
 
static Set< String > asSet (String... vals)
 

Private Member Functions

Planner getPlanner ()
 

Detailed Description

Definition at line 31 of file SqlIdentifierCapturerTest.java.

Member Function Documentation

◆ asArray()

◆ asSet()

static Set<String> com.mapd.parser.server.test.SqlIdentifierCapturerTest.asSet ( String...  vals)
inlinestatic

Definition at line 111 of file SqlIdentifierCapturerTest.java.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDelete(), com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsert(), com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelect(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdate().

111  {
112  return new HashSet<String>(asList(vals));
113  }
+ Here is the caller graph for this function:

◆ getPlanner()

Planner com.mapd.parser.server.test.SqlIdentifierCapturerTest.getPlanner ( )
inlineprivate

Definition at line 89 of file SqlIdentifierCapturerTest.java.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDelete(), com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsert(), com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelect(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdate().

89  {
90  Schema mapd = new MockSchema() {
91 
92  };
93  final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
94  final FrameworkConfig config =
95  Frameworks.newConfigBuilder()
96  .defaultSchema(rootSchema.add("omnisci", mapd))
97  .operatorTable(
98  new MapDSqlOperatorTable(SqlStdOperatorTable.instance()))
99  .parserConfig(SqlParser.configBuilder()
100  .setUnquotedCasing(Casing.UNCHANGED)
101  .setCaseSensitive(false)
102  .build())
103  .build();
104  return new MapDPlanner(config);
105  }
Definition: DataGen.cpp:60
+ Here is the caller graph for this function:

◆ testDelete()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDelete ( String  sql,
String []  expectedDeletes,
String []  expectedSelects 
) throws Exception
inline

Definition at line 147 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asSet(), org.apache.calcite.prepare.SqlIdentifierCapturer.deletes, com.mapd.parser.server.test.SqlIdentifierCapturerTest.getPlanner(), org.apache.calcite.prepare.SqlIdentifierCapturer.inserts, org.apache.calcite.prepare.SqlIdentifierCapturer.scan(), org.apache.calcite.prepare.SqlIdentifierCapturer.selects, sql(), and org.apache.calcite.prepare.SqlIdentifierCapturer.updates.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDeletes(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDeletesWithSchema().

148  {
149  SqlIdentifierCapturer capturer = new SqlIdentifierCapturer();
150  capturer.scan(getPlanner().parse(sql));
151 
152  assertEquals("selects", asSet(expectedSelects), capturer.selects);
153  assertEquals("inserts", asSet(), capturer.inserts);
154  assertEquals("updates", asSet(), capturer.updates);
155  assertEquals("deletes", asSet(expectedDeletes), capturer.deletes);
156  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDeletes()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDeletes ( ) throws Exception
inline

Definition at line 297 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDelete().

297  {
298  String sql = "DELETE FROM sales";
299  testDelete(sql, asArray("sales"), asArray());
300 
301  sql = "DELETE FROM sales WHERE id=1";
302  testDelete(sql, asArray("sales"), asArray());
303 
304  sql = "DELETE FROM sales WHERE id=(SELECT max(r.val) FROM reports AS r)";
305  testDelete(sql, asArray("sales"), asArray("reports"));
306 
307  sql = "DELETE FROM sales WHERE id=(SELECT max(r.val) FROM reports AS r) AND id=(SELECT max(m.val) FROM marketing AS m)";
308  testDelete(sql, asArray("sales"), asArray("reports", "marketing"));
309  }
void testDelete(String sql, String[] expectedDeletes, String[] expectedSelects)
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:

◆ testDeletesWithSchema()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDeletesWithSchema ( ) throws Exception
inline

Definition at line 312 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testDelete().

312  {
313  String sql = "DELETE FROM mapd.sales";
314  testDelete(sql, asArray("sales"), asArray());
315 
316  sql = "DELETE FROM mapd.sales WHERE id=1";
317  testDelete(sql, asArray("sales"), asArray());
318 
319  sql = "DELETE FROM mapd.sales WHERE id=(SELECT max(r.val) FROM mapd.reports AS r)";
320  testDelete(sql, asArray("sales"), asArray("reports"));
321 
322  sql = "DELETE FROM mapd.sales WHERE id=(SELECT max(r.val) FROM mapd.reports AS r) AND id=(SELECT max(m.val) FROM mapd.marketing AS m)";
323  testDelete(sql, asArray("sales"), asArray("reports", "marketing"));
324  }
void testDelete(String sql, String[] expectedDeletes, String[] expectedSelects)
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:

◆ testInsert()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsert ( String  sql,
String []  expectedInserts,
String []  expectedSelects 
) throws Exception
inline

Definition at line 136 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asSet(), org.apache.calcite.prepare.SqlIdentifierCapturer.deletes, com.mapd.parser.server.test.SqlIdentifierCapturerTest.getPlanner(), org.apache.calcite.prepare.SqlIdentifierCapturer.inserts, org.apache.calcite.prepare.SqlIdentifierCapturer.scan(), org.apache.calcite.prepare.SqlIdentifierCapturer.selects, sql(), and org.apache.calcite.prepare.SqlIdentifierCapturer.updates.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInserts(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsertsWithSchema().

137  {
138  SqlIdentifierCapturer capturer = new SqlIdentifierCapturer();
139  capturer.scan(getPlanner().parse(sql));
140 
141  assertEquals("selects", asSet(expectedSelects), capturer.selects);
142  assertEquals("inserts", asSet(expectedInserts), capturer.inserts);
143  assertEquals("updates", asSet(), capturer.updates);
144  assertEquals("deletes", asSet(), capturer.deletes);
145  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testInserts()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInserts ( ) throws Exception
inline

Definition at line 231 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsert().

231  {
232  String sql = "INSERT INTO sales VALUES(10)";
233  testInsert(sql, asArray("sales"), asArray());
234 
235  sql = "INSERT INTO sales(id, target) VALUES(10, 21321)";
236  testInsert(sql, asArray("sales"), asArray());
237 
238  sql = "INSERT INTO sales(id, target) VALUES(10, (SELECT max(r.val) FROM reports AS r))";
239  testInsert(sql, asArray("sales"), asArray("reports"));
240 
241  sql = "INSERT INTO sales(id, target) VALUES((SELECT m.id FROM marketing m), (SELECT max(r.val) FROM reports AS r))";
242  testInsert(sql, asArray("sales"), asArray("reports", "marketing"));
243  }
auto sql(const std::string &sql_stmts)
void testInsert(String sql, String[] expectedInserts, String[] expectedSelects)
+ Here is the call graph for this function:

◆ testInsertsWithSchema()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsertsWithSchema ( ) throws Exception
inline

Definition at line 246 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testInsert().

246  {
247  String sql = "INSERT INTO mapd.sales VALUES(10)";
248  testInsert(sql, asArray("sales"), asArray());
249 
250  sql = "INSERT INTO mapd.sales(id, target) VALUES(10, 21321)";
251  testInsert(sql, asArray("sales"), asArray());
252 
253  sql = "INSERT INTO mapd.sales(id, target) VALUES(10, (SELECT max(r.val) FROM mapd.reports AS r))";
254  testInsert(sql, asArray("sales"), asArray("reports"));
255 
256  sql = "INSERT INTO mapd.sales(id, target) VALUES((SELECT m.id FROM mapd.marketing m), (SELECT max(r.val) FROM mapd.reports AS r))";
257  testInsert(sql, asArray("sales"), asArray("reports", "marketing"));
258  }
auto sql(const std::string &sql_stmts)
void testInsert(String sql, String[] expectedInserts, String[] expectedSelects)
+ Here is the call graph for this function:

◆ testSelect()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelect ( String  sql,
String []  expectedSelects 
) throws Exception
inline

Definition at line 115 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asSet(), org.apache.calcite.prepare.SqlIdentifierCapturer.deletes, com.mapd.parser.server.test.SqlIdentifierCapturerTest.getPlanner(), org.apache.calcite.prepare.SqlIdentifierCapturer.inserts, org.apache.calcite.prepare.SqlIdentifierCapturer.scan(), org.apache.calcite.prepare.SqlIdentifierCapturer.selects, sql(), and org.apache.calcite.prepare.SqlIdentifierCapturer.updates.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelects(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelectsWithSchema().

115  {
116  SqlIdentifierCapturer capturer = new SqlIdentifierCapturer();
117  capturer.scan(getPlanner().parse(sql));
118 
119  assertEquals("selects", asSet(expectedSelects), capturer.selects);
120  assertEquals("inserts", asSet(), capturer.inserts);
121  assertEquals("updates", asSet(), capturer.updates);
122  assertEquals("deletes", asSet(), capturer.deletes);
123  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testSelects()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelects ( ) throws Exception
inline

Definition at line 159 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelect().

159  {
160  String sql = "SELECT * FROM sales";
161  testSelect(sql, asArray("sales"));
162 
163  sql = "SELECT * FROM sales AS s";
164  testSelect(sql, asArray("sales"));
165 
166  sql = "SELECT * FROM sales AS s, reports AS r WHERE s.id = r.id";
167  testSelect(sql, asArray("sales", "reports"));
168 
169  sql = "SELECT * FROM sales AS s left outer join reports AS r on s.id = r.id";
170  testSelect(sql, asArray("sales", "reports"));
171 
172  sql = "SELECT *, (SELECT sum(val) FROM marketing m WHERE m.id=a.id) FROM sales AS s left outer join reports AS r on s.id = r.id";
173  testSelect(sql, asArray("sales", "reports", "marketing"));
174 
175  sql = "SELECT * FROM sales UNION SELECT * FROM reports UNION SELECT * FROM marketing";
176  testSelect(sql, asArray("sales", "reports", "marketing"));
177 
178  sql = "SELECT COUNT(*) AS n, str FROM query_rewrite_test WHERE str IN ('str2', 'str99') GROUP BY str HAVING n > 0 ORDER BY n DESC";
179  testSelect(sql, asArray("query_rewrite_test"));
180 
181  sql = "SELECT str, SUM(y) as total_y FROM test GROUP BY str ORDER BY total_y DESC, str LIMIT 1";
182  testSelect(sql, asArray("test"));
183 
184  sql = "SELECT str FROM (SELECT str, SUM(y) as total_y FROM test GROUP BY str ORDER BY total_y DESC, str LIMIT 1)";
185  testSelect(sql, asArray("test"));
186 
187  sql = "SELECT deptno, dname FROM (SELECT * from dept) AS view_name LIMIT 10";
188  testSelect(sql, asArray("dept"));
189 
190  sql = "WITH d1 AS (SELECT deptno, dname FROM dept LIMIT 10) SELECT ename, dname FROM emp, d1 WHERE emp.deptno = d1.deptno ORDER BY ename ASC LIMIT 10";
191  testSelect(sql, asArray("emp", "dept"));
192  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:

◆ testSelectsWithSchema()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelectsWithSchema ( ) throws Exception
inline

Definition at line 195 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testSelect().

195  {
196  String sql = "SELECT * FROM mapd.sales";
197  testSelect(sql, asArray("sales"));
198 
199  sql = "SELECT * FROM mapd.sales AS s";
200  testSelect(sql, asArray("sales"));
201 
202  sql = "SELECT * FROM mapd.sales AS s, mapd.reports AS r WHERE s.id = r.id";
203  testSelect(sql, asArray("sales", "reports"));
204 
205  sql = "SELECT * FROM mapd.sales AS s left outer join mapd.reports AS r on s.id = r.id";
206  testSelect(sql, asArray("sales", "reports"));
207 
208  sql = "SELECT *, (SELECT sum(val) FROM mapd.marketing m WHERE m.id=a.id) FROM mapd.sales AS s left outer join mapd.reports AS r on s.id = r.id";
209  testSelect(sql, asArray("sales", "reports", "marketing"));
210 
211  sql = "SELECT * FROM mapd.sales UNION SELECT * FROM mapd.reports UNION SELECT * FROM mapd.marketing";
212  testSelect(sql, asArray("sales", "reports", "marketing"));
213 
214  sql = "SELECT COUNT(*) AS n, str FROM mapd.query_rewrite_test WHERE str IN ('str2', 'str99') GROUP BY str HAVING n > 0 ORDER BY n DESC";
215  testSelect(sql, asArray("query_rewrite_test"));
216 
217  sql = "SELECT str, SUM(y) as total_y FROM mapd.test GROUP BY str ORDER BY total_y DESC, str LIMIT 1";
218  testSelect(sql, asArray("test"));
219 
220  sql = "SELECT str FROM (SELECT str, SUM(y) as total_y FROM mapd.test GROUP BY str ORDER BY total_y DESC, str LIMIT 1)";
221  testSelect(sql, asArray("test"));
222 
223  sql = "SELECT deptno, dname FROM (SELECT * from mapd.dept) AS view_name LIMIT 10";
224  testSelect(sql, asArray("dept"));
225 
226  sql = "WITH d1 AS (SELECT deptno, dname FROM mapd.dept LIMIT 10) SELECT ename, dname FROM mapd.emp, d1 WHERE emp.deptno = d1.deptno ORDER BY ename ASC LIMIT 10";
227  testSelect(sql, asArray("emp", "dept"));
228  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:

◆ testUpdate()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdate ( String  sql,
String []  expectedUpdates,
String []  expectedSelects 
) throws Exception
inline

Definition at line 125 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asSet(), org.apache.calcite.prepare.SqlIdentifierCapturer.deletes, com.mapd.parser.server.test.SqlIdentifierCapturerTest.getPlanner(), org.apache.calcite.prepare.SqlIdentifierCapturer.inserts, org.apache.calcite.prepare.SqlIdentifierCapturer.scan(), org.apache.calcite.prepare.SqlIdentifierCapturer.selects, sql(), and org.apache.calcite.prepare.SqlIdentifierCapturer.updates.

Referenced by com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdates(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdatesWithSchema().

126  {
127  SqlIdentifierCapturer capturer = new SqlIdentifierCapturer();
128  capturer.scan(getPlanner().parse(sql));
129 
130  assertEquals("selects", asSet(expectedSelects), capturer.selects);
131  assertEquals("inserts", asSet(), capturer.inserts);
132  assertEquals("updates", asSet(expectedUpdates), capturer.updates);
133  assertEquals("deletes", asSet(), capturer.deletes);
134  }
auto sql(const std::string &sql_stmts)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testUpdates()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdates ( ) throws Exception
inline

Definition at line 261 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdate().

261  {
262  String sql = "UPDATE sales SET id=10";
263  testUpdate(sql, asArray("sales"), asArray());
264 
265  sql = "UPDATE sales SET id=10 WHERE id=1";
266  testUpdate(sql, asArray("sales"), asArray());
267 
268  sql = "UPDATE sales SET id=(SELECT max(r.val) FROM reports AS r)";
269  testUpdate(sql, asArray("sales"), asArray("reports"));
270 
271  sql = "UPDATE sales SET id=(SELECT max(r.val) FROM reports AS r) WHERE id=(SELECT max(m.val) FROM marketing AS m)";
272  testUpdate(sql, asArray("sales"), asArray("reports", "marketing"));
273 
274  sql = "UPDATE shardkey SET y=99 WHERE x=(SELECT max(id) from v2 LIMIT 1)";
275  testUpdate(sql, asArray("shardkey"), asArray("v2"));
276  }
auto sql(const std::string &sql_stmts)
void testUpdate(String sql, String[] expectedUpdates, String[] expectedSelects)
+ Here is the call graph for this function:

◆ testUpdatesWithSchema()

void com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdatesWithSchema ( ) throws Exception
inline

Definition at line 279 of file SqlIdentifierCapturerTest.java.

References com.mapd.parser.server.test.SqlIdentifierCapturerTest.asArray(), sql(), Experimental.String, and com.mapd.parser.server.test.SqlIdentifierCapturerTest.testUpdate().

279  {
280  String sql = "UPDATE mapd.sales SET id=10";
281  testUpdate(sql, asArray("sales"), asArray());
282 
283  sql = "UPDATE mapd.sales SET id=10 WHERE id=1";
284  testUpdate(sql, asArray("sales"), asArray());
285 
286  sql = "UPDATE mapd.sales SET id=(SELECT max(r.val) FROM mapd.reports AS r)";
287  testUpdate(sql, asArray("sales"), asArray("reports"));
288 
289  sql = "UPDATE mapd.sales SET id=(SELECT max(r.val) FROM mapd.reports AS r) WHERE id=(SELECT max(m.val) FROM mapd.marketing AS m)";
290  testUpdate(sql, asArray("sales"), asArray("reports", "marketing"));
291 
292  sql = "UPDATE mapd.shardkey SET y=99 WHERE x=(SELECT max(id) from mapd.v2 LIMIT 1)";
293  testUpdate(sql, asArray("shardkey"), asArray("v2"));
294  }
auto sql(const std::string &sql_stmts)
void testUpdate(String sql, String[] expectedUpdates, String[] expectedSelects)
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: