schizophrenicmaniac commented on PR #40294:
URL: https://github.com/apache/shardingsphere/pull/40294#issuecomment-6282784920

   @terrymanu Thanks for the detailed review. All five points are addressed in 
the latest commit.
   
   The CTE is now found from the actual FROM source. The column owner is 
matched against the table alias or name in FROM (joins included), and only that 
table's CTE definition is used. So `SELECT q.n FROM foo_cte q` works, and the 
case where `a` and `b` both have `n` now resolves to `b`. The CTE column list 
is matched against the anchor projections after `*` is expanded, so `c(a, b, n) 
AS (SELECT foo_tbl.*, 'foo' FROM foo_tbl)` picks the literal for `n`. If the 
matched projection is itself a column of another expression-backed CTE, the 
lookup follows the anchor select's FROM into the CTEs declared before it, until 
it reaches an expression or a physical column. The outer column label is kept 
as the alias.
   
   The new lookup is marked with `@HighFrequencyInvocation` and uses plain 
loops instead of streams, and the new `columnAlias` parameter is now 
`@Nullable`.
   
   I added tests for the same column name in two CTEs, an aliased CTE 
reference, `foo_tbl.*` inside a CTE, and the chained `bar_cte (m) AS (SELECT n 
FROM foo_cte)` case, which also checks that the `m` alias is kept.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to