|
| 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 | +} |
0 commit comments