You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/20 21:20:57 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2284: Remove dependency from `LogicalPlan::TableScan` to `ExecutionPlan`

alamb commented on code in PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284#discussion_r854563327


##########
datafusion/core/src/logical_plan/plan.rs:
##########
@@ -125,13 +127,71 @@ pub struct Window {
     pub schema: DFSchemaRef,
 }
 
+/// DataFusion default table source, wrapping TableProvider
+pub struct DefaultTableSource {
+    /// table provider
+    pub table_provider: Arc<dyn TableProvider>,
+}
+
+impl DefaultTableSource {
+    /// Create a new DefaultTableSource to wrap a TableProvider
+    pub fn new(table_provider: Arc<dyn TableProvider>) -> Self {
+        Self { table_provider }
+    }
+}
+
+impl TableSource for DefaultTableSource {
+    /// Returns the table source as [`Any`](std::any::Any) so that it can be
+    /// downcast to a specific implementation.
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    /// Get a reference to the schema for this table
+    fn schema(&self) -> SchemaRef {
+        self.table_provider.schema()
+    }
+
+    /// Tests whether the table provider can make use of a filter expression
+    /// to optimise data retrieval.
+    fn supports_filter_pushdown(
+        &self,
+        filter: &Expr,
+    ) -> datafusion_common::Result<TableProviderFilterPushDown> {
+        self.table_provider.supports_filter_pushdown(filter)
+    }
+}
+
+/// Wrap TableProvider in TableSource
+pub fn provider_as_source(
+    table_provider: Arc<dyn TableProvider>,
+) -> Arc<dyn TableSource> {
+    Arc::new(DefaultTableSource::new(table_provider))
+}
+
+/// Extract TableProvider from TableSource
+pub fn source_as_provider(

Review Comment:
   Maybe it is worth a comment on `TableSource` that it is not intended, initially, to be extended outside of DataFusion.



##########
datafusion/expr/src/table_source.rs:
##########
@@ -0,0 +1,72 @@
+// 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.
+
+use crate::Expr;
+use arrow::datatypes::SchemaRef;
+use std::any::Any;
+
+///! Table source
+
+/// Indicates whether and how a filter expression can be handled by a
+/// TableProvider for table scans.
+#[derive(Debug, Clone, PartialEq)]
+pub enum TableProviderFilterPushDown {
+    /// The expression cannot be used by the provider.
+    Unsupported,
+    /// The expression can be used to help minimise the data retrieved,
+    /// but the provider cannot guarantee that all returned tuples
+    /// satisfy the filter. The Filter plan node containing this expression
+    /// will be preserved.
+    Inexact,
+    /// The provider guarantees that all returned data satisfies this
+    /// filter expression. The Filter plan node containing this expression
+    /// will be removed.
+    Exact,
+}
+
+/// Indicates the type of this table for metadata/catalog purposes.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum TableType {
+    /// An ordinary physical table.
+    Base,
+    /// A non-materialised table that itself uses a query internally to provide data.
+    View,
+    /// A transient table.
+    Temporary,
+}
+
+/// TableSource

Review Comment:
   It is probably worth some comments here about the rationale for this structure existing -- namely so LogicalPlan doesn't directly rely on physical plans



##########
datafusion/core/src/logical_plan/plan.rs:
##########
@@ -125,13 +127,71 @@ pub struct Window {
     pub schema: DFSchemaRef,
 }
 
+/// DataFusion default table source, wrapping TableProvider

Review Comment:
   ```suggestion
   /// DataFusion default table source, wrapping TableProvider
   ///
   /// This structure adapts a `TableProvider` (physical plan trait) to the `TableSource` 
   /// (logical plan trait)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org