findepi commented on code in PR #13651: URL: https://github.com/apache/datafusion/pull/13651#discussion_r1871324921
########## datafusion/optimizer/src/optimizer.rs: ########## @@ -384,9 +395,15 @@ impl Optimizer { // rule handles recursion itself None => optimize_plan_node(new_plan, rule.as_ref(), config), } - // verify the rule didn't change the schema .and_then(|tnr| { - assert_schema_is_the_same(rule.name(), &starting_schema, &tnr.data)?; + // verify after each optimizer pass. + check_plan(rule.name(), &tnr.data, starting_schema).map_err(|e| { Review Comment: Nice! ########## datafusion/optimizer/src/optimizer.rs: ########## @@ -476,6 +520,38 @@ pub(crate) fn assert_schema_is_the_same( } } +/// Returns an error if plan, and subplans, do not have unique fields. +/// +/// This invariant is subject to change. +/// refer: <https://github.com/apache/datafusion/issues/13525#issuecomment-2494046463> +fn assert_unique_field_names(plan: &LogicalPlan) -> Result<()> { + plan.schema().check_names()?; Review Comment: Is `check_names` also called whenever creating new DFSchema? ########## datafusion/optimizer/src/optimizer.rs: ########## @@ -476,6 +520,38 @@ pub(crate) fn assert_schema_is_the_same( } } +/// Returns an error if plan, and subplans, do not have unique fields. +/// +/// This invariant is subject to change. +/// refer: <https://github.com/apache/datafusion/issues/13525#issuecomment-2494046463> +fn assert_unique_field_names(plan: &LogicalPlan) -> Result<()> { + plan.schema().check_names()?; + + plan.apply_with_subqueries(|plan: &LogicalPlan| { + plan.schema().check_names()?; + Ok(TreeNodeRecursion::Continue) + }) + .map(|_| ()) +} + +/// Returns an error if any union nodes are invalid. +#[allow(dead_code)] Review Comment: please remove the suppression -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org