While reviewing the PR: https://github.com/apache/datafusion/pull/17449 I think we can add a new optimizer rule to remove empty input for the union.