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 13:12:26 UTC

[GitHub] [arrow-datafusion] andygrove opened a new pull request, #2284: WIP: Introduce new TableSource trait in expr crate

andygrove opened a new pull request, #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes https://github.com/apache/arrow-datafusion/issues/2247
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   We want to remove the dependency from `TableScan` to `ExecutionPlan` so that we can move the `LogicalPlan` into the `expr` crate.
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   - New `TableSource` trait in `expr` crate that is referenced from `TableScan`
   - New `DefaultTableSource` struct in core crate that wraps `TableProvider`
   - Shim methods
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   Yes, at API level
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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


[GitHub] [arrow-datafusion] andygrove merged pull request #2284: Remove dependency from `LogicalPlan::TableScan` to `ExecutionPlan`

Posted by GitBox <gi...@apache.org>.
andygrove merged PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284


-- 
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


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

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284#issuecomment-1104520602

   Thanks for the review @alamb. I pushed an update with more documentation. Let me know if I missed anything and I can address in one of the following refactor PRs.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284#issuecomment-1104417566

   The last comment from @Jimexist during "the great split of datafusion" was is https://github.com/apache/arrow-datafusion/pull/1762#discussion_r802563462 --  I think this PR will help
   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284#issuecomment-1103927941

   @matthewmturner @alamb I aborted the large refactor and found a simpler and more practical approach. Let me know what you think.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2284:
URL: https://github.com/apache/arrow-datafusion/pull/2284#issuecomment-1104067667

   I plan to review this later today


-- 
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