Apache DataFusion SQL Query Engine
Fix SQL planner to support multibyte column names (#357)
Agata Naomichi5c5a0bb0af81
diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rsindex 036c66da16..34c5901b45 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),