From c0906f7c22f8b6cc83163c291631beede2702196 Mon Sep 17 00:00:00 2001 From: Aldrin Montana Date: Fri, 25 Oct 2024 09:34:25 -0700 Subject: [PATCH] feat: anchor for non-ordinal reference to PlanRel This adds an "anchor" to `PlanRel` that can be referenced from a `ReferenceRel`. This anchor and reference relationship provides a non-ordinal method for identifying and accessing a "subtree" or sub-graph. This commit leaves in the original `subtree_ordinal` attribute since it seems a (mildly) more performant method for referencing a subtree, but also since it is still relevant in the typical case. The new anchor improves cases where multiple plans are merged and at least one already contains a `ReferenceRel`. It is expected that only one of `subtree_ordinal` or `subtree_reference` will be used, however I don't see a good reason to enforce the use of only one, so I did not group the attributes in a `oneof` constraint. Issue: #725 --- proto/substrait/algebra.proto | 6 +++++- proto/substrait/plan.proto | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/proto/substrait/algebra.proto b/proto/substrait/algebra.proto index 8279ece67..127cd0a93 100644 --- a/proto/substrait/algebra.proto +++ b/proto/substrait/algebra.proto @@ -1633,8 +1633,12 @@ message AggregateFunction { } } -// This rel is used to create references, +// This rel is used to create references, // in case we refer to a RelRoot field names will be ignored message ReferenceRel { + // points to a PlanRel in Plan.relations (ordinal reference) int32 subtree_ordinal = 1; + + // points to a subtree_anchor in PlanRel (for non-ordinal reference) + uint32 subtree_reference = 2; } diff --git a/proto/substrait/plan.proto b/proto/substrait/plan.proto index e5657fb8f..768392f55 100644 --- a/proto/substrait/plan.proto +++ b/proto/substrait/plan.proto @@ -19,6 +19,9 @@ message PlanRel { // The root of a relation tree RelRoot root = 2; } + + // provides a non-ordinal anchor for ReferenceRel + uint32 subtree_anchor = 3; } // Describe a set of operations to complete.