You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by pr...@apache.org on 2016/08/20 01:38:29 UTC

[2/3] hive git commit: HIVE-14503: Remove explicit order by in qfiles for union tests (Prasanth Jayachandran reviewed by Siddharth Seth, Hari)

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_2.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_2.q.out b/ql/src/test/results/clientpositive/spark/union_remove_2.q.out
index 4667e70..755ff3f 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_2.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_2.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -13,7 +14,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -217,11 +219,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_20.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_20.q.out b/ql/src/test/results/clientpositive/spark/union_remove_20.q.out
index b7682a9..bec77a8 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_20.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_20.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select and a file sink
 -- However, the order of the columns in the select list is different. So, union cannot
 -- be removed.
@@ -13,7 +14,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select and a file sink
 -- However, the order of the columns in the select list is different. So, union cannot
 -- be removed.
@@ -200,11 +202,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_21.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_21.q.out b/ql/src/test/results/clientpositive/spark/union_remove_21.q.out
index c9bcf36..f5a1caa 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_21.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_21.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select and a file sink
 -- However, all the columns are not selected. So, union cannot
 -- be removed.
@@ -13,7 +14,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select and a file sink
 -- However, all the columns are not selected. So, union cannot
 -- be removed.
@@ -186,11 +188,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_22.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_22.q.out b/ql/src/test/results/clientpositive/spark/union_remove_22.q.out
index 90caa89..c762002 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_22.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_22.q.out
@@ -347,11 +347,11 @@ POSTHOOK: Output: default@outputtbl1
 POSTHOOK: Lineage: outputtbl1.key EXPRESSION [(inputtbl1)inputtbl1.FieldSchema(name:key, type:string, comment:null), ]
 POSTHOOK: Lineage: outputtbl1.values EXPRESSION [(inputtbl1)inputtbl1.null, ]
 POSTHOOK: Lineage: outputtbl1.values2 EXPRESSION [(inputtbl1)inputtbl1.null, ]
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_23.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_23.q.out b/ql/src/test/results/clientpositive/spark/union_remove_23.q.out
index 3d51af5..b351893 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_23.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_23.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely. One of the sub-queries
@@ -13,7 +14,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely. One of the sub-queries
@@ -253,11 +255,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_24.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_24.q.out b/ql/src/test/results/clientpositive/spark/union_remove_24.q.out
index 94f71ac..c66691e 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_24.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_24.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -11,7 +12,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -196,11 +198,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_25.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_25.q.out b/ql/src/test/results/clientpositive/spark/union_remove_25.q.out
index eb95cad..ba9d4d1 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_25.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_25.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -12,7 +13,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -212,12 +214,12 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 PREHOOK: Input: default@outputtbl1@ds=2004
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 POSTHOOK: Input: default@outputtbl1@ds=2004

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_3.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_3.q.out b/ql/src/test/results/clientpositive/spark/union_remove_3.q.out
index 66675ce..7692443 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_3.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_3.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->remove->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->remove->filesink optimization
 -- Union of 3 subqueries is performed (all of which are map-only queries)
 -- followed by select star and a file sink.
 -- There is no need for any optimization, since the whole query can be processed in
@@ -13,7 +14,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->remove->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->remove->filesink optimization
 -- Union of 3 subqueries is performed (all of which are map-only queries)
 -- followed by select star and a file sink.
 -- There is no need for any optimization, since the whole query can be processed in
@@ -207,11 +209,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_4.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_4.q.out b/ql/src/test/results/clientpositive/spark/union_remove_4.q.out
index 1bf917a..3ab62c8 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_4.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_4.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -12,7 +13,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -240,11 +242,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_5.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_5.q.out b/ql/src/test/results/clientpositive/spark/union_remove_5.q.out
index aabb6c4..9a9caf6 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_5.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_5.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -14,7 +15,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -269,11 +271,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_6.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_6.q.out b/ql/src/test/results/clientpositive/spark/union_remove_6.q.out
index d677d1b..1bdeb09 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_6.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_6.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 subqueries is performed (all of which are mapred queries)
 -- followed by select star and a file sink in 2 output tables.
 -- The optimiaztion does not take affect since it is a multi-table insert.
