Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Invalid query generated after series of filters/mutates #1496
When a series of mutates/filters are moved to "WITH" statements, the compiled statement sometimes includes incorrect table references.
This isn't actually a bug, but
WITH t0 AS ( SELECT * FROM foobar WHERE `PARTITIONTIME` < DATE '2017-01-01' ), t1 AS ( SELECT CAST(`file_date` AS DATE) AS `file_date`, `PARTITIONTIME`, `val` FROM t0 ), t2 AS ( SELECT t1.*, t0.`val` * 2 AS `XYZ` FROM t1 WHERE t1.`file_date` < DATE '2017-01-01' ) SELECT t2.* FROM t2 CROSS JOIN t2 t3
This is potentially a duplicate of #1460.
@seibs Is there another issue that manifested this way with non-generated table names?
@seibs Finally got around to fixing this. The issue here is that we're fusing across projections without considering the immediate parent table. What happens is that when we're looking for fusion opportunities in a project we look for common expressions in the deepest base table in the tree and assume that we can substitute in the matching columns from that in whatever query we're projecting. This is invalid because there may be other non-fused relations in between. For now, the fix is to only allow fusing with the immediate parent.