[Spark-4512] [SQL] Unresolved Attribute Exception in Sort By

It will cause exception while do query like:
SELECT key+key FROM src sort by value;

This fix is inspired by #3363 , hope it goes in after #3363 merged. And I've removed the `logical.SortPartitions` and added a new attribute `global` for `logical.Sort`, the reason we do that is for sharing `ResolveSortReferences` for both `ORDER BY` and `SORT BY`.