@@ -9,7 +10,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 subqueries is performed (all of which are mapred queries)
 -- followed by select star and a file sink in 2 output tables.
 -- The optimiaztion does not take affect since it is a multi-table insert.
@@ -191,11 +193,11 @@ POSTHOOK: Lineage: outputtbl1.key EXPRESSION [(inputtbl1)inputtbl1.FieldSchema(n
 POSTHOOK: Lineage: outputtbl1.values EXPRESSION [(inputtbl1)inputtbl1.null, ]
 POSTHOOK: Lineage: outputtbl2.key EXPRESSION [(inputtbl1)inputtbl1.FieldSchema(name:key, type:string, comment:null), ]
 POSTHOOK: Lineage: outputtbl2.values EXPRESSION [(inputtbl1)inputtbl1.null, ]
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
@@ -209,11 +211,11 @@ POSTHOOK: Input: default@outputtbl1
 7	1
 8	2
 8	2
-PREHOOK: query: select * from outputTbl2 order by key, `values`
+PREHOOK: query: select * from outputTbl2
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl2
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl2 order by key, `values`
+POSTHOOK: query: select * from outputTbl2
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl2
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_6_subq.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_6_subq.q.out b/ql/src/test/results/clientpositive/spark/union_remove_6_subq.q.out
index dac8247..10de07d 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_6_subq.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_6_subq.q.out
@@ -203,11 +203,11 @@ POSTHOOK: Lineage: outputtbl1.key EXPRESSION [(inputtbl1)inputtbl1.FieldSchema(n
 POSTHOOK: Lineage: outputtbl1.values EXPRESSION [(inputtbl1)inputtbl1.null, ]
 POSTHOOK: Lineage: outputtbl2.key EXPRESSION [(inputtbl1)inputtbl1.FieldSchema(name:key, type:string, comment:null), ]
 POSTHOOK: Lineage: outputtbl2.values EXPRESSION [(inputtbl1)inputtbl1.null, ]
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
@@ -221,11 +221,11 @@ POSTHOOK: Input: default@outputtbl1
 7	1
 8	2
 8	2
-PREHOOK: query: select * from outputTbl2 order by key, `values`
+PREHOOK: query: select * from outputTbl2
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl2
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl2 order by key, `values`
+POSTHOOK: query: select * from outputTbl2
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl2
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_7.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_7.q.out b/ql/src/test/results/clientpositive/spark/union_remove_7.q.out
index 6af69e0..585b61e 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_7.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_7.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -14,7 +15,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 map-reduce subqueries is performed followed by select star and a file sink
 -- There is no need to write the temporary results of the sub-queries, and then read them 
 -- again to process the union. The union can be removed completely.
@@ -194,11 +196,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_8.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_8.q.out b/ql/src/test/results/clientpositive/spark/union_remove_8.q.out
index f19afad..17079a1 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_8.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_8.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -15,7 +16,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 3 subqueries is performed (exactly one of which requires a map-reduce job)
 -- followed by select star and a file sink.
 -- There is no need to write the temporary results of the sub-queries, and then read them 
@@ -221,11 +223,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_remove_9.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_remove_9.q.out b/ql/src/test/results/clientpositive/spark/union_remove_9.q.out
index 2e2abf9..0b46bd7 100644
--- a/ql/src/test/results/clientpositive/spark/union_remove_9.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_remove_9.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: -- This is to test the union->selectstar->filesink optimization
+PREHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 subqueries is performed (one of which contains a union and is map-only),
 -- and the other one is a map-reduce query followed by select star and a file sink.
 -- There is no need for the outer union.
@@ -14,7 +15,8 @@ create table inputTbl1(key string, val string) stored as textfile
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@inputTbl1
-POSTHOOK: query: -- This is to test the union->selectstar->filesink optimization
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+-- This is to test the union->selectstar->filesink optimization
 -- Union of 2 subqueries is performed (one of which contains a union and is map-only),
 -- and the other one is a map-reduce query followed by select star and a file sink.
 -- There is no need for the outer union.
@@ -277,11 +279,11 @@ Bucket Columns:     	[]
 Sort Columns:       	[]                  	 
 Storage Desc Params:	 	 
 	serialization.format	1                   
-PREHOOK: query: select * from outputTbl1 order by key, `values`
+PREHOOK: query: select * from outputTbl1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####
-POSTHOOK: query: select * from outputTbl1 order by key, `values`
+POSTHOOK: query: select * from outputTbl1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@outputtbl1
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_script.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_script.q.out b/ql/src/test/results/clientpositive/spark/union_script.q.out
index e044f63..44ea01b 100644
--- a/ql/src/test/results/clientpositive/spark/union_script.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_script.q.out
@@ -1,10 +1,12 @@
-PREHOOK: query: select * from (
-  select transform(key) using 'cat' as cola from src)s order by cola
+PREHOOK: query: -- SORT_QUERY_RESULTS
+select * from (
+  select transform(key) using 'cat' as cola from src)s
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
-POSTHOOK: query: select * from (
-  select transform(key) using 'cat' as cola from src)s order by cola
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+select * from (
+  select transform(key) using 'cat' as cola from src)s
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
@@ -511,14 +513,14 @@ POSTHOOK: Input: default@src
 PREHOOK: query: select * from (
   select transform(key) using 'cat' as cola from src
   union all
-  select transform(key) using 'cat' as cola from src) s order by cola
+  select transform(key) using 'cat' as cola from src) s
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
 POSTHOOK: query: select * from (
   select transform(key) using 'cat' as cola from src
   union all
-  select transform(key) using 'cat' as cola from src) s order by cola
+  select transform(key) using 'cat' as cola from src) s
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/spark/union_view.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_view.q.out b/ql/src/test/results/clientpositive/spark/union_view.q.out
index 892cc6f..a5970c0 100644
--- a/ql/src/test/results/clientpositive/spark/union_view.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_view.q.out
@@ -406,8 +406,6 @@ STAGE DEPENDENCIES:
 STAGE PLANS:
   Stage: Stage-1
     Spark
-      Edges:
-        Reducer 2 <- Map 1 (SORT, 1), Map 3 (SORT, 1), Map 4 (SORT, 1)
 #### A masked pattern was here ####
       Vertices:
         Map 1 
@@ -424,15 +422,17 @@ STAGE PLANS:
                       outputColumnNames: _col0, _col1
                       Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE
                       Select Operator
-                        expressions: _col0 (type: string), _col1 (type: string)
-                        outputColumnNames: _col1, _col2
+                        expressions: 86 (type: int), _col0 (type: string), _col1 (type: string)
+                        outputColumnNames: _col0, _col1, _col2
                         Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                        Reduce Output Operator
-                          key expressions: _col2 (type: string)
-                          sort order: +
+                        File Output Operator
+                          compressed: false
                           Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                          value expressions: _col1 (type: string)
-        Map 3 
+                          table:
+                              input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                              output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                              serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+        Map 2 
             Map Operator Tree:
                 TableScan
                   alias: src_union_2
@@ -446,15 +446,17 @@ STAGE PLANS:
                       outputColumnNames: _col0, _col1
                       Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE
                       Select Operator
-                        expressions: _col0 (type: string), _col1 (type: string)
-                        outputColumnNames: _col1, _col2
+                        expressions: 86 (type: int), _col0 (type: string), _col1 (type: string)
+                        outputColumnNames: _col0, _col1, _col2
                         Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                        Reduce Output Operator
-                          key expressions: _col2 (type: string)
-                          sort order: +
+                        File Output Operator
+                          compressed: false
                           Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                          value expressions: _col1 (type: string)
-        Map 4 
+                          table:
+                              input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                              output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                              serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+        Map 3 
             Map Operator Tree:
                 TableScan
                   alias: src_union_3
@@ -468,27 +470,16 @@ STAGE PLANS:
                       outputColumnNames: _col0, _col1
                       Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE
                       Select Operator
-                        expressions: _col0 (type: string), _col1 (type: string)
-                        outputColumnNames: _col1, _col2
+                        expressions: 86 (type: int), _col0 (type: string), _col1 (type: string)
+                        outputColumnNames: _col0, _col1, _col2
                         Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                        Reduce Output Operator
-                          key expressions: _col2 (type: string)
-                          sort order: +
+                        File Output Operator
+                          compressed: false
                           Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                          value expressions: _col1 (type: string)
-        Reducer 2 
-            Reduce Operator Tree:
-              Select Operator
-                expressions: 86 (type: int), VALUE._col0 (type: string), KEY.reducesinkkey0 (type: string)
-                outputColumnNames: _col0, _col1, _col2
-                Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                File Output Operator
-                  compressed: false
-                  Statistics: Num rows: 1250 Data size: 13280 Basic stats: COMPLETE Column stats: NONE
-                  table:
-                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
-                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
-                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+                          table:
+                              input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                              output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                              serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
 
   Stage: Stage-0
     Fetch Operator
@@ -501,9 +492,9 @@ STAGE PLANS:
 86	val_86	2
 86	val_86	3
 86	val_86	3
-86	val_86	1
 86	val_86	2
 86	val_86	2
+86	val_86	1
 86	val_86	3
 86	val_86	3
 STAGE DEPENDENCIES:

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/tez/unionDistinct_1.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/tez/unionDistinct_1.q.out b/ql/src/test/results/clientpositive/tez/unionDistinct_1.q.out
index dd78248..2c8e57f 100644
--- a/ql/src/test/results/clientpositive/tez/unionDistinct_1.q.out
+++ b/ql/src/test/results/clientpositive/tez/unionDistinct_1.q.out
@@ -7174,7 +7174,6 @@ from (
   from src
   UNION DISTINCT 
   select key as key2, value as value2 from src) s
-order by s.key2, s.value2
 PREHOOK: type: QUERY
 POSTHOOK: query: -- union23.q
 
@@ -7185,7 +7184,6 @@ from (
   from src
   UNION DISTINCT 
   select key as key2, value as value2 from src) s
-order by s.key2, s.value2
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -7197,9 +7195,8 @@ STAGE PLANS:
 #### A masked pattern was here ####
       Edges:
         Map 1 <- Union 2 (CONTAINS)
-        Map 5 <- Union 2 (CONTAINS)
+        Map 4 <- Union 2 (CONTAINS)
         Reducer 3 <- Union 2 (SIMPLE_EDGE)
-        Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
 #### A masked pattern was here ####
       Vertices:
         Map 1 
@@ -7228,7 +7225,7 @@ STAGE PLANS:
                           sort order: ++
                           Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
                           Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
-        Map 5 
+        Map 4 
             Map Operator Tree:
                 TableScan
                   alias: src
@@ -7254,16 +7251,6 @@ STAGE PLANS:
                 mode: mergepartial
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string), _col1 (type: string)
-                  sort order: ++
-                  Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
-        Reducer 4 
-            Reduce Operator Tree:
-              Select Operator
-                expressions: KEY.reducesinkkey0 (type: string), KEY.reducesinkkey1 (type: string)
-                outputColumnNames: _col0, _col1
-                Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
                 File Output Operator
                   compressed: false
                   Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
@@ -7286,7 +7273,6 @@ from (
   from src
   UNION DISTINCT 
   select key as key2, value as value2 from src) s
-order by s.key2, s.value2
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
@@ -7296,7 +7282,6 @@ from (
   from src
   UNION DISTINCT 
   select key as key2, value as value2 from src) s
-order by s.key2, s.value2
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
@@ -12823,7 +12808,6 @@ SELECT * FROM
 (SELECT CAST(key AS DOUBLE) AS key FROM t1
 UNION DISTINCT
 SELECT CAST(key AS BIGINT) AS key FROM t2) a
-ORDER BY key
 PREHOOK: type: QUERY
 POSTHOOK: query: -- Test simple union with double
 EXPLAIN
@@ -12831,7 +12815,6 @@ SELECT * FROM
 (SELECT CAST(key AS DOUBLE) AS key FROM t1
 UNION DISTINCT
 SELECT CAST(key AS BIGINT) AS key FROM t2) a
-ORDER BY key
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -12843,9 +12826,8 @@ STAGE PLANS:
 #### A masked pattern was here ####
       Edges:
         Map 1 <- Union 2 (CONTAINS)
-        Map 5 <- Union 2 (CONTAINS)
+        Map 4 <- Union 2 (CONTAINS)
         Reducer 3 <- Union 2 (SIMPLE_EDGE)
-        Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
 #### A masked pattern was here ####
       Vertices:
         Map 1 
@@ -12867,7 +12849,7 @@ STAGE PLANS:
                         sort order: +
                         Map-reduce partition columns: _col0 (type: double)
                         Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-        Map 5 
+        Map 4 
             Map Operator Tree:
                 TableScan
                   alias: t2
@@ -12893,16 +12875,6 @@ STAGE PLANS:
                 mode: mergepartial
                 outputColumnNames: _col0
                 Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: double)
