alamb commented on code in PR #26558:
URL: https://github.com/apache/datafusion/pull/26558#discussion_r4393928039


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -129,7 +132,7 @@ impl AnalyzerRule for TypeCoercion {
 /// Coerce each node of `plan` and of its subqueries, from the leaves up.
 fn coerce_plan_and_subqueries(
     plan: LogicalPlan,
-    config: &ConfigOptions,
+    session_time_zone: Option<&str>,

Review Comment:
   why are we changing from the more general ConfigOptions to just passing in 
the timezone? 
   



##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -311,6 +311,65 @@ impl<'a> TypeCoercionRewriter<'a> {
         self
     }
 
+    /// Coerce a subquery whose outer plan has been coerced into `self.schema`.
+    ///
+    /// The subquery was coerced before its outer plan, against the types its
+    /// outer reference columns had when the plan was built. Coercing the outer
+    /// plan can change those types, for example for a `CASE` with `INT` and
+    /// `BIGINT` branches or a `UNION` of `INT` and `BIGINT` columns. In that
+    /// case the outer references take the new types and the subquery is
+    /// coerced again, so that its comparisons with them are coerced too.
+    fn coerce_subquery(&self, subquery: Subquery) -> Result<Subquery> {

Review Comment:
   isn't this kind of treating the symptom rather than the problem?  This 
basically rewalks down a subquery to recoerce it. That will probably work, but 
it is going to walk the query too many times
   
   It seems the core problem is that the subqueries are coerced with 
empty_schema in the first place:
   
   
https://github.com/apache/datafusion/blob/be2c37b4e1e118c0eb1963231be6a0282e2acdda/datafusion/optimizer/src/analyzer/type_coercion.rs#L170
   
   What if we fixed things so the correct outer schema was passed to the 
subquery?



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