kadinrabo commented on code in PR #19179: URL: https://github.com/apache/datafusion/pull/19179#discussion_r2620611806
########## datafusion/substrait/src/logical_plan/consumer/rel/recursive_query_rel.rs: ########## @@ -0,0 +1,64 @@ +// 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::logical_plan::{ + consumer::SubstraitConsumer, recursive::decode_recursive_query_detail, +}; +use datafusion::{ + common::substrait_err, + logical_expr::{LogicalPlan, RecursiveQuery}, +}; +use std::sync::Arc; +use substrait::proto::ExtensionMultiRel; +/// Deserializes Substrait ExtensionMultiRel back into DataFusion RecursiveQuery. +/// +/// RecursiveQuery is encoded as ExtensionMultiRel with exactly two inputs: +/// +/// - `inputs[0]`: static_term +/// - `inputs[1]`: recursive_term +/// +/// The detail field contains the encoded name and is_distinct metadata. +pub async fn from_recursive_query_rel( + consumer: &impl SubstraitConsumer, + rel: &ExtensionMultiRel, +) -> datafusion::common::Result<LogicalPlan> { + // Validate structure + if rel.inputs.len() != 2 { + return substrait_err!( + "RecursiveQuery extension must have exactly 2 inputs, found {}", + rel.inputs.len() + ); + } + + let Some(detail) = &rel.detail else { + return substrait_err!("RecursiveQuery extension missing detail"); + }; + + // Decode metadata + let (name, is_distinct) = decode_recursive_query_detail(&detail.value)?; + + // Convert child plans + let static_term = Arc::new(consumer.consume_rel(&rel.inputs[0]).await?); + let recursive_term = Arc::new(consumer.consume_rel(&rel.inputs[1]).await?); Review Comment: Nice work 🚀 I know we're only getting to this function with `RECURSIVE_QUERY_TYPE_URL`, but I think validating that the recursive term references the work table would be good. Since the Substrait spec doesn't yet have a native recursive relation and ExtensionMultiRel is pretty general purpose for complex operations, a defensive check here would help catch invalid plans. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