-                  sort order: +
-                  Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
-        Reducer 4 
-            Reduce Operator Tree:
-              Select Operator
-                expressions: KEY.reducesinkkey0 (type: double)
-                outputColumnNames: _col0
-                Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
                 File Output Operator
                   compressed: false
                   Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
@@ -13992,7 +13964,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 POSTHOOK: query: -- When we convert the Join of sub1 and sub0 into a MapJoin,
 -- we can use a single MR job to evaluate this entire query.
@@ -14001,7 +13973,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -14012,12 +13984,11 @@ STAGE PLANS:
     Tez
 #### A masked pattern was here ####
       Edges:
-        Map 1 <- Map 5 (BROADCAST_EDGE), Union 2 (CONTAINS)
-        Map 6 <- Union 7 (CONTAINS)
-        Map 9 <- Union 7 (CONTAINS)
+        Map 1 <- Map 4 (BROADCAST_EDGE), Union 2 (CONTAINS)
+        Map 5 <- Union 6 (CONTAINS)
+        Map 8 <- Union 6 (CONTAINS)
         Reducer 3 <- Union 2 (SIMPLE_EDGE)
-        Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
-        Reducer 8 <- Union 2 (CONTAINS), Union 7 (SIMPLE_EDGE)
+        Reducer 7 <- Union 2 (CONTAINS), Union 6 (SIMPLE_EDGE)
 #### A masked pattern was here ####
       Vertices:
         Map 1 
