This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new ccbd01a9b8 Fix broken build/test from merge (#10637)
ccbd01a9b8 is described below

commit ccbd01a9b88f06df19ea85b1874de5156f696dad
Author: Phillip LeBlanc <[email protected]>
AuthorDate: Thu May 23 21:32:37 2024 +0900

    Fix broken build/test from merge (#10637)
    
    * Move and fix test test_table_references_in_plan_to_sql
    
    * merge issue
---
 datafusion/sql/src/unparser/plan.rs     | 35 ++-------------------------------
 datafusion/sql/tests/sql_integration.rs | 27 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/datafusion/sql/src/unparser/plan.rs 
b/datafusion/sql/src/unparser/plan.rs
index 833ac5cdbe..45e0f59a5e 100644
--- a/datafusion/sql/src/unparser/plan.rs
+++ b/datafusion/sql/src/unparser/plan.rs
@@ -141,7 +141,8 @@ impl Unparser<'_> {
                 let mut builder = TableRelationBuilder::default();
                 let mut table_parts = vec![];
                 if let Some(catalog_name) = scan.table_name.catalog() {
-                    table_parts.push(self.new_ident(catalog_name.to_string()));
+                    table_parts
+                        
.push(self.new_ident_quoted_if_needs(catalog_name.to_string()));
                 }
                 if let Some(schema_name) = scan.table_name.schema() {
                     table_parts
@@ -515,35 +516,3 @@ impl From<BuilderError> for DataFusionError {
         DataFusionError::External(Box::new(e))
     }
 }
-
-#[cfg(test)]
-mod test {
-    use crate::unparser::plan_to_sql;
-    use arrow::datatypes::{DataType, Field, Schema};
-    use datafusion_expr::{col, logical_plan::table_scan};
-    #[test]
-    fn test_table_references_in_plan_to_sql() {
-        fn test(table_name: &str, expected_sql: &str) {
-            let schema = Schema::new(vec![
-                Field::new("id", DataType::Utf8, false),
-                Field::new("value", DataType::Utf8, false),
-            ]);
-            let plan = table_scan(Some(table_name), &schema, None)
-                .unwrap()
-                .project(vec![col("id"), col("value")])
-                .unwrap()
-                .build()
-                .unwrap();
-            let sql = plan_to_sql(&plan).unwrap();
-
-            assert_eq!(format!("{}", sql), expected_sql)
-        }
-
-        test("catalog.schema.table", "SELECT 
\"catalog\".\"schema\".\"table\".\"id\", 
\"catalog\".\"schema\".\"table\".\"value\" FROM 
\"catalog\".\"schema\".\"table\"");
-        test("schema.table", "SELECT \"schema\".\"table\".\"id\", 
\"schema\".\"table\".\"value\" FROM \"schema\".\"table\"");
-        test(
-            "table",
-            "SELECT \"table\".\"id\", \"table\".\"value\" FROM \"table\"",
-        );
-    }
-}
diff --git a/datafusion/sql/tests/sql_integration.rs 
b/datafusion/sql/tests/sql_integration.rs
index 685911ee81..0d84d9b2ab 100644
--- a/datafusion/sql/tests/sql_integration.rs
+++ b/datafusion/sql/tests/sql_integration.rs
@@ -27,6 +27,7 @@ use datafusion_common::{
     assert_contains, plan_err, DFSchema, DataFusionError, ParamValues, Result,
     ScalarValue, TableReference,
 };
+use datafusion_expr::{col, table_scan};
 use datafusion_expr::{
     logical_plan::{LogicalPlan, Prepare},
     AggregateUDF, ColumnarValue, ScalarUDF, ScalarUDFImpl, Signature, 
TableSource,
@@ -4799,6 +4800,32 @@ fn test_unnest_logical_plan() -> Result<()> {
     Ok(())
 }
 
+#[test]
+fn test_table_references_in_plan_to_sql() {
+    fn test(table_name: &str, expected_sql: &str) {
+        let schema = Schema::new(vec![
+            Field::new("id", DataType::Utf8, false),
+            Field::new("value", DataType::Utf8, false),
+        ]);
+        let plan = table_scan(Some(table_name), &schema, None)
+            .unwrap()
+            .project(vec![col("id"), col("value")])
+            .unwrap()
+            .build()
+            .unwrap();
+        let sql = plan_to_sql(&plan).unwrap();
+
+        assert_eq!(format!("{}", sql), expected_sql)
+    }
+
+    test("catalog.schema.table", "SELECT catalog.\"schema\".\"table\".id, 
catalog.\"schema\".\"table\".\"value\" FROM catalog.\"schema\".\"table\"");
+    test("schema.table", "SELECT \"schema\".\"table\".id, 
\"schema\".\"table\".\"value\" FROM \"schema\".\"table\"");
+    test(
+        "table",
+        "SELECT \"table\".id, \"table\".\"value\" FROM \"table\"",
+    );
+}
+
 #[cfg(test)]
 #[ctor::ctor]
 fn init() {


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

Reply via email to