[SPARK-13630][SQL] Adds optimizer rule collapsesorts to collapse adja… #11480
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
What changes were proposed in this pull request?
This patch does the following:
I) Adds a new optimizer rule collapsesorts that does the following if global is same for the adjacent sorts.
a) Collapse adjacent sorts and keep the last sort
b) Collapse adjacent sorts if there is a project or a limit or a filter in between and keep the last sort.
II) A new test suite CollapseSortsSuite is added with tests.
Also note, one of the _testcase (test("collapsesorts: test collapsesorts in sort <- limit <- sort scenario") ) _does not compare with expected plan because of the unapply in Limit will actually remove the LocalLimit from the plan. Hence the test just checks that the collapsesorts rule was exercised by checking for the number of Sort in the plan.
How was this patch tested?
A)
Following test suites were run and the lint checking was done. No new test failures:
build/sbt -Phive hive/test
build/sbt sql/test
build/sbt catalyst/test
dev/lint-scala
B) A new test suite CollapseSortsSuite is added with new tests to exercise the collapsesorts rule.