@@ -14040,7 +14011,7 @@ STAGE PLANS:
                           1 _col0 (type: string)
                         outputColumnNames: _col0, _col1
                         input vertices:
-                          1 Map 5
+                          1 Map 4
                         Statistics: Num rows: 11 Data size: 114 Basic stats: COMPLETE Column stats: NONE
                         HybridGraceHashJoin: true
                         Group By Operator
@@ -14053,7 +14024,7 @@ STAGE PLANS:
                             sort order: ++
                             Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
                             Statistics: Num rows: 21 Data size: 218 Basic stats: COMPLETE Column stats: NONE
-        Map 5 
+        Map 4 
             Map Operator Tree:
                 TableScan
                   alias: src10_2
@@ -14070,7 +14041,7 @@ STAGE PLANS:
                         sort order: +
                         Map-reduce partition columns: _col0 (type: string)
                         Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
-        Map 6 
+        Map 5 
             Map Operator Tree:
                 TableScan
                   alias: src10_3
@@ -14089,7 +14060,7 @@ STAGE PLANS:
                         sort order: ++
                         Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
                         Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
-        Map 9 
+        Map 8 
             Map Operator Tree:
                 TableScan
                   alias: src10_4
@@ -14115,17 +14086,6 @@ STAGE PLANS:
                 mode: mergepartial
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
-                  Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
-        Reducer 4 
-            Reduce Operator Tree:
-              Select Operator
-                expressions: KEY.reducesinkkey0 (type: string), VALUE._col0 (type: string)
-                outputColumnNames: _col0, _col1
-                Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
                 File Output Operator
                   compressed: false
                   Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
