-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Recursive CTEs: Stage 2 - add support for sql -> logical plan generation #8839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alamb
merged 11 commits into
apache:main
from
matthewgapp:matt/feat/recursive-ctes/parser
Jan 19, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
162e740
add config flag for recursive ctes
matthewgapp cbe79e5
restore testing pin
matthewgapp 6ef0ff2
add sql -> logical plan support
matthewgapp 8d38c92
wip: remove uncessary with qualifier method
matthewgapp 57cf8b4
Merge remote-tracking branch 'apache/main' into matt/feat/recursive-c…
alamb 675a6df
Add comments to `RecursiveQuery`
alamb 85c2764
Update datfusion-cli Cargo.lock
alamb 63445d8
Fix clippy
alamb 129d41a
better errors and comments
matthewgapp cd95b79
add doc comment with rationale for create_cte_worktable method
matthewgapp ead6b30
wip: tweak
matthewgapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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. | ||
|
||
//! CteWorkTable implementation used for recursive queries | ||
|
||
use std::any::Any; | ||
use std::sync::Arc; | ||
|
||
use arrow::datatypes::SchemaRef; | ||
use async_trait::async_trait; | ||
use datafusion_common::not_impl_err; | ||
|
||
use crate::{ | ||
error::Result, | ||
logical_expr::{Expr, LogicalPlan, TableProviderFilterPushDown}, | ||
physical_plan::ExecutionPlan, | ||
}; | ||
|
||
use datafusion_common::DataFusionError; | ||
|
||
use crate::datasource::{TableProvider, TableType}; | ||
use crate::execution::context::SessionState; | ||
|
||
/// The temporary working table where the previous iteration of a recursive query is stored | ||
/// Naming is based on PostgreSQL's implementation. | ||
/// See here for more details: www.postgresql.org/docs/11/queries-with.html#id-1.5.6.12.5.4 | ||
pub struct CteWorkTable { | ||
/// The name of the CTE work table | ||
// WIP, see https://github.com/apache/arrow-datafusion/issues/462 | ||
#[allow(dead_code)] | ||
name: String, | ||
/// This schema must be shared across both the static and recursive terms of a recursive query | ||
table_schema: SchemaRef, | ||
} | ||
|
||
impl CteWorkTable { | ||
/// construct a new CteWorkTable with the given name and schema | ||
/// This schema must match the schema of the recursive term of the query | ||
/// Since the scan method will contain an physical plan that assumes this schema | ||
pub fn new(name: &str, table_schema: SchemaRef) -> Self { | ||
Self { | ||
name: name.to_owned(), | ||
table_schema, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl TableProvider for CteWorkTable { | ||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
fn get_logical_plan(&self) -> Option<&LogicalPlan> { | ||
None | ||
} | ||
|
||
fn schema(&self) -> SchemaRef { | ||
self.table_schema.clone() | ||
} | ||
|
||
fn table_type(&self) -> TableType { | ||
TableType::Temporary | ||
} | ||
|
||
async fn scan( | ||
&self, | ||
_state: &SessionState, | ||
_projection: Option<&Vec<usize>>, | ||
_filters: &[Expr], | ||
_limit: Option<usize>, | ||
) -> Result<Arc<dyn ExecutionPlan>> { | ||
not_impl_err!("scan not implemented for CteWorkTable yet") | ||
} | ||
|
||
fn supports_filter_pushdown( | ||
&self, | ||
_filter: &Expr, | ||
) -> Result<TableProviderFilterPushDown> { | ||
// TODO: should we support filter pushdown? | ||
Ok(TableProviderFilterPushDown::Unsupported) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.