presto icon indicating copy to clipboard operation
presto copied to clipboard

Materialized view automatic rewrite does not correctly handle ORDER BY of aliased columns

Open Sullivan-Patrick opened this issue 2 years ago • 2 comments

When writing a query that should be rewritten by a materialized view, using an alias on a column and then ordering by that column makes the rewrite fail due to an IllegalStateException:Sort key %s is not present in materialized view select fields.

To recreate:

  • Create materialized view
  • Create a query which can be rewritten by a materialized view, with an alias over a field
  • Order by the aliased field

Code pointer: https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/sql/analyzer/MaterializedViewQueryOptimizer.java#L647

Sullivan-Patrick avatar Jul 11 '22 03:07 Sullivan-Patrick

Can you please assign it to me , I will work on this

maheshsv avatar Aug 10 '22 09:08 maheshsv

@maheshsv Thanks for looking into this! Feel free to reach out if you're stuck.

Sullivan-Patrick avatar Aug 10 '22 15:08 Sullivan-Patrick