@@ -14133,7 +14093,7 @@ STAGE PLANS:
                       input format: org.apache.hadoop.mapred.SequenceFileInputFormat
                       output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
                       serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
-        Reducer 8 
+        Reducer 7 
             Reduce Operator Tree:
               Group By Operator
                 keys: KEY._col0 (type: string), KEY._col1 (type: string)
@@ -14152,8 +14112,8 @@ STAGE PLANS:
                     Statistics: Num rows: 21 Data size: 218 Basic stats: COMPLETE Column stats: NONE
         Union 2 
             Vertex: Union 2
-        Union 7 
-            Vertex: Union 7
+        Union 6 
+            Vertex: Union 6
 
   Stage: Stage-0
     Fetch Operator
@@ -14165,7 +14125,7 @@ PREHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src10_1
 PREHOOK: Input: default@src10_2
@@ -14176,7 +14136,7 @@ POSTHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src10_1
 POSTHOOK: Input: default@src10_2
@@ -14202,7 +14162,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 POSTHOOK: query: -- When we do not convert the Join of sub1 and sub0 into a MapJoin,
 -- we need to use two MR jobs to evaluate this query.
@@ -14213,7 +14173,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -14224,12 +14184,11 @@ STAGE PLANS:
     Tez
 #### A masked pattern was here ####
       Edges:
