Skip to content

Commit 820021b

Browse files
committed
[datafusion-cli] support for flight tables
1 parent 4fe546d commit 820021b

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

datafusion-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ datafusion = { path = "../datafusion/core", version = "41.0.0", features = [
4444
"regex_expressions",
4545
"unicode_expressions",
4646
"compression",
47+
"flight",
4748
] }
4849
dirs = "4.0.0"
4950
env_logger = "0.9"

datafusion-cli/src/exec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use datafusion::sql::sqlparser;
4646
use rustyline::error::ReadlineError;
4747
use rustyline::Editor;
4848
use tokio::signal;
49+
use datafusion::datasource::flight::config::FlightOptions;
4950

5051
/// run and execute SQL statements and commands, against a context with the given print options
5152
pub async fn exec_from_commands(
@@ -383,6 +384,8 @@ pub(crate) async fn register_object_store_and_config_extensions(
383384
let mut table_options = ctx.session_state().default_table_options().clone();
384385
if let Some(format) = format {
385386
table_options.set_config_format(format);
387+
} else {
388+
table_options.extensions.insert(FlightOptions::default())
386389
}
387390
table_options.alter_with_string_hash_map(options)?;
388391

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Only meant for datafusion-cli to accept the `flight` namespace
19+
20+
use datafusion_common::config::{ConfigEntry, ConfigExtension, ExtensionOptions};
21+
use std::any::Any;
22+
use std::collections::HashMap;
23+
24+
/// Collects the config entries
25+
#[derive(Default, Debug, Clone)]
26+
pub struct FlightOptions {
27+
inner: HashMap<String, String>,
28+
}
29+
30+
impl ConfigExtension for FlightOptions {
31+
const PREFIX: &'static str = "flight";
32+
}
33+
34+
impl ExtensionOptions for FlightOptions {
35+
fn as_any(&self) -> &dyn Any {
36+
self
37+
}
38+
39+
fn as_any_mut(&mut self) -> &mut dyn Any {
40+
self
41+
}
42+
43+
fn cloned(&self) -> Box<dyn ExtensionOptions> {
44+
Box::new(self.clone())
45+
}
46+
47+
fn set(&mut self, key: &str, value: &str) -> datafusion_common::Result<()> {
48+
self.inner.insert(key.into(), value.into());
49+
Ok(())
50+
}
51+
52+
fn entries(&self) -> Vec<ConfigEntry> {
53+
self.inner
54+
.iter()
55+
.map(|(key, value)| ConfigEntry {
56+
key: key.to_owned(),
57+
value: Some(value.to_owned()).filter(|s| !s.is_empty()),
58+
description: "",
59+
})
60+
.collect()
61+
}
62+
}

datafusion/core/src/datasource/flight/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use datafusion_physical_plan::{ExecutionMode, ExecutionPlan, PlanProperties};
3838

3939
use crate::datasource::physical_plan::FlightExec;
4040

41+
pub mod config;
4142
pub mod sql;
4243

4344
/// Generic Arrow Flight data source. Requires a [FlightDriver] that allows implementors

0 commit comments

Comments
 (0)