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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5c5a0bb  Fix SQL planner to support multibyte column names (#357)
5c5a0bb is described below

commit 5c5a0bb0af8130069071c193ca8c214022666a4e
Author: Agata Naomichi <[email protected]>
AuthorDate: Thu May 20 01:44:07 2021 +0900

    Fix SQL planner to support multibyte column names (#357)
    
    * Fix SQL planner to support multibyte column names
    
    * Fix test cases for multibyte column name support
    
    * Use starts_with
---
 datafusion/src/sql/planner.rs | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs
index 036c66d..34c5901 100644
--- a/datafusion/src/sql/planner.rs
+++ b/datafusion/src/sql/planner.rs
@@ -857,7 +857,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             ),
 
             SQLExpr::Identifier(ref id) => {
-                if &id.value[0..1] == "@" {
+                if id.value.starts_with('@') {
                     let var_names = vec![id.value.clone()];
                     Ok(Expr::ScalarVariable(var_names))
                 } else {
@@ -1520,7 +1520,7 @@ mod tests {
     use functions::ScalarFunctionImplementation;
 
     const PERSON_COLUMN_NAMES: &str =
-        "id, first_name, last_name, age, state, salary, birth_date";
+        "id, first_name, last_name, age, state, salary, birth_date, 😀";
 
     #[test]
     fn select_no_relation() {
@@ -1559,7 +1559,7 @@ mod tests {
         let sql = "SELECT *, age FROM person";
         let err = logical_plan(sql).expect_err("query should have failed");
         assert_eq!(
-            "Plan(\"Projections require unique expression names but the 
expression \\\"#age\\\" at position 3 and \\\"#age\\\" at position 7 have the 
same name. Consider aliasing (\\\"AS\\\") one of them.\")",
+            "Plan(\"Projections require unique expression names but the 
expression \\\"#age\\\" at position 3 and \\\"#age\\\" at position 8 have the 
same name. Consider aliasing (\\\"AS\\\") one of them.\")",
             format!("{:?}", err)
         );
     }
@@ -1568,7 +1568,7 @@ mod tests {
     fn select_wildcard_with_repeated_column_but_is_aliased() {
         quick_test(
             "SELECT *, first_name AS fn from person",
-            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date, #first_name AS fn\
+            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date, #😀, #first_name AS fn\
             \n  TableScan: person projection=None",
         );
     }
@@ -2044,9 +2044,9 @@ mod tests {
     #[test]
     fn select_wildcard_with_groupby() {
         quick_test(
-            "SELECT * FROM person GROUP BY id, first_name, last_name, age, 
state, salary, birth_date",
-            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date\
-             \n  Aggregate: groupBy=[[#id, #first_name, #last_name, #age, 
#state, #salary, #birth_date]], aggr=[[]]\
+            r#"SELECT * FROM person GROUP BY id, first_name, last_name, age, 
state, salary, birth_date, "😀""#,
+            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date, #😀\
+             \n  Aggregate: groupBy=[[#id, #first_name, #last_name, #age, 
#state, #salary, #birth_date, #😀]], aggr=[[]]\
              \n    TableScan: person projection=None",
         );
         quick_test(
@@ -2365,7 +2365,7 @@ mod tests {
     fn test_wildcard() {
         quick_test(
             "SELECT * from person",
-            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date\
+            "Projection: #id, #first_name, #last_name, #age, #state, #salary, 
#birth_date, #😀\
             \n  TableScan: person projection=None",
         );
     }
@@ -2679,6 +2679,14 @@ mod tests {
         quick_test(sql, expected);
     }
 
+    #[test]
+    fn select_multibyte_column() {
+        let sql = r#"SELECT "😀" FROM person"#;
+        let expected = "Projection: #😀\
+            \n  TableScan: person projection=None";
+        quick_test(sql, expected);
+    }
+
     fn logical_plan(sql: &str) -> Result<LogicalPlan> {
         let planner = SqlToRel::new(&MockContextProvider {});
         let result = DFParser::parse_sql(&sql);
@@ -2712,6 +2720,7 @@ mod tests {
                         DataType::Timestamp(TimeUnit::Nanosecond, None),
                         false,
                     ),
+                    Field::new("😀", DataType::Int32, false),
                 ])),
                 "orders" => Some(Schema::new(vec![
                     Field::new("order_id", DataType::UInt32, false),

Reply via email to