-        Map 10 <- Union 8 (CONTAINS)
-        Map 7 <- Union 8 (CONTAINS)
-        Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 6 (SIMPLE_EDGE), Union 3 (CONTAINS)
+        Map 6 <- Union 7 (CONTAINS)
+        Map 9 <- Union 7 (CONTAINS)
+        Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 5 (SIMPLE_EDGE), Union 3 (CONTAINS)
         Reducer 4 <- Union 3 (SIMPLE_EDGE)
-        Reducer 5 <- Reducer 4 (SIMPLE_EDGE)
-        Reducer 9 <- Union 3 (CONTAINS), Union 8 (SIMPLE_EDGE)
+        Reducer 8 <- Union 3 (CONTAINS), Union 7 (SIMPLE_EDGE)
 #### A masked pattern was here ####
       Vertices:
         Map 1 
@@ -14250,26 +14209,7 @@ STAGE PLANS:
                         Map-reduce partition columns: _col0 (type: string)
                         Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
                         value expressions: _col1 (type: string)
-        Map 10 
-            Map Operator Tree:
-                TableScan
-                  alias: src10_4
-                  Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
-                  Select Operator
-                    expressions: key (type: string), value (type: string)
-                    outputColumnNames: _col0, _col1
-                    Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
-                    Group By Operator
-                      keys: _col0 (type: string), _col1 (type: string)
-                      mode: hash
-                      outputColumnNames: _col0, _col1
-                      Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
-                      Reduce Output Operator
-                        key expressions: _col0 (type: string), _col1 (type: string)
-                        sort order: ++
-                        Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
-                        Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
-        Map 6 
+        Map 5 
             Map Operator Tree:
                 TableScan
                   alias: src10_2
@@ -14286,7 +14226,7 @@ STAGE PLANS:
                         sort order: +
                         Map-reduce partition columns: _col0 (type: string)
                         Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
-        Map 7 
+        Map 6 
             Map Operator Tree:
                 TableScan
                   alias: src10_3
@@ -14305,6 +14245,25 @@ STAGE PLANS:
                         sort order: ++
                         Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
                         Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
+        Map 9 
+            Map Operator Tree:
+                TableScan
+                  alias: src10_4
+                  Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
+                  Select Operator
+                    expressions: key (type: string), value (type: string)
+                    outputColumnNames: _col0, _col1
+                    Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
+                    Group By Operator
+                      keys: _col0 (type: string), _col1 (type: string)
+                      mode: hash
+                      outputColumnNames: _col0, _col1
+                      Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
+                      Reduce Output Operator
+                        key expressions: _col0 (type: string), _col1 (type: string)
+                        sort order: ++
+                        Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                        Statistics: Num rows: 20 Data size: 208 Basic stats: COMPLETE Column stats: NONE
         Reducer 2 
             Reduce Operator Tree:
               Merge Join Operator
@@ -14332,17 +14291,6 @@ STAGE PLANS:
                 mode: mergepartial
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
-                  Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
-        Reducer 5 
-            Reduce Operator Tree:
-              Select Operator
-                expressions: KEY.reducesinkkey0 (type: string), VALUE._col0 (type: string)
-                outputColumnNames: _col0, _col1
-                Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
                 File Output Operator
                   compressed: false
                   Statistics: Num rows: 10 Data size: 103 Basic stats: COMPLETE Column stats: NONE
@@ -14350,7 +14298,7 @@ STAGE PLANS:
                       input format: org.apache.hadoop.mapred.SequenceFileInputFormat
                       output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
                       serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
-        Reducer 9 
+        Reducer 8 
             Reduce Operator Tree:
               Group By Operator
                 keys: KEY._col0 (type: string), KEY._col1 (type: string)
@@ -14369,8 +14317,8 @@ STAGE PLANS:
                     Statistics: Num rows: 21 Data size: 218 Basic stats: COMPLETE Column stats: NONE
         Union 3 
             Vertex: Union 3
