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 2022/04/15 14:18:36 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request, #2243: Move identifer case tests to `sql_integ`, add negative cases, Debug for `DataFrame`

alamb opened a new pull request, #2243:
URL: https://github.com/apache/arrow-datafusion/pull/2243

   # Which issue does this PR close?
   
   
   Closes https://github.com/apache/arrow-datafusion/issues/2227
   
    # Rationale for this change
   
   Basically so that it is clear what types of identifier comparisons are meant to work
   
   Also, Re cleaning up tests https://github.com/apache/arrow-datafusion/issues/743
   
   # What changes are included in this PR?
   
   1. Move normalized column identifier tests into sql_integration to hopefully make them more discoverable
   2. Add a negative case (where the query fails) adapted from the great one from @ReggieFan on https://github.com/apache/arrow-datafusion/pull/2211 to make it clear this is expected behavior
   3. Add some `Debug`  impl (so I can use `unwrap_err()`
   
   # Are there any user-facing changes?
   Debug impl for `DataFame`


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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2243: Move identifer case tests to `sql_integ`, add negative cases, Debug for `DataFrame`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2243:
URL: https://github.com/apache/arrow-datafusion/pull/2243#discussion_r851296452


##########
datafusion/core/tests/sql/idenfifers.rs:
##########
@@ -0,0 +1,226 @@
+use std::sync::Arc;
+
+use arrow::{array::StringArray, record_batch::RecordBatch};
+use datafusion::{
+    assert_batches_sorted_eq, assert_contains, datasource::MemTable, prelude::*,
+};
+
+use crate::sql::plan_and_collect;
+
+#[tokio::test]
+async fn normalized_column_identifiers() {
+    // create local execution context
+    let ctx = SessionContext::new();
+
+    // register csv file with the execution context
+    ctx.register_csv(
+        "case_insensitive_test",
+        "tests/example.csv",
+        CsvReadOptions::new(),
+    )
+    .await
+    .unwrap();
+
+    let sql = "SELECT A, b FROM case_insensitive_test";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| a | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = "SELECT t.A, b FROM case_insensitive_test AS t";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| a | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    // Aliases
+
+    let sql = "SELECT t.A as x, b FROM case_insensitive_test AS t";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| x | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = "SELECT t.A AS X, b FROM case_insensitive_test AS t";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| x | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = r#"SELECT t.A AS "X", b FROM case_insensitive_test AS t"#;
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| X | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    // Order by
+
+    let sql = "SELECT t.A AS x, b FROM case_insensitive_test AS t ORDER BY x";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| x | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = "SELECT t.A AS x, b FROM case_insensitive_test AS t ORDER BY X";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| x | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = r#"SELECT t.A AS "X", b FROM case_insensitive_test AS t ORDER BY "X""#;
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| X | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    // Where
+
+    let sql = "SELECT a, b FROM case_insensitive_test where A IS NOT null";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| a | b |",
+        "+---+---+",
+        "| 1 | 2 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    // Group by
+
+    let sql = "SELECT a as x, count(*) as c FROM case_insensitive_test GROUP BY X";
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| x | c |",
+        "+---+---+",
+        "| 1 | 1 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+
+    let sql = r#"SELECT a as "X", count(*) as c FROM case_insensitive_test GROUP BY "X""#;
+    let result = plan_and_collect(&ctx, sql)
+        .await
+        .expect("ran plan correctly");
+    let expected = vec![
+        "+---+---+",
+        "| X | c |",
+        "+---+---+",
+        "| 1 | 1 |",
+        "+---+---+",
+    ];
+    assert_batches_sorted_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn case_insensitive_in_sql_errors() {

Review Comment:
   This is a new test added in this PR, based on the one from @ReggieFan on https://github.com/apache/arrow-datafusion/pull/2211 to make it clear this is expected behavior



##########
datafusion/core/src/execution/context.rs:
##########
@@ -1148,6 +1151,15 @@ pub struct SessionState {
     pub runtime_env: Arc<RuntimeEnv>,
 }
 
+impl Debug for SessionState {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SessionState")
+            .field("session_id", &self.session_id)
+            // TODO should we print out more?

Review Comment:
   There are a lot of other fields on SessionState -- I wasn't sure the value of printing them, so I left it as a future todo



##########
datafusion/core/src/execution/context.rs:
##########
@@ -3322,173 +3334,6 @@ mod tests {
         Ok(())
     }
 
-    #[tokio::test]

Review Comment:
   Moved out of `context.rs` and into `datafusion/core/tests/sql/idenfifers.rs` without change
   



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


[GitHub] [arrow-datafusion] yjshen merged pull request #2243: Move identifer case tests to `sql_integ`, add negative cases, Debug for `DataFrame`

Posted by GitBox <gi...@apache.org>.
yjshen merged PR #2243:
URL: https://github.com/apache/arrow-datafusion/pull/2243


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