alamb opened a new pull request, #12595:
URL: https://github.com/apache/datafusion/pull/12595

   Draft as it builds on https://github.com/apache/datafusion/pull/12590
   
   ## Which issue does this PR close?
   
   Part of https://github.com/apache/datafusion/issues/12446
   
   
   ## Rationale for this change
   
   
   Today when the SanityChecker fails it is not always clear why and dumps out 
a message like thisL
   > Error during planning: Plan: ["SortPreservingMergeExec: [d@4 ASC NULLS 
LAST,c@1 ASC NULLS LAST,a@2 ASC NULLS LAST,a0@3 ASC NULLS LAST,b@0 ASC NULLS 
LAST], fetch=2", "  UnionExec", "    SortExec: TopK(fetch=2), expr=[d@4 ASC 
NULLS LAST,c@1 ASC NULLS LAST,a@2 ASC NULLS LAST,b@0 ASC NULLS LAST], 
preserve_partitioning=[false]", "      ProjectionExec: expr=[b@1 as b, c@2 as 
c, a@0 as a, NULL as a0, d@3 as d]", "        CsvExec: file_groups={1 group: 
[[Users/andrewlamb/Software/datafusion2/datafusion/core/tests/data/window_2.csv]]},
 projection=[a, b, c, d], output_ordering=[c@2 ASC NULLS LAST], 
has_header=true", "    SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST,c@1 
ASC NULLS LAST,a0@3 ASC NULLS LAST,b@0 ASC NULLS LAST], 
preserve_partitioning=[false]", "      ProjectionExec: expr=[b@1 as b, c@2 as 
c, NULL as a, a0@0 as a0, d@3 as d]", "        CsvExec: file_groups={1 group: 
[[Users/andrewlamb/Software/datafusion2/datafusion/core/tests/data/window_2.csv]]},
 projection=[a0, b, c, d]
 , output_ordering=[c@2 ASC NULLS LAST], has_header=true"] does not satisfy 
order requirements: [PhysicalSortRequirement { expr: Column { name: "d", index: 
4 }, options: Some(SortOptions { descending: false, nulls_first: false }) }, 
PhysicalSortRequirement { expr: Column { name: "c", index: 1 }, options: 
Some(SortOptions { descending: false, nulls_first: false }) }, 
PhysicalSortRequirement { expr: Column { name: "a", index: 2 }, options: 
Some(SortOptions { descending: false, nulls_first: false }) }, 
PhysicalSortRequirement { expr: Column { name: "a0", index: 3 }, options: 
Some(SortOptions { descending: false, nulls_first: false }) }, 
PhysicalSortRequirement { expr: Column { name: "b", index: 0 }, options: 
Some(SortOptions { descending: false, nulls_first: false }) }]. Child-0 order: 
OrderingEquivalenceClass { orderings: [[PhysicalSortExpr { expr: Column { name: 
"d", index: 4 }, options: SortOptions { descending: false, nulls_first: false } 
}, PhysicalSortExpr { expr: Column { name: "
 c", index: 1 }, options: SortOptions { descending: false, nulls_first: false } 
}]] }
   
   It would be nice to at least have the actual and required ordering dumped 
out in readable form
   
   ## What changes are included in this PR?
   
   
   Improve the display of the actual and required ordering in the error message
   Here is an example of what the output looks liek now:
   
   > Error during planning: Plan: ["SortPreservingMergeExec: [c@0 ASC NULLS 
LAST,a@1 ASC NULLS LAST,a0@2 ASC NULLS LAST,b@3 ASC NULLS LAST], fetch=2", "  
UnionExec", "    SortExec: TopK(fetch=2), expr=[c@0 ASC NULLS LAST,a@1 ASC 
NULLS LAST,b@3 ASC NULLS LAST], preserve_partitioning=[false]", "      
ProjectionExec: expr=[c@2 as c, a@0 as a, NULL as a0, b@1 as b]", "        
MemoryExec: partitions=1, partition_sizes=[1]", "    SortExec: TopK(fetch=2), 
expr=[c@0 ASC NULLS LAST,a0@2 ASC NULLS LAST,b@3 ASC NULLS LAST], 
preserve_partitioning=[false]", "      ProjectionExec: expr=[c@2 as c, NULL as 
a, a0@0 as a0, b@1 as b]", "        MemoryExec: partitions=1, 
partition_sizes=[1]"] does not satisfy order requirements: [c@0 ASC NULLS LAST, 
a@1 ASC NULLS LAST, a0@2 ASC NULLS LAST, b@3 ASC NULLS LAST]. Child-0 order: 
[[c@0 ASC NULLS LAST]]
   
   Specifically I think the part is now useful:
   
   > does not satisfy order requirements: [c@0 ASC NULLS LAST, a@1 ASC NULLS 
LAST, a0@2 ASC NULLS LAST, b@3 ASC NULLS LAST]. Child-0 order: [[c@0 ASC NULLS 
LAST]]
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


-- 
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

Reply via email to