-        Union 8 
-            Vertex: Union 8
+        Union 7 
+            Vertex: Union 7
 
   Stage: Stage-0
     Fetch Operator
@@ -14382,7 +14330,7 @@ PREHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src10_1
 PREHOOK: Input: default@src10_2
@@ -14393,7 +14341,7 @@ POSTHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION DISTINCT
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION DISTINCT SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src10_1
 POSTHOOK: Input: default@src10_2

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/tez/union_type_chk.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/tez/union_type_chk.q.out b/ql/src/test/results/clientpositive/tez/union_type_chk.q.out
index 12f060b..1eb0182 100644
--- a/ql/src/test/results/clientpositive/tez/union_type_chk.q.out
+++ b/ql/src/test/results/clientpositive/tez/union_type_chk.q.out
@@ -1,28 +1,30 @@
-PREHOOK: query: select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y
+PREHOOK: query: -- SORT_QUERY_RESULTS
+select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
-POSTHOOK: query: select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
+0.4999999900000002
+0.4999999900000002
 4.999999900000002E-9
 4.999999900000002E-9
 4.999999900000002E-9
 4.999999900000002E-9
-0.4999999900000002
-0.4999999900000002
-PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y
+PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
-POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y
+POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
-NULL
-NULL
 0.25
 0.25
 0.25
 0.25
+NULL
+NULL

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/union32.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/union32.q.out b/ql/src/test/results/clientpositive/union32.q.out
index f61a313..136a1c3 100644
--- a/ql/src/test/results/clientpositive/union32.q.out
+++ b/ql/src/test/results/clientpositive/union32.q.out
@@ -38,7 +38,6 @@ SELECT * FROM
 (SELECT CAST(key AS DOUBLE) AS key FROM t1
 UNION ALL
 SELECT CAST(key AS BIGINT) AS key FROM t2) a
-ORDER BY key
 PREHOOK: type: QUERY
 POSTHOOK: query: -- Test simple union with double
 EXPLAIN
@@ -46,7 +45,6 @@ SELECT * FROM
 (SELECT CAST(key AS DOUBLE) AS key FROM t1
 UNION ALL
 SELECT CAST(key AS BIGINT) AS key FROM t2) a
-ORDER BY key
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -65,10 +63,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: double)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
           TableScan
             alias: t2
             Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
@@ -78,22 +79,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 70 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: double)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-      Reduce Operator Tree:
-        Select Operator
-          expressions: KEY.reducesinkkey0 (type: double)
-          outputColumnNames: _col0
-          Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-          File Output Operator
-            compressed: false
-            Statistics: Num rows: 20 Data size: 140 Basic stats: COMPLETE Column stats: NONE
-            table:
-                input format: org.apache.hadoop.mapred.SequenceFileInputFormat
-                output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
-                serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
 
   Stage: Stage-0
     Fetch Operator

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/union34.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/union34.q.out b/ql/src/test/results/clientpositive/union34.q.out
index 06f75e7..8d7846c 100644
--- a/ql/src/test/results/clientpositive/union34.q.out
+++ b/ql/src/test/results/clientpositive/union34.q.out
@@ -1,8 +1,10 @@
-PREHOOK: query: create table src10_1 (key string, value string)
+PREHOOK: query: -- SORT_QUERY_RESULTS
+create table src10_1 (key string, value string)
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@src10_1
-POSTHOOK: query: create table src10_1 (key string, value string)
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+create table src10_1 (key string, value string)
 POSTHOOK: type: CREATETABLE
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@src10_1
@@ -67,7 +69,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 POSTHOOK: query: -- When we convert the Join of sub1 and sub0 into a MapJoin,
 -- we can use a single MR job to evaluate this entire query.
@@ -76,7 +78,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-7 is a root stage
@@ -119,11 +121,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
           TableScan
             alias: src10_4
             Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
@@ -133,11 +137,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
           TableScan
             alias: src10_2
             Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
@@ -158,25 +164,15 @@ STAGE PLANS:
                   Statistics: Num rows: 11 Data size: 114 Basic stats: COMPLETE Column stats: NONE
                   Union
                     Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                    Reduce Output Operator
