Skip to content

Commit cd69e37

Browse files
leoyvensjonahgao
andauthored
support recursive CTEs logical plans in datafusion-proto (#13314)
* support LogicaPlan::RecursiveQuery in datafusion-proto * fixed and failing test roundtrip_recursive_query * fix rebase artifact * add node for CteWorkTableScan in datafusion-proto * Use Arc::clone --------- Co-authored-by: jonahgao <[email protected]>
1 parent cb7ec85 commit cd69e37

File tree

6 files changed

+434
-9
lines changed

6 files changed

+434
-9
lines changed

datafusion/core/src/datasource/cte_worktable.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ use crate::datasource::{TableProvider, TableType};
3939
#[derive(Debug)]
4040
pub struct CteWorkTable {
4141
/// The name of the CTE work table
42-
// WIP, see https://github.com/apache/datafusion/issues/462
43-
#[allow(dead_code)]
4442
name: String,
4543
/// This schema must be shared across both the static and recursive terms of a recursive query
4644
table_schema: SchemaRef,
@@ -56,6 +54,16 @@ impl CteWorkTable {
5654
table_schema,
5755
}
5856
}
57+
58+
/// The user-provided name of the CTE
59+
pub fn name(&self) -> &str {
60+
&self.name
61+
}
62+
63+
/// The schema of the recursive term of the query
64+
pub fn schema(&self) -> SchemaRef {
65+
Arc::clone(&self.table_schema)
66+
}
5967
}
6068

6169
#[async_trait]

datafusion/proto/proto/datafusion.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ message LogicalPlanNode {
5959
DistinctOnNode distinct_on = 28;
6060
CopyToNode copy_to = 29;
6161
UnnestNode unnest = 30;
62+
RecursiveQueryNode recursive_query = 31;
63+
CteWorkTableScanNode cte_work_table_scan = 32;
6264
}
6365
}
6466

@@ -1249,3 +1251,15 @@ message PartitionStats {
12491251
int64 num_bytes = 3;
12501252
repeated datafusion_common.ColumnStats column_stats = 4;
12511253
}
1254+
1255+
message RecursiveQueryNode {
1256+
string name = 1;
1257+
LogicalPlanNode static_term = 2;
1258+
LogicalPlanNode recursive_term = 3;
1259+
bool is_distinct = 4;
1260+
}
1261+
1262+
message CteWorkTableScanNode {
1263+
string name = 1;
1264+
datafusion_common.Schema schema = 2;
1265+
}

datafusion/proto/src/generated/pbjson.rs

Lines changed: 281 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)