Veeupup commented on code in PR #8306: URL: https://github.com/apache/arrow-datafusion/pull/8306#discussion_r1403489719
########## datafusion/core/src/datasource/function.rs: ########## @@ -0,0 +1,60 @@ +// 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. + +//! A table that uses a function to generate data + +use std::sync::Arc; + +use super::{streaming::StreamingTable, TableProvider}; +use arrow::datatypes::SchemaRef; +use datafusion_common::Result; +use datafusion_physical_plan::streaming::PartitionStream; + +/// Table Function implementation +pub type TableFunctionImplementation = Arc< + dyn Fn(&[String]) -> Result<(SchemaRef, Vec<Arc<dyn PartitionStream>>)> + Send + Sync, +>; + +/// A table that uses a function to generate data +pub struct TableFunction { + /// Name of the table function + name: String, + /// Function implementation + fun: TableFunctionImplementation, +} + +impl TableFunction { + /// Create a new table function + pub fn new(name: String, fun: TableFunctionImplementation) -> Self { + Self { name, fun } + } + + /// Get the name of the table function + pub fn name(&self) -> String { + self.name.clone() + } + + /// Get the function implementation and generate a table + pub fn create_table_provider( + &self, + args: &[String], Review Comment: Love this idea too! I'll try to figure out iff we can find a way to evaluate `Expr` correctly! ########## datafusion/core/src/datasource/function.rs: ########## @@ -0,0 +1,60 @@ +// 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. + +//! A table that uses a function to generate data + +use std::sync::Arc; + +use super::{streaming::StreamingTable, TableProvider}; +use arrow::datatypes::SchemaRef; +use datafusion_common::Result; +use datafusion_physical_plan::streaming::PartitionStream; + +/// Table Function implementation +pub type TableFunctionImplementation = Arc< + dyn Fn(&[String]) -> Result<(SchemaRef, Vec<Arc<dyn PartitionStream>>)> + Send + Sync, +>; + +/// A table that uses a function to generate data +pub struct TableFunction { + /// Name of the table function + name: String, + /// Function implementation + fun: TableFunctionImplementation, +} + +impl TableFunction { + /// Create a new table function + pub fn new(name: String, fun: TableFunctionImplementation) -> Self { + Self { name, fun } + } + + /// Get the name of the table function + pub fn name(&self) -> String { + self.name.clone() + } + + /// Get the function implementation and generate a table + pub fn create_table_provider( + &self, + args: &[String], Review Comment: Love this idea too! I'll try to figure out if we can find a way to evaluate `Expr` correctly! -- 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]
