leaves12138 commented on code in PR #1435:
URL: https://github.com/apache/paimon-rust/pull/1435#discussion_r4596798317


##########
crates/integrations/datafusion/src/sql_context.rs:
##########
@@ -519,7 +520,23 @@ impl SQLContext {
             let lateral_changed = crate::lateral_views::rewrite(&mut 
statements[0])?;
             let compat_changed =
                 crate::expression_compat::rewrite(&mut statements[0], 
&self.ctx.state())?;
-            binary_changed || regex_changed || lateral_changed || 
compat_changed
+            let state = self.ctx.state();
+            // Queries resolve after catalog SQL functions have been expanded 
below.
+            let max_pt_changed = if matches!(
+                statements[0],
+                Statement::Query(_) | Statement::Explain { .. }
+            ) {
+                false
+            } else {
+                Box::pin(crate::partition_functions::rewrite(

Review Comment:
   [P2] Defer max_pt folding until temporary views are queried
   
   This non-query branch also rewrites `CREATE TEMPORARY VIEW` before 
`handle_create_view` stores its query/logical plan, so the new non-immutable 
metadata lookup becomes a permanent string literal in a session view. For 
example, after creating `t(id INT, p INT) PARTITIONED BY (p)` and inserting 
`(1, 1)`, execute:
   
   ```sql
   CREATE TEMPORARY VIEW latest_rows AS
   SELECT * FROM t WHERE p = CAST(max_pt('t') AS INT);
   INSERT INTO t VALUES (2, 2);
   SELECT max_pt('t');                 -- '2'
   SELECT MAX(p) FROM latest_rows;     -- 1, not 2
   ```
   
   I independently reproduced this on the reviewed head. A control temporary 
view `SELECT * FROM t` sees both rows, so this is not a frozen table snapshot: 
only `max_pt` is permanently folded. Likewise, `CREATE TEMPORARY VIEW 
latest_partition AS SELECT max_pt('t') AS latest` keeps returning `'1'` while 
direct calls return `'2'`. This silently makes the documented latest-partition 
filtering pattern read old partitions (or no rows after they are dropped), 
despite later SELECT statements reading fresh table data. Preserve the 
unresolved metadata call and resolve it when the view is queried, as persistent 
views do, or explicitly reject unsupported view definitions rather than 
silently snapshotting this function. Please add a temporary-view regression 
that inserts a newer partition after view creation.
   



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