-                      key expressions: _col0 (type: string)
-                      sort order: +
+                    File Output Operator
+                      compressed: false
                       Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col1 (type: string)
+                      table:
+                          input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                          output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                          serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
       Local Work:
         Map Reduce Local Work
-      Reduce Operator Tree:
-        Select Operator
-          expressions: KEY.reducesinkkey0 (type: string), VALUE._col0 (type: string)
-          outputColumnNames: _col0, _col1
-          Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-          File Output Operator
-            compressed: false
-            Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-            table:
-                input format: org.apache.hadoop.mapred.SequenceFileInputFormat
-                output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
-                serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
 
   Stage: Stage-0
     Fetch Operator
@@ -188,7 +184,7 @@ PREHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src10_1
 PREHOOK: Input: default@src10_2
@@ -199,7 +195,7 @@ POSTHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src10_1
 POSTHOOK: Input: default@src10_2
@@ -245,7 +241,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 POSTHOOK: query: -- When we do not convert the Join of sub1 and sub0 into a MapJoin,
 -- we need to use two MR jobs to evaluate this query.
@@ -256,7 +252,7 @@ SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 STAGE DEPENDENCIES:
   Stage-1 is a root stage
@@ -320,11 +316,13 @@ STAGE PLANS:
           TableScan
             Union
               Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-              Reduce Output Operator
-                key expressions: _col0 (type: string)
-                sort order: +
+              File Output Operator
+                compressed: false
                 Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                value expressions: _col1 (type: string)
+                table:
+                    input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                    output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                    serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
           TableScan
             alias: src10_3
             Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
@@ -334,11 +332,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
           TableScan
             alias: src10_4
             Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
@@ -348,23 +348,13 @@ STAGE PLANS:
               Statistics: Num rows: 10 Data size: 104 Basic stats: COMPLETE Column stats: NONE
               Union
                 Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                Reduce Output Operator
-                  key expressions: _col0 (type: string)
-                  sort order: +
+                File Output Operator
+                  compressed: false
                   Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col1 (type: string)
-      Reduce Operator Tree:
-        Select Operator
-          expressions: KEY.reducesinkkey0 (type: string), VALUE._col0 (type: string)
-          outputColumnNames: _col0, _col1
-          Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-          File Output Operator
-            compressed: false
-            Statistics: Num rows: 31 Data size: 322 Basic stats: COMPLETE Column stats: NONE
-            table:
-                input format: org.apache.hadoop.mapred.SequenceFileInputFormat
-                output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
-                serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
 
   Stage: Stage-0
     Fetch Operator
@@ -376,7 +366,7 @@ PREHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src10_1
 PREHOOK: Input: default@src10_2
@@ -387,7 +377,7 @@ POSTHOOK: query: SELECT * FROM (
   SELECT sub1.key,sub1.value FROM (SELECT * FROM src10_1) sub1 JOIN (SELECT * FROM src10_2) sub0 ON (sub0.key = sub1.key)
   UNION ALL
   SELECT key,value FROM (SELECT * FROM (SELECT * FROM src10_3) sub2 UNION ALL SELECT * FROM src10_4 ) alias0
-) alias1 order by key
+) alias1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src10_1
 POSTHOOK: Input: default@src10_2

http://git-wip-us.apache.org/repos/asf/hive/blob/d14673a0/ql/src/test/results/clientpositive/union36.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/union36.q.out b/ql/src/test/results/clientpositive/union36.q.out
index 12f060b..1eb0182 100644
--- a/ql/src/test/results/clientpositive/union36.q.out
+++ b/ql/src/test/results/clientpositive/union36.q.out
@@ -1,28 +1,30 @@
-PREHOOK: query: select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y
+PREHOOK: query: -- SORT_QUERY_RESULTS
+select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
-POSTHOOK: query: select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y
+POSTHOOK: query: -- SORT_QUERY_RESULTS
+select (x/sum(x) over())  as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
+0.4999999900000002
+0.4999999900000002
 4.999999900000002E-9
 4.999999900000002E-9
 4.999999900000002E-9
 4.999999900000002E-9
-0.4999999900000002
-0.4999999900000002
-PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y
+PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
 #### A masked pattern was here ####
-POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y
+POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0))  as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
-NULL
-NULL
 0.25
 0.25
 0.25
 0.25
+NULL
+NULL