jonahgao opened a new pull request, #12341:
URL: https://github.com/apache/datafusion/pull/12341

   ## Which issue does this PR close?
   A more general fix for #12183
   
   
   ## Rationale for this change
   The two expressions in the following code have the same `schema_name`s, so 
the `NamePreserver` will not take effect when `expr1` is rewritten to `expr2`. 
But they will produce different fields, which will result in schema changes.
   
   Therefore the `NamePreserver` needs to preserve both the qualifier and 
schema name at the same time.
   ```rust
      #[test]
       fn test_expr_schema_name() {
           let schema = Schema::new(vec![
               Field::new("a", DataType::Int32, true),
               Field::new("test.a", DataType::Utf8, true),
           ]);
           let dfschema = DFSchema::try_from_qualified_schema("test", 
&schema).unwrap();
           let expr1 = Expr::Column(Column::new_unqualified("test.a"));
           let expr2 = Expr::Column(Column::new(Some("test"), "a"));
   
           assert_eq!(
               expr1.schema_name().to_string(),
               expr2.schema_name().to_string()
           );
   
           let field1 = expr1.to_field(&dfschema).unwrap();
           let field2 = expr2.to_field(&dfschema).unwrap();
   
           // field1: qualifier: None, name: "test.a"
           println!(
               "field1: qualifier: {:?}, name: {:?}",
               field1.0,
               field1.1.name()
           );
           // field2: qualifier: Some(Bare { table: "test" }), name: "a"
           println!(
               "field2: qualifier: {:?}, name: {:?}",
               field2.0,
               field2.1.name()
           );
       }
   ```
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Yes
   
   
   ## Are there any user-facing changes?
   No


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