From ffc3cf8c2efd35a4b487f9e8bb9733aa74257f0c Mon Sep 17 00:00:00 2001 From: gaojun Date: Sat, 2 Apr 2022 19:52:03 +0800 Subject: [PATCH 1/4] add show tables for datafusion cli --- datafusion-cli/src/context.rs | 23 +++++++++++++++++++---- datafusion-cli/src/main.rs | 13 ++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/datafusion-cli/src/context.rs b/datafusion-cli/src/context.rs index 6b76baffa04f9..ac543ed13c3a8 100644 --- a/datafusion-cli/src/context.rs +++ b/datafusion-cli/src/context.rs @@ -32,8 +32,14 @@ pub enum Context { impl Context { /// create a new remote context with given host and port - pub async fn new_remote(host: &str, port: u16) -> Result { - Ok(Context::Remote(BallistaContext::try_new(host, port).await?)) + pub async fn new_remote( + host: &str, + port: u16, + with_information_schema: bool, + ) -> Result { + Ok(Context::Remote( + BallistaContext::try_new(host, port, with_information_schema).await?, + )) } /// create a local context using the given config @@ -56,10 +62,19 @@ impl Context { pub struct BallistaContext(ballista::context::BallistaContext); #[cfg(feature = "ballista")] impl BallistaContext { - pub async fn try_new(host: &str, port: u16) -> Result { + pub async fn try_new( + host: &str, + port: u16, + with_information_schema: bool, + ) -> Result { use ballista::context::BallistaContext; use ballista::prelude::BallistaConfig; - let config: BallistaConfig = BallistaConfig::new() + let builder = BallistaConfig::builder(); + if with_information_schema { + builder.set("ballista.with_information_schema", "true"); + } + let config = builder + .build() .map_err(|e| DataFusionError::Execution(format!("{:?}", e)))?; let remote_ctx = BallistaContext::remote(host, port, &config) .await diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs index d76fe38e5fb62..a059d6eb2a5f3 100644 --- a/datafusion-cli/src/main.rs +++ b/datafusion-cli/src/main.rs @@ -82,6 +82,9 @@ struct Args { help = "Reduce printing other than the results and work quietly" )] quiet: bool, + + #[clap(long, help = "whether enable with_information_schema")] + with_information_schema: Option, } #[tokio::main] @@ -104,8 +107,16 @@ pub async fn main() -> Result<()> { session_config = session_config.with_batch_size(batch_size); }; + let mut enable_with_information_schema = false; + if let Some(with_information_schema) = args.with_information_schema { + session_config.with_information_schema(with_information_schema); + enable_with_information_schema = with_information_schema; + } + let mut ctx: Context = match (args.host, args.port) { - (Some(ref h), Some(p)) => Context::new_remote(h, p).await?, + (Some(ref h), Some(p)) => { + Context::new_remote(h, p, enable_with_information_schema).await? + } _ => Context::new_local(&session_config), }; From da2d9a8021fabb0c1ef07aeba1e4aad3f6d6b78a Mon Sep 17 00:00:00 2001 From: gaojun Date: Sat, 2 Apr 2022 22:26:56 +0800 Subject: [PATCH 2/4] fix error --- datafusion-cli/src/context.rs | 6 +++++- datafusion-cli/src/main.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/datafusion-cli/src/context.rs b/datafusion-cli/src/context.rs index ac543ed13c3a8..78f5457727dcb 100644 --- a/datafusion-cli/src/context.rs +++ b/datafusion-cli/src/context.rs @@ -90,7 +90,11 @@ impl BallistaContext { pub struct BallistaContext(); #[cfg(not(feature = "ballista"))] impl BallistaContext { - pub async fn try_new(_host: &str, _port: u16) -> Result { + pub async fn try_new( + _host: &str, + _port: u16, + _with_information_schema: bool, + ) -> Result { Err(DataFusionError::NotImplemented( "Remote execution not supported. Compile with feature 'ballista' to enable" .to_string(), diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs index a059d6eb2a5f3..9015d74c215de 100644 --- a/datafusion-cli/src/main.rs +++ b/datafusion-cli/src/main.rs @@ -109,7 +109,7 @@ pub async fn main() -> Result<()> { let mut enable_with_information_schema = false; if let Some(with_information_schema) = args.with_information_schema { - session_config.with_information_schema(with_information_schema); + session_config = session_config.with_information_schema(with_information_schema); enable_with_information_schema = with_information_schema; } From 8b3191205898dadb37294d2a44ce6e1b93d05d9d Mon Sep 17 00:00:00 2001 From: gaojun2048 Date: Sat, 2 Apr 2022 23:03:27 +0800 Subject: [PATCH 3/4] Update datafusion-cli/src/main.rs Co-authored-by: Andy Grove --- datafusion-cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs index 9015d74c215de..12fd0929484bd 100644 --- a/datafusion-cli/src/main.rs +++ b/datafusion-cli/src/main.rs @@ -83,7 +83,7 @@ struct Args { )] quiet: bool, - #[clap(long, help = "whether enable with_information_schema")] + #[clap(long, help = "Enable with_information_schema")] with_information_schema: Option, } From 7878e26e0efbf3aa2acc9b195abab5bcd9b3b4f2 Mon Sep 17 00:00:00 2001 From: gaojun Date: Wed, 6 Apr 2022 10:03:27 +0800 Subject: [PATCH 4/4] change datafusion-cli to always have access to the information schema --- datafusion-cli/src/context.rs | 28 ++++++---------------------- datafusion-cli/src/main.rs | 13 +------------ 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/datafusion-cli/src/context.rs b/datafusion-cli/src/context.rs index 78f5457727dcb..c96b0e76624a9 100644 --- a/datafusion-cli/src/context.rs +++ b/datafusion-cli/src/context.rs @@ -32,14 +32,8 @@ pub enum Context { impl Context { /// create a new remote context with given host and port - pub async fn new_remote( - host: &str, - port: u16, - with_information_schema: bool, - ) -> Result { - Ok(Context::Remote( - BallistaContext::try_new(host, port, with_information_schema).await?, - )) + pub async fn new_remote(host: &str, port: u16) -> Result { + Ok(Context::Remote(BallistaContext::try_new(host, port).await?)) } /// create a local context using the given config @@ -62,17 +56,11 @@ impl Context { pub struct BallistaContext(ballista::context::BallistaContext); #[cfg(feature = "ballista")] impl BallistaContext { - pub async fn try_new( - host: &str, - port: u16, - with_information_schema: bool, - ) -> Result { + pub async fn try_new(host: &str, port: u16) -> Result { use ballista::context::BallistaContext; use ballista::prelude::BallistaConfig; - let builder = BallistaConfig::builder(); - if with_information_schema { - builder.set("ballista.with_information_schema", "true"); - } + let builder = + BallistaConfig::builder().set("ballista.with_information_schema", "true"); let config = builder .build() .map_err(|e| DataFusionError::Execution(format!("{:?}", e)))?; @@ -90,11 +78,7 @@ impl BallistaContext { pub struct BallistaContext(); #[cfg(not(feature = "ballista"))] impl BallistaContext { - pub async fn try_new( - _host: &str, - _port: u16, - _with_information_schema: bool, - ) -> Result { + pub async fn try_new(_host: &str, _port: u16) -> Result { Err(DataFusionError::NotImplemented( "Remote execution not supported. Compile with feature 'ballista' to enable" .to_string(), diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs index 9015d74c215de..d76fe38e5fb62 100644 --- a/datafusion-cli/src/main.rs +++ b/datafusion-cli/src/main.rs @@ -82,9 +82,6 @@ struct Args { help = "Reduce printing other than the results and work quietly" )] quiet: bool, - - #[clap(long, help = "whether enable with_information_schema")] - with_information_schema: Option, } #[tokio::main] @@ -107,16 +104,8 @@ pub async fn main() -> Result<()> { session_config = session_config.with_batch_size(batch_size); }; - let mut enable_with_information_schema = false; - if let Some(with_information_schema) = args.with_information_schema { - session_config = session_config.with_information_schema(with_information_schema); - enable_with_information_schema = with_information_schema; - } - let mut ctx: Context = match (args.host, args.port) { - (Some(ref h), Some(p)) => { - Context::new_remote(h, p, enable_with_information_schema).await? - } + (Some(ref h), Some(p)) => Context::new_remote(h, p).await?, _ => Context::new_local(&session_config), };