You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/12/15 01:47:59 UTC

[GitHub] [arrow-datafusion] Jimexist commented on a change in pull request #1449: Support identifiers with `.` in them

Jimexist commented on a change in pull request #1449:
URL: https://github.com/apache/arrow-datafusion/pull/1449#discussion_r769181060



##########
File path: datafusion/tests/sql.rs
##########
@@ -5426,6 +5426,67 @@ async fn qualified_table_references() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn qualified_table_references_and_fields() -> Result<()> {
+    let mut ctx = ExecutionContext::new();
+
+    let c1: StringArray = vec!["foofoo", "foobar", "foobaz"]
+        .into_iter()
+        .map(Some)
+        .collect();
+    let c2: Int64Array = vec![1, 2, 3].into_iter().map(Some).collect();
+
+    let batch = RecordBatch::try_from_iter(vec![
+        ("f.c1", Arc::new(c1) as ArrayRef),
+        //  evil -- use the same name as the table
+        ("test.c2", Arc::new(c2) as ArrayRef),
+    ])?;
+
+    let table = MemTable::try_new(batch.schema(), vec![vec![batch]])?;
+    ctx.register_table("test", Arc::new(table))?;
+
+    // referring to the unquoted column is an error
+    let sql = format!(r#"SELECT f1.c1 from test"#);
+    let error = ctx.create_logical_plan(&sql).unwrap_err();
+    assert_contains!(
+        error.to_string(),
+        "No field named 'f1.c1'. Valid fields are 'test.f.c1', 'test.test.c2'"
+    );
+
+    // however, enclosing it in double quotes is ok
+    let sql = format!(r#"SELECT "f.c1" from test"#);
+    let actual = execute_to_batches(&mut ctx, &sql).await;
+    let expected = vec![
+        "+--------+",
+        "| f.c1   |",

Review comment:
       i wonder if it is okay to create column `....`

##########
File path: datafusion/tests/sql.rs
##########
@@ -5426,6 +5426,67 @@ async fn qualified_table_references() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn qualified_table_references_and_fields() -> Result<()> {
+    let mut ctx = ExecutionContext::new();
+
+    let c1: StringArray = vec!["foofoo", "foobar", "foobaz"]
+        .into_iter()
+        .map(Some)
+        .collect();
+    let c2: Int64Array = vec![1, 2, 3].into_iter().map(Some).collect();
+
+    let batch = RecordBatch::try_from_iter(vec![
+        ("f.c1", Arc::new(c1) as ArrayRef),
+        //  evil -- use the same name as the table
+        ("test.c2", Arc::new(c2) as ArrayRef),
+    ])?;
+
+    let table = MemTable::try_new(batch.schema(), vec![vec![batch]])?;
+    ctx.register_table("test", Arc::new(table))?;
+
+    // referring to the unquoted column is an error
+    let sql = format!(r#"SELECT f1.c1 from test"#);
+    let error = ctx.create_logical_plan(&sql).unwrap_err();
+    assert_contains!(
+        error.to_string(),
+        "No field named 'f1.c1'. Valid fields are 'test.f.c1', 'test.test.c2'"
+    );
+
+    // however, enclosing it in double quotes is ok
+    let sql = format!(r#"SELECT "f.c1" from test"#);
+    let actual = execute_to_batches(&mut ctx, &sql).await;
+    let expected = vec![
+        "+--------+",
+        "| f.c1   |",

Review comment:
       i wonder if it is okay to create column `"...."`




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org