Skip to content

Commit 801cf21

Browse files
committed
added test cases for problematic expressions
1 parent 7c1b88e commit 801cf21

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/SqlParserTest.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public Object[][] testMiscStmtDp() {
281281
{"insert into `events` (s) values ('a')", 0},
282282
{"SELECT COUNT(*) > 0 FROM system.databases WHERE name = ?", 1},
283283
{"SELECT count(*) > 0 FROM system.databases WHERE c1 = ?", 1},
284+
{"SELECT COUNT() FROM system.databases WHERE name = ?", 1},
284285
{"alter table user delete where reg_time = ?", 1},
285286
{"SELECT * FROM a,b WHERE id > ?", 1},
286287
{"DROP USER IF EXISTS default_impersonation_user", 0},
@@ -304,13 +305,90 @@ public Object[][] testMiscStmtDp() {
304305
{"GRANT ON CLUSTER '{cluster}' `metabase_test_role`, `metabase-test-role` TO `metabase_test_user`", 0},
305306
{"SELECT * FROM `test_data`.`categories` WHERE id = 1::String or id = ?", 1},
306307
{"SELECT * FROM `test_data`.`categories` WHERE id = cast(1 as String) or id = ?", 1},
308+
{"select * from test_data.categories WHERE test_data.categories.name = ? limit 4", 1},
307309
{INSERT_INLINE_DATA, 0},
308310
{"select sum(value) from `uuid_filter_db`.`uuid_filter_table` WHERE `uuid_filter_db`.`uuid_filter_table`.`uuid` IN (CAST('36f7f85c-d7f4-49e2-af05-f45d5f6636ad' AS UUID))", 0},
311+
{"SELECT DISTINCT ON (column) FROM table WHER column > ?", 1},
312+
{"SELECT * FROM test_table \nUNION\n DISTINCT SELECT * FROM test_table", 0},
313+
{"SELECT * FROM test_table1 \nUNION\n SELECT * FROM test_table2 WHERE test_table2.column1 = ?", 1},
314+
{PARAMETRIZED_VIEW, 0},
315+
{COMPLEX_CTE, 0},
316+
{"select toYear(dt) year from test WHERE val=?", 1},
317+
{"select toYear(dt) AS year from test WHERE val=?", 1},
318+
{"select toYear(dt) AS yearx from test WHERE val=?", 1},
309319
};
310320
}
311321

312322
private static final String INSERT_INLINE_DATA =
313323
"INSERT INTO `interval_15_XUTLZWBLKMNZZPRZSKRF`.`checkins` (`timestamp`, `id`) " +
314324
"VALUES ((`now64`(9) + INTERVAL -225 second), 1)";
315325

326+
private static final String PARAMETRIZED_VIEW = "CREATE VIEW default.test\n" +
327+
"AS \n" +
328+
"WITH \n" +
329+
" toDateTime({from:String}, 'Asia/Seoul') AS FROM, \n" +
330+
" date_add(FROM, INTERVAL 1 MINUTE) AS TO, \n" +
331+
" {target_id:String} AS TARGET_ID \n" +
332+
"SELECT FROM, TO, TARGET_ID";
333+
334+
private static final String COMPLEX_CTE = "WITH ? AS starting_time, ? AS ending_time, ? AS session_timeout, ? AS starting_event, ? AS ending_event, SessionData AS (\n" +
335+
" WITH\n" +
336+
" date,\n" +
337+
" arraySort(\n" +
338+
" groupArray(\n" +
339+
" (\n" +
340+
" tracking.event.time,\n" +
341+
" tracking.event.event\n" +
342+
" )\n" +
343+
" )\n" +
344+
" ) AS _sorted_events,\n" +
345+
" arrayEnumerate(_sorted_events) AS _event_serial,\n" +
346+
" arrayDifference(_sorted_events.1) AS _event_time_diff,\n" +
347+
" \n" +
348+
" arrayFilter(\n" +
349+
" (x, y, z) -> y > session_timeout OR z.2 = starting_event,\n" +
350+
" _event_serial,\n" +
351+
" _event_time_diff,\n" +
352+
" _sorted_events\n" +
353+
" ) AS _gap_index_1,\n" +
354+
"\n" +
355+
" arrayFilter(\n" +
356+
" (x, y) -> y.2 = ending_event,\n" +
357+
" _event_serial,\n" +
358+
" _sorted_events\n" +
359+
" ) AS _gap_index_2_,\n" +
360+
" arrayMap(\n" +
361+
" x -> x + 1,\n" +
362+
" _gap_index_2_\n" +
363+
" ) AS _gap_index_2,\n" +
364+
"\n" +
365+
" arrayMap(x -> if (has(_gap_index_1,x) OR has(_gap_index_2,x), 1, 0), _event_serial) AS _session_splitter,\n" +
366+
" arraySplit((x, y) -> y, _sorted_events, _session_splitter) AS _session_chain\n" +
367+
" SELECT\n" +
368+
" date,\n" +
369+
" user_id AS user_id,\n" +
370+
" arrayJoin(_session_chain) AS event_chain,\n" +
371+
" \n" +
372+
" arrayCompact(x -> x.2, event_chain) AS event_chain_dedup\n" +
373+
" FROM tracking.event\n" +
374+
" WHERE\n" +
375+
" project=? AND time>=starting_time AND time<ending_time\n" +
376+
" AND event NOT IN (?, ?, ?, ?)\n" +
377+
" GROUP BY\n" +
378+
" date,\n" +
379+
" user_id\n" +
380+
"),\n" +
381+
"SessionOverallInfo AS (\n" +
382+
" SELECT\n" +
383+
" date,\n" +
384+
" COUNT(*) AS number_of_sessions\n" +
385+
" FROM SessionData\n" +
386+
" GROUP BY date\n" +
387+
")\n" +
388+
"SELECT\n" +
389+
" SessionOverallInfo.date, SessionOverallInfo.number_of_sessions AS number_of_total_sessions\n" +
390+
"FROM\n" +
391+
" SessionOverallInfo\n" +
392+
"ORDER BY\n" +
393+
" SessionOverallInfo.date";
316394
}

0 commit comments

Comments
 (0)