|
1 |
| -import { |
2 |
| - getLimitedQuery, |
3 |
| - getSelectStatementLimit, |
4 |
| -} from 'lib/sql-helper/sql-limiter'; |
| 1 | +import { getSelectStatementLimit } from 'lib/sql-helper/sql-limiter'; |
5 | 2 |
|
6 | 3 | describe('getSelectStatementLimit', () => {
|
7 | 4 | describe('when it is not a SELECT statement', () => {
|
@@ -76,126 +73,3 @@ describe('getSelectStatementLimit', () => {
|
76 | 73 | });
|
77 | 74 | });
|
78 | 75 | });
|
79 |
| - |
80 |
| -describe('getLimitedQuery', () => { |
81 |
| - describe('not limited', () => { |
82 |
| - test('when rowLimit is not specified', () => { |
83 |
| - const query = 'SELECT * FROM table_1 WHERE field = 1;'; |
84 |
| - expect(getLimitedQuery(query)).toBe(query); |
85 |
| - }); |
86 |
| - test('when rowLimit is not specified for multiple queries', () => { |
87 |
| - const query = ` |
88 |
| - SELECT * FROM table_1 WHERE field = 1; |
89 |
| - SELECT * FROM table_1 WHERE field = 1; |
90 |
| - `; |
91 |
| - expect(getLimitedQuery(query)).toBe(query); |
92 |
| - }); |
93 |
| - test('when running a select query with fetch', () => { |
94 |
| - const query = |
95 |
| - 'SELECT * FROM table_1 ORDER BY id FETCH FIRST 10 ROWS ONLY;'; |
96 |
| - expect(getLimitedQuery(query, 100, 'trino')).toBe(query); |
97 |
| - }); |
98 |
| - test('when running a select query with offset and fetch', () => { |
99 |
| - const query = |
100 |
| - 'SELECT * FROM table_1 ORDER BY id OFFSET 10 FETCH NEXT 10 ROWS ONLY;'; |
101 |
| - expect(getLimitedQuery(query, 100, 'trino')).toBe(query); |
102 |
| - }); |
103 |
| - test('when running a select query with nested query', () => { |
104 |
| - const query = `select * from (select * from table limit 5) as x limit 10`; |
105 |
| - expect(getLimitedQuery(query, 100, 'trino')).toBe(query); |
106 |
| - }); |
107 |
| - test('when running a select query with a where clause and a limit', () => { |
108 |
| - const query = 'SELECT * FROM table_1 WHERE field = 1 LIMIT 1000;'; |
109 |
| - expect(getLimitedQuery(query, 100, 'trino')).toBe(query); |
110 |
| - }); |
111 |
| - }); |
112 |
| - describe('limited', () => { |
113 |
| - test('when running a select query', () => { |
114 |
| - const query = 'SELECT * FROM table_1'; |
115 |
| - expect(getLimitedQuery(query, 10)).toBe(`${query} limit 10;`); |
116 |
| - }); |
117 |
| - test('when running a select query with a where clause and a group by and an order by', () => { |
118 |
| - const query = |
119 |
| - 'SELECT field, count(*) FROM table_1 WHERE deleted = false GROUP BY field ORDER BY field'; |
120 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
121 |
| - }); |
122 |
| - test('when running a select query with trailing semicolon', () => { |
123 |
| - const query = 'SELECT * FROM table_1;'; |
124 |
| - expect(getLimitedQuery(query, 10)).toBe( |
125 |
| - 'SELECT * FROM table_1 limit 10;' |
126 |
| - ); |
127 |
| - }); |
128 |
| - test('when running a select query with comments', () => { |
129 |
| - const query = 'SELECT * FROM table_1 -- limit here'; |
130 |
| - expect(getLimitedQuery(query, 10)).toBe( |
131 |
| - 'SELECT * FROM table_1 limit 10;' |
132 |
| - ); |
133 |
| - }); |
134 |
| - test('when running a select query with non-keyword limits', () => { |
135 |
| - const query = `SELECT id, account, 'limit' FROM querybook2.limit ORDER by 'limit' ASC`; |
136 |
| - expect(getLimitedQuery(query, 10)).toBe(`${query} limit 10;`); |
137 |
| - }); |
138 |
| - test('when running a multiple select queries', () => { |
139 |
| - const query = `SELECT * FROM table_1; |
140 |
| -SELECT col1, col2, FROM table2;`; |
141 |
| - expect(getLimitedQuery(query, 10)).toBe( |
142 |
| - `SELECT * FROM table_1 limit 10; |
143 |
| -SELECT col1, col2, FROM table2 limit 10;` |
144 |
| - ); |
145 |
| - }); |
146 |
| - test('when running a select query with a where clause', () => { |
147 |
| - const query = 'SELECT * FROM table_1 WHERE field = 1'; |
148 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
149 |
| - }); |
150 |
| - test('when running a select query with a where clause and an order by', () => { |
151 |
| - const query = |
152 |
| - 'SELECT * FROM table_1 WHERE field = 1 ORDER BY field'; |
153 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
154 |
| - }); |
155 |
| - test('when running a select query with a where clause and a group by and an order by', () => { |
156 |
| - const query = |
157 |
| - 'SELECT field, count(*) FROM table_1 WHERE deleted = false GROUP BY field ORDER BY field'; |
158 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
159 |
| - }); |
160 |
| - test('when running two select queries with mixed limits', () => { |
161 |
| - const query = `SELECT * FROM table_1; |
162 |
| -SELECT col1, col2, FROM table2 LIMIT 300;`; |
163 |
| - expect(getLimitedQuery(query, 10)) |
164 |
| - .toBe(`SELECT * FROM table_1 limit 10; |
165 |
| -SELECT col1, col2, FROM table2 LIMIT 300;`); |
166 |
| - }); |
167 |
| - test('when running multiple select queries with mixed limits', () => { |
168 |
| - const query = `SELECT * FROM table_1; |
169 |
| -SELECT col1, col2, FROM table2 LIMIT 300; |
170 |
| -SELECT field, count(1) FROM table3 GROUP BY field`; |
171 |
| - expect(getLimitedQuery(query, 10)) |
172 |
| - .toBe(`SELECT * FROM table_1 limit 10; |
173 |
| -SELECT col1, col2, FROM table2 LIMIT 300; |
174 |
| -SELECT field, count(1) FROM table3 GROUP BY field limit 10;`); |
175 |
| - }); |
176 |
| - test('when running a select query with nested query', () => { |
177 |
| - const query = `select * from (select * from table limit 5) as x`; |
178 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
179 |
| - }); |
180 |
| - test('when running a select query with wrapped where', () => { |
181 |
| - const query = `select * from table where (field = 1 and field2 = 2)`; |
182 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
183 |
| - }); |
184 |
| - test('when running a select query with two nested queries', () => { |
185 |
| - const query = `select * from (select * from table limit 5) as x outer join (select * from table2 limit 5) as y on x.id = y.id`; |
186 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
187 |
| - }); |
188 |
| - test('when running a select query with two nested queries', () => { |
189 |
| - const query = `select * from (select * from table limit 5) as x outer join (select * from table2 limit 5) as y on x.id = y.id`; |
190 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
191 |
| - }); |
192 |
| - test('when running a select query with two union queries', () => { |
193 |
| - const query = `select id, name from table_a union all select id, name from table_b where (deleted = false and active = true)`; |
194 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
195 |
| - }); |
196 |
| - test('when running a select query with two nested union queries', () => { |
197 |
| - const query = `(select id, name from table_a limit 10) union all (select id, name from table_b where (deleted = false and active = true))`; |
198 |
| - expect(getLimitedQuery(query, 100)).toBe(`${query} limit 100;`); |
199 |
| - }); |
200 |
| - }); |
201 |
| -}); |
0 commit comments