yuyang-ok commented on issue #8926:
URL: 
https://github.com/apache/arrow-datafusion/issues/8926#issuecomment-1914044312

   @alamb  I have this code to test.
   
   ~~~
   use std::{any::Any, sync::Arc};
   
   use datafusion::{
       arrow::datatypes::{Schema, SchemaRef},
       config::{ConfigExtension, ExtensionOptions},
       datasource::TableProvider,
       execution::context::SessionState,
       logical_expr::TableType,
       physical_plan::ExecutionPlan,
       prelude::*,
   };
   
   #[tokio::main]
   async fn main() {
       let cfg = SessionConfig::new();
       let cfg = cfg.with_information_schema(true);
   
       let ctx = SessionContext::new();
   
       ctx.register_table("xxx", Arc::new(TP {})).unwrap();
       let mut config = ctx.copied_config();
       config.options_mut().extensions.insert(EXT {});
   
       let state = SessionState::new_with_config_rt(config, ctx.runtime_env());
   
       let plan = state
           .create_logical_plan("select * from xxx")
           .await
           .unwrap();
       let df = DataFrame::new(state, plan);
       df.show().await.unwrap();
   }
   
   impl ConfigExtension for EXT {
       const PREFIX: &'static str = "fabric";
   }
   
   impl ExtensionOptions for EXT {
       fn as_any(&self) -> &dyn Any {
           self
       }
   
       fn as_any_mut(&mut self) -> &mut dyn Any {
           self
       }
   
       fn cloned(&self) -> Box<dyn ExtensionOptions> {
           Box::new(self.clone())
       }
   
       fn set(&mut self, key: &str, value: &str) -> 
datafusion::error::Result<()> {
           todo!()
       }
   
       fn entries(&self) -> Vec<datafusion::config::ConfigEntry> {
           todo!()
       }
   }
   
   #[derive(Clone)]
   struct EXT {}
   
   impl std::fmt::Debug for EXT {
       fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
           write!(f, "{}", "haha this datafusion ext.")
       }
   }
   
   struct TP {}
   
   #[async_trait::async_trait]
   
   impl TableProvider for TP {
       fn as_any(&self) -> &dyn Any {
           self
       }
       fn schema(&self) -> SchemaRef {
           Arc::new(Schema::empty())
       }
   
       fn table_type(&self) -> TableType {
           TableType::View
       }
       async fn scan(
           &self,
           state: &SessionState,
           projection: Option<&Vec<usize>>,
           filters: &[Expr],
           limit: Option<usize>,
       ) -> datafusion::error::Result<Arc<dyn ExecutionPlan>> {
           let x = state.config_options().extensions.get::<EXT>();
           println!("ext is :{:?}", x);
   
           unimplemented!()
       }
   }
   ~~~
   But I am getting this error.
   ~~~
   
   Finished dev [unoptimized + debuginfo] target(s) in 15.87s
        Running `target/debug/abc-rust`
   thread 'main' panicked at src/main.rs:29:10:
   called `Result::unwrap()` on an `Err` value: Plan("table 
'datafusion.public.xxx' not found")
   stack backtrace:
      0: rust_begin_unwind
                at 
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
      1: core::panicking::panic_fmt
                at 
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
      2: core::result::unwrap_failed
                at 
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
      3: core::result::Result<T,E>::unwrap
                at 
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1077:23
      4: abc_rust::main::{{closure}}
                at ./src/main.rs:26:16
      5: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/park.rs:282:63
      6: tokio::runtime::coop::with_budget
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/coop.rs:107:5
      7: tokio::runtime::coop::budget
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/coop.rs:73:5
      8: tokio::runtime::park::CachedParkThread::block_on
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/park.rs:282:31
      9: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/context/blocking.rs:66:9
     10: 
tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/scheduler/multi_thread/mod.rs:87:13
     11: tokio::runtime::context::runtime::enter_runtime
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/context/runtime.rs:65:16
     12: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/scheduler/multi_thread/mod.rs:86:9
     13: tokio::runtime::runtime::Runtime::block_on
                at 
/home/yuyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/runtime/runtime.rs:350:45
     14: abc_rust::main
                at ./src/main.rs:31:5
     15: core::ops::function::FnOnce::call_once
                at 
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 
backtrace.
   ~~~
   
   somehow I can get `SessionState` from 
https://docs.rs/datafusion/latest/datafusion/execution/context/struct.SessionContext.html#method.state
 ,
   But I am not able to modify it. maybe missing some `config_options_mut` ???
   


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