pub fn parse(input: &str) -> Result<Plan, ParseError>
Expand description
Parse a Substrait plan from text format.
This is the main entry point for parsing well-formed plans. Returns a clear error if parsing fails.
The input should be in the Substrait text format, which consists of:
- An optional extensions section starting with “=== Extensions”
- A plan section starting with “=== Plan”
- Indented relation definitions
§Example
use substrait_explain::parse;
let plan_text = r#"
=== Plan
Root[c, d]
Project[$1, 42]
Read[schema.table => a:i64, b:string?]
"#;
// Parse the plan. Builds a complete Substrait plan.
let plan = parse(plan_text).unwrap();
§Errors
Returns a ParseError
if the input cannot be parsed as a valid Substrait plan.
The error includes details about what went wrong and where in the input.
use substrait_explain::parse;
let invalid_plan = r#"
=== Plan
InvalidRelation[invalid syntax]
"#;
match parse(invalid_plan) {
Ok(_) => println!("Valid plan"),
Err(e) => println!("Parse error: {}", e),
}