(t *testing.T)
| 304 | } |
| 305 | |
| 306 | func TestAST_RewriteFunctionTableRefs(t *testing.T) { |
| 307 | sqlVariations := []struct { |
| 308 | title string |
| 309 | sql string |
| 310 | expectedSql string |
| 311 | }{ |
| 312 | { |
| 313 | "no replace", |
| 314 | `select * from AdBid a join AdImp i on a.id=i.id where a='1' group by b limit 2`, |
| 315 | `SELECT * FROM AdBid AS a INNER JOIN AdImp AS i ON ((a.id = i.id)) WHERE (a = '1') GROUP BY b LIMIT 2`, |
| 316 | }, |
| 317 | { |
| 318 | "simple replace", |
| 319 | `select * from read_csv( 'AdBids.csv', delim='|', columns={'timestamp':'TIMESTAMP'})`, |
| 320 | `SELECT * FROM AdBids`, |
| 321 | }, |
| 322 | { |
| 323 | "replace with join and alias", |
| 324 | ` |
| 325 | select * from |
| 326 | read_csv( 'AdBids.csv', delim='|', columns={'timestamp':'TIMESTAMP'}) as b join |
| 327 | AdImpressions i on b.id=i.id |
| 328 | `, |
| 329 | `SELECT * FROM AdBids AS b INNER JOIN AdImpressions AS i ON ((b.id = i.id))`, |
| 330 | }, |
| 331 | { |
| 332 | "join with sub query", |
| 333 | ` |
| 334 | select * from |
| 335 | read_csv( 'AdBids.csv', delim='|', columns={'timestamp':'TIMESTAMP'}) a join |
| 336 | (select * from read_csv( 'AdImpressions.csv', delim='|', columns={'timestamp':'TIMESTAMP'}) i1 where i1.city='Bengaluru') i on a.id=i.id |
| 337 | where a='1' group by b limit 2`, |
| 338 | `SELECT * FROM AdBids AS a INNER JOIN (SELECT * FROM AdImpressions AS i1 WHERE (i1.city = 'Bengaluru')) AS i ON ((a.id = i.id)) WHERE (a = '1') GROUP BY b LIMIT 2`, |
| 339 | }, |
| 340 | { |
| 341 | "replace with CTEs", |
| 342 | ` |
| 343 | with |
| 344 | tbl2 as (select col1 from read_csv( 'AdBids.csv', delim='|', columns={'timestamp':'TIMESTAMP'})), |
| 345 | tbl3 as (select col1 from read_csv( 'AdImpressions.csv', delim='|', columns={'timestamp':'TIMESTAMP'})) |
| 346 | select col1 from tbl2 join tbl3 on tbl2.id = tbl3.id |
| 347 | `, |
| 348 | `WITH tbl2 AS (SELECT col1 FROM AdBids), tbl3 AS (SELECT col1 FROM AdImpressions)SELECT col1 FROM tbl2 INNER JOIN tbl3 ON ((tbl2.id = tbl3.id))`, |
| 349 | }, |
| 350 | { |
| 351 | "replace with CTEs and unions", |
| 352 | ` |
| 353 | with |
| 354 | tbl2 as (select col1 from read_csv( 'AdBids_May.csv', delim='|', columns={'timestamp':'TIMESTAMP'})), |
| 355 | tbl3 as (select col1 from read_csv( 'AdBids_June.csv', delim='|', columns={'timestamp':'TIMESTAMP'})) |
| 356 | select col1 from tbl2 union all select col1 from tbl3 union all select col1 from read_csv( 'AdBids_July.csv', delim='|', columns={'timestamp':'TIMESTAMP'}) |
| 357 | `, |
| 358 | `WITH tbl2 AS (SELECT col1 FROM AdBids_May), tbl3 AS (SELECT col1 FROM AdBids_June)(SELECT col1 FROM tbl2) UNION ALL ((SELECT col1 FROM tbl3) UNION ALL (SELECT col1 FROM AdBids_July))`, |
| 359 | }, |
| 360 | { |
| 361 | "replace with pivot statement", |
| 362 | ` |
| 363 | pivot |
nothing calls this directly
no test coverage detected