j1wonpark opened a new issue, #7855:
URL: https://github.com/apache/kyuubi/issues/7855

   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   
   ### Search before asking
   
   - [x] I have searched in the 
[issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Describe the bug
   
   With the Spark AuthZ extension enabled, querying a cached permanent view 
containing CTEs through a fresh analysis misses the cache and recomputes the 
result.
   
   ```scala
   spark.sql("""
     CREATE VIEW v AS
     WITH c AS (SELECT 1 AS id) SELECT id FROM c
   """)
   spark.sql("SELECT id FROM v").cache().count()
   spark.sql("SELECT id FROM v").explain(true)
   // Expected: InMemoryRelation; actual: cache is not reused.
   ```
   
   Each analysis assigns fresh CTE IDs. Spark’s `NormalizeCTEIds` cannot 
traverse the view plan hidden inside `PermanentViewMarker`, which is a 
`LeafNode`. Its canonicalization leaves those IDs unchanged, so equivalent 
queries produce different cache keys.
   
   ### Affects Version(s)
   
   master, 1.12.0 with Spark 4.1.1+ providing `NormalizeCTEIds`.
   
   ### Additional context
   
   Follow-up to #7739: removing the projects introduced by `newInstance()` does 
not address fresh CTE IDs assigned during independent analysis.
   
   The proposed fix builds on that change to normalize CTE IDs within the view 
scope for cache-key comparison, including nested views and subqueries.
   
   ### Are you willing to submit PR?
   
   - [x] Yes. I would be willing to submit a PR with guidance from the Kyuubi 
community to fix.


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to