You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix check_access_control_on_utilized_columns_only for CTE
Previously we weren't associating the with query with the columns used
from it in the main part of the query, so we wouldn't consider any
columns as used. When the usage within the cte or outside of it was
just an identifier, we would have the utilized column collected anyway
because the column collected in the main query kept the source table
information. However, if there was an expression in between, we would
lose that information, and we wouldn't check access control for the
column that was used in an expression in the cte.
Example:
For the following query
```
with cte as (select x as c1, z + 1 as c2 from t13) select c1, c2 from (select * from cte)
```
Previously we would only check access permissions on t13.x, but not
t13.z. With this change we will check column access on both 13.x and
t13.z.
Fix empty relations case
Add error message to utilized columns warning.
handle ctes used multiple times
fixup >1 reference support
Add tests for multiple cte with same name
Co-authored-by: Kevin Tang <tangk@meta.com>
"with cte1 as (select x + 1 as c1, y as c2, z + 1 as c3 from t13), cte2 as (with cte1 AS (select y +1 as c1 from t13) select * from cte1) SELECT cte1.c1, cte2.c1 from cte1 join cte2 on cte1.c1=cte2.c1",
// TODO(kevintang2022): Fix visitWithQuery so that it looks up relation properly.
553
+
// Currently, it just looks the relations using the name (string) of the CTE
554
+
assertUtilizedTableColumns(
555
+
"with cte1 as (select x + 1 as c1 from t13), cte2 as (with cte1 as (select x + 1 as c2, y + 1 as c3, z as c4 from t13) select * from cte1) select cte1.c1, cte2.c3 from cte1 join cte2 on true",
"with cte1 as (select x + 1 as c1 from t13), cte2 as (with cte1 as (select a + 1 as c2, b + 1 as c3, c as c4 from t1) select * from cte1) select cte1.c1 from cte1 join cte2 on true",
"with cte1 as (select x + 1 as c1 from t13), cte2 as (with cte3 as (select x + 1 as c2, y + 1 as c3, z as c4 from t13) select * from cte3) select cte1.c1, cte2.c3 from cte1 join cte2 on true",
"with cte1 as (select x + 1 as c1 from t13), cte2 as (with cte3 as (select a + 1 as c2, b + 1 as c3, c as c4 from t1) select * from cte3) select cte1.c1 from cte1 join cte2 on true",
0 commit comments