You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/08/29 12:37:02 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request, #7441: Fix describe to work without SessionContext

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

   ## Which issue does this PR close?
   
   Closes https://github.com/apache/arrow-datafusion/issues/7440
   
   ## Rationale for this change
   
   I want to be able to run `DESCRIBE` in SQL without a `SessionContext`. 
   
   ## What changes are included in this PR?
   
   1. Move the implementation of `DESCRIBE` planning to the physical planner
   2. Add some tests
   
   ## Are these changes tested?
   Yes
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   3. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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 pull request #7441: Fix `describe ` to work without SessionContextPosted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#issuecomment-1710545898

   Converting to draft until I sort out the errors and file a follow on ticket


-- 
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 pull request #7441: Fix `describe

` to work without SessionContextPosted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#issuecomment-1710795829

   
   Filed https://github.com/apache/arrow-datafusion/issues/7501 to track the security question


-- 
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 #7441: Fix describe to work without SessionContext

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#discussion_r1308754530


##########
datafusion/core/src/execution/context.rs:
##########
@@ -487,53 +481,6 @@ impl SessionContext {
         Ok(DataFrame::new(self.state(), plan))
     }
 
-    // return an record_batch which describe table
-    async fn return_describe_table_record_batch(

Review Comment:
   This PR basically just moves this function into the physical planner



-- 
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] comphead commented on a diff in pull request #7441: Fix `describe

` to work without SessionContextPosted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#discussion_r1309488957


##########
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:
   Dataframe `describe` is similar to pandas https://www.w3schools.com/python/pandas/ref_df_describe.asp 



-- 
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 #7441: Fix `describe

` to work without SessionContextPosted by "alamb (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb merged pull request #7441: Fix `describe

` to work without SessionContextPosted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441


-- 
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] comphead commented on pull request #7441: Fix `describe

` to work without SessionContextPosted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#issuecomment-1698341294

   just a small neat on DESC without SessionContext: there is no plans to have a security layer in DF? because session context will help in this case, having some security token and allowing to know if the user can DESC table


-- 
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 pull request #7441: Fix `describe

` to work without SessionContextPosted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7441:
URL: https://github.com/apache/arrow-datafusion/pull/7441#issuecomment-1708356258

   >  just a small nit on DESC without SessionContext: there is no plans to have a security layer in DF? because session context will help in this case, having some security token and allowing to know if the user can DESC table
   
   It is an interesting question about hooking up a security model to DataFusion -- at the moment I don't know of any plans, but having some sort of pluggable auth system would seem very much in keeping with DataFusion's long term goals.
   
   I'll write up a ticket with some ideas over the next few days


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