[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #7441: Fix `describe ` to work without SessionContext

Tue, 29 Aug 2023 05:39:18 -0700


alamb commented on code in PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#discussion_r1308755281


##########
datafusion/core/tests/dataframe/describe.rs:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::{
+    assert_batches_eq,
+    prelude::{ParquetReadOptions, SessionContext},
+};
+use datafusion_common::{test_util::parquet_test_data, Result};
+
+#[tokio::test]
+async fn describe() -> Result<()> {

Review Comment:
   I just moved these tests into their own module to make it easier to find. 
Note that `Dataframe::describe` and the `DESCRIBE` sql command are different 😱 



##########
datafusion/core/tests/sql/describe.rs:
##########
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::assert_batches_eq;
+use datafusion::prelude::*;
+use datafusion_common::test_util::parquet_test_data;
+
+#[tokio::test]
+async fn describe_plan() {
+    let ctx = parquet_context().await;
+
+    let query = "describe alltypes_tiny_pages";
+    let results = ctx.sql(query).await.unwrap().collect().await.unwrap();
+
+    let expected = vec![
+        "+-----------------+-----------------------------+-------------+",
+        "| column_name     | data_type                   | is_nullable |",
+        "+-----------------+-----------------------------+-------------+",
+        "| id              | Int32                       | YES         |",
+        "| bool_col        | Boolean                     | YES         |",
+        "| tinyint_col     | Int8                        | YES         |",
+        "| smallint_col    | Int16                       | YES         |",
+        "| int_col         | Int32                       | YES         |",
+        "| bigint_col      | Int64                       | YES         |",
+        "| float_col       | Float32                     | YES         |",
+        "| double_col      | Float64                     | YES         |",
+        "| date_string_col | Utf8                        | YES         |",
+        "| string_col      | Utf8                        | YES         |",
+        "| timestamp_col   | Timestamp(Nanosecond, None) | YES         |",
+        "| year            | Int32                       | YES         |",
+        "| month           | Int32                       | YES         |",
+        "+-----------------+-----------------------------+-------------+",
+    ];
+
+    assert_batches_eq!(expected, &results);
+
+    // also ensure we plan Describe via SessionState

Review Comment:
   Without the code in this PR, this test fails like this:
   
   ```
   ---- sql::describe::describe_plan stdout ----
   thread 'sql::describe::describe_plan' panicked at 'called `Result::unwrap()` 
on an `Err` value: Internal("Unsupported logical plan: DescribeTable must be 
root of the plan")', datafusion/core/tests/sql/describe.rs:55:38
   stack backtrace:
      0: rust_begin_unwind
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
      1: core::panicking::panic_fmt
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
      2: core::result::unwrap_failed
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1651:5
      3: core::result::Result<T,E>::unwrap
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1076:23
      4: core_integration::sql::describe::describe_plan::{{closure}}
                at ./tests/sql/describe.rs:55:19
      5: <core::pin::Pin<P> as core::future::future::Future>::poll
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/future/future.rs:125:9
      6: <core::pin::Pin<P> as core::future::future::Future>::poll
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/future/future.rs:125:9
      7: 
tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:665:57
      8: tokio::runtime::coop::with_budget
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:107:5
      9: tokio::runtime::coop::budget
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:73:5
     10: 
tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:665:25
     11: tokio::runtime::scheduler::current_thread::Context::enter
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:410:19
     12: 
tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:664:36
     13: 
tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:743:68
     14: tokio::runtime::context::scoped::Scoped<T>::set
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/scoped.rs:40:9
     15: tokio::runtime::context::set_scheduler::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context.rs:176:26
     16: std::thread::local::LocalKey<T>::try_with
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:270:16
     17: std::thread::local::LocalKey<T>::with
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:246:9
     18: tokio::runtime::context::set_scheduler
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context.rs:176:9
     19: tokio::runtime::scheduler::current_thread::CoreGuard::enter
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:743:27
     20: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:652:19
     21: 
tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:175:28
     22: tokio::runtime::context::runtime::enter_runtime
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/runtime.rs:65:16
     23: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/current_thread/mod.rs:167:9
     24: tokio::runtime::runtime::Runtime::block_on
                at 
/Users/alamb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/runtime.rs:347:47
     25: core_integration::sql::describe::describe_plan
                at ./tests/sql/describe.rs:57:5
     26: core_integration::sql::describe::describe_plan::{{closure}}
                at ./tests/sql/describe.rs:24:27
     27: core::ops::function::FnOnce::call_once
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
     28: core::ops::function::FnOnce::call_once
                at 
/rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 
backtrace.
   ```



##########
datafusion/core/tests/dataframe/describe.rs:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::{
+    assert_batches_eq,
+    prelude::{ParquetReadOptions, SessionContext},
+};
+use datafusion_common::{test_util::parquet_test_data, Result};
+
+#[tokio::test]
+async fn describe() -> Result<()> {

Review Comment:
   I just moved these tests into their own module to make it easier to find. 
Note that `Dataframe::describe` and the `DESCRIBE` sql command are different 😱 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to