y-f-u opened a new pull request, #11527: URL: https://github.com/apache/datafusion/pull/11527
## Which issue does this PR close? This PR addresses two issues: - missing order/limit/distinct on derived table Before the fix, query like `select a from (select a, b from table order by b desc) tmp order by a` will only keep the `order by b desc` at a wrong nesting level after unparsing. - order by columns not on select Before the fix, query like `select a from table order by b` will be unparsed into `select table.a from (select table.a, table.b from table) order by table.b` which is invalid as the derived table misses alias. ## Rationale for this change To prevent unparser generating invalid sql for above two common scenarios ## What changes are included in this PR? - relation derive can happen for projection, limit, order, distinct as they can be top-level logical plan node. - rewrite the logicalplan when it has a pattern which parsed from sort columns are not in select. See code comment for more details ## Are these changes tested? Yes ## Are there any user-facing changes? No -- 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