You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by vg...@apache.org on 2019/08/21 22:24:50 UTC

[hive] branch master updated: HIVE-22107: Correlated subquery producing wrong schema (Vineet Garg, reviewed by Ashutosh Chauhan)

This is an automated email from the ASF dual-hosted git repository.

vgarg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new a7e1c0d  HIVE-22107: Correlated subquery producing wrong schema (Vineet Garg,reviewed by Ashutosh Chauhan)
a7e1c0d is described below

commit a7e1c0dfa8ed5db52f36c30acd620611e2564989
Author: Vineet Garg <vg...@apache.org>
AuthorDate: Wed Aug 21 15:24:09 2019 -0700

    HIVE-22107: Correlated subquery producing wrong schema (Vineet Garg,reviewed by Ashutosh Chauhan)
---
 .../calcite/rules/HiveRelDecorrelator.java         |   6 -
 .../calcite/rules/HiveSubQueryRemoveRule.java      |  13 +-
 .../queries/clientpositive/subquery_notexists.q    |   9 +
 .../clientpositive/llap/explainuser_1.q.out        |  22 +--
 .../llap/external_jdbc_table_perf.q.out            |  80 ++++----
 .../results/clientpositive/llap/subquery_in.q.out  |  28 +--
 .../clientpositive/llap/subquery_in_having.q.out   |  28 +--
 .../clientpositive/llap/subquery_multi.q.out       |  62 +++---
 .../clientpositive/llap/subquery_notin.q.out       | 208 ++++++++++-----------
 .../clientpositive/llap/subquery_scalar.q.out      |  26 +--
 .../clientpositive/llap/subquery_select.q.out      |  92 ++++-----
 .../clientpositive/llap/subquery_views.q.out       |  28 +--
 .../clientpositive/perf/spark/query10.q.out        |  24 +--
 .../clientpositive/perf/spark/query16.q.out        |  14 +-
 .../clientpositive/perf/spark/query35.q.out        |  24 +--
 .../clientpositive/perf/spark/query69.q.out        |  28 +--
 .../clientpositive/perf/spark/query94.q.out        |  14 +-
 .../clientpositive/perf/tez/cbo_query10.q.out      |  10 +-
 .../clientpositive/perf/tez/cbo_query16.q.out      |   6 +-
 .../clientpositive/perf/tez/cbo_query35.q.out      |  10 +-
 .../clientpositive/perf/tez/cbo_query69.q.out      |  14 +-
 .../clientpositive/perf/tez/cbo_query94.q.out      |   6 +-
 .../perf/tez/constraints/cbo_query10.q.out         |  10 +-
 .../perf/tez/constraints/cbo_query16.q.out         |   6 +-
 .../perf/tez/constraints/cbo_query35.q.out         |  10 +-
 .../perf/tez/constraints/cbo_query69.q.out         |  14 +-
 .../perf/tez/constraints/cbo_query94.q.out         |   6 +-
 .../perf/tez/constraints/query10.q.out             |  10 +-
 .../perf/tez/constraints/query16.q.out             |   6 +-
 .../perf/tez/constraints/query35.q.out             |  10 +-
 .../perf/tez/constraints/query69.q.out             |  12 +-
 .../perf/tez/constraints/query94.q.out             |   6 +-
 .../results/clientpositive/perf/tez/query10.q.out  |  10 +-
 .../results/clientpositive/perf/tez/query16.q.out  |   6 +-
 .../results/clientpositive/perf/tez/query35.q.out  |  10 +-
 .../results/clientpositive/perf/tez/query69.q.out  |  12 +-
 .../results/clientpositive/perf/tez/query94.q.out  |   6 +-
 .../clientpositive/spark/spark_explainuser_1.q.out |  24 +--
 .../results/clientpositive/spark/subquery_in.q.out |  28 +--
 .../clientpositive/spark/subquery_multi.q.out      |  62 +++---
 .../clientpositive/spark/subquery_notin.q.out      | 208 ++++++++++-----------
 .../clientpositive/spark/subquery_scalar.q.out     |  22 +--
 .../clientpositive/spark/subquery_select.q.out     |  92 ++++-----
 .../clientpositive/spark/subquery_views.q.out      |  32 ++--
 .../clientpositive/subquery_notexists.q.out        | 110 ++++++++---
 .../clientpositive/subquery_notexists_having.q.out |  28 +--
 .../clientpositive/subquery_notin_having.q.out     |  14 +-
 .../clientpositive/subquery_unqualcolumnrefs.q.out |  14 +-
 48 files changed, 792 insertions(+), 728 deletions(-)

diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java
index dd5eb41..86b7914 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java
@@ -729,12 +729,6 @@ public final class HiveRelDecorrelator implements ReflectiveVisitor {
     final NavigableMap<Integer, RexLiteral> omittedConstants = new TreeMap<>();
     for (int i = 0; i < oldGroupKeyCount; i++) {
       final RexLiteral constant = projectedLiteral(newInput, i);
-      if (constant != null) {
-        // Exclude constants. Aggregate({true}) occurs because Aggregate({})
-        // would generate 1 row even when applied to an empty table.
-        omittedConstants.put(i, constant);
-        continue;
-      }
       int newInputPos = frame.oldToNewOutputs.get(i);
       projects.add(RexInputRef.of2(newInputPos, newInputOutput));
       mapNewInputToProjOutputs.put(newInputPos, newPos);
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSubQueryRemoveRule.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSubQueryRemoveRule.java
index bad49f9..2a2c384 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSubQueryRemoveRule.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSubQueryRemoveRule.java
@@ -199,7 +199,7 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
 
       // id is appended since there could be multiple scalar subqueries and FILTER
       // is created using field name
-      String indicator = "alwaysTrue" + e.rel.getId();
+      String indicator = "trueLiteral";
       parentQueryFields.add(builder.alias(builder.literal(true), indicator));
       builder.project(parentQueryFields);
       builder.join(JoinRelType.LEFT, builder.literal(true), variablesSet);
@@ -283,7 +283,7 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
       //   end as v
       // from emp as e
       // left outer join (
-      //   select max(deptno) as m, count(*) as c, count(deptno) as d, "alwaysTrue" as indicator
+      //   select max(deptno) as m, count(*) as c, count(deptno) as d, "trueLiteral" as indicator
       //   group by name from emp) as q on e.name = q.name
       subqueryRestriction(e.rel);
       builder.push(e.rel);
@@ -294,7 +294,7 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
 
       final List<RexNode> parentQueryFields = new ArrayList<>();
       parentQueryFields.addAll(builder.fields());
-      String indicator = "alwaysTrue" + e.rel.getId();
+      String indicator = "trueLiteral" ;
       parentQueryFields.add(builder.alias(builder.literal(true), indicator));
       builder.project(parentQueryFields).as("q");
       builder.join(JoinRelType.LEFT, builder.literal(true), variablesSet);
@@ -432,10 +432,11 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
     }
 
     // Now the left join
+    String trueLiteral = "literalTrue";
     switch (logic) {
     case TRUE:
       if (fields.isEmpty()) {
-        builder.project(builder.alias(builder.literal(true), "i" + e.rel.getId()));
+        builder.project(builder.alias(builder.literal(true), trueLiteral));
         if (!variablesSet.isEmpty() && (e.getKind() == SqlKind.EXISTS
             || e.getKind() == SqlKind.IN)) {
           // avoid adding group by for correlated IN/EXISTS queries
@@ -456,7 +457,7 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
       }
       break;
     default:
-      fields.add(builder.alias(builder.literal(true), "i" + e.rel.getId()));
+      fields.add(builder.alias(builder.literal(true), trueLiteral));
       builder.project(fields);
       builder.distinct();
     }
@@ -494,7 +495,7 @@ public class HiveSubQueryRemoveRule extends RelOptRule {
       break;
     }
     operands
-        .add(builder.isNotNull(builder.field("dt", "i" + e.rel.getId())), builder.literal(true));
+        .add(builder.isNotNull(builder.field("dt",trueLiteral)), builder.literal(true));
     if (!keyIsNulls.isEmpty()) {
       //Calcite creates null literal with Null type here but
       // because HIVE doesn't support null type it is appropriately typed boolean
diff --git a/ql/src/test/queries/clientpositive/subquery_notexists.q b/ql/src/test/queries/clientpositive/subquery_notexists.q
index 5b80969..eab5d9e 100644
--- a/ql/src/test/queries/clientpositive/subquery_notexists.q
+++ b/ql/src/test/queries/clientpositive/subquery_notexists.q
@@ -67,3 +67,12 @@ explain SELECT p1.p_name FROM part p1 LEFT JOIN (select p_type as p_col from par
                 (select pp1.p_type as p_col from part pp1 where pp1.p_partkey = p2.p_col);
 SELECT p1.p_name FROM part p1 LEFT JOIN (select p_type as p_col from part ) p2 WHERE NOT EXISTS
                 (select pp1.p_type as p_col from part pp1 where pp1.p_partkey = p2.p_col);
+
+-- decorrelation should not mangle up the result schema
+create table tschema(id int, name string,dept string);
+insert into tschema values(1,'a','it'),(2,'b','eee'),(NULL, 'c', 'cse');
+explain cbo select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id);
+select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id);
+drop table tschema;
diff --git a/ql/src/test/results/clientpositive/llap/explainuser_1.q.out b/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
index ee50efd..e17ac7b 100644
--- a/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
+++ b/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
@@ -2095,9 +2095,9 @@ Stage-0
         Select Operator [SEL_18] (rows=500 width=178)
           Output:["_col0","_col1"]
           Filter Operator [FIL_17] (rows=500 width=178)
-            predicate:_col3 is null
+            predicate:_col2 is null
             Merge Join Operator [MERGEJOIN_27] (rows=635 width=178)
-              Conds:RS_14._col1=RS_15._col0(Left Outer),Output:["_col0","_col1","_col3"]
+              Conds:RS_14._col1=RS_15._col1(Left Outer),Output:["_col0","_col1","_col2"]
             <-Map 1 [SIMPLE_EDGE] llap
               SHUFFLE [RS_14]
                 PartitionCols:_col1
@@ -2107,7 +2107,7 @@ Stage-0
                     default@src_cbo,b,Tbl:COMPLETE,Col:COMPLETE,Output:["key","value"]
             <-Reducer 3 [SIMPLE_EDGE] llap
               SHUFFLE [RS_15]
-                PartitionCols:_col0
+                PartitionCols:_col1
                 Select Operator [SEL_13] (rows=83 width=95)
                   Output:["_col0","_col1"]
                   Group By Operator [GBY_12] (rows=83 width=91)
@@ -2161,9 +2161,9 @@ Stage-0
         Select Operator [SEL_17] (rows=250 width=178)
           Output:["_col0","_col1"]
           Filter Operator [FIL_16] (rows=250 width=179)
-            predicate:_col4 is null
+            predicate:_col2 is null
             Merge Join Operator [MERGEJOIN_31] (rows=333 width=179)
-              Conds:GBY_4._col0, _col1=SEL_12._col0, _col1(Left Outer),Output:["_col0","_col1","_col4"]
+              Conds:GBY_4._col0, _col1=SEL_12._col1, _col2(Left Outer),Output:["_col0","_col1","_col2"]
             <-Select Operator [SEL_12] (rows=83 width=182)
                 Output:["_col0","_col1","_col2"]
                 Group By Operator [GBY_11] (rows=83 width=178)
@@ -2707,9 +2707,9 @@ Stage-0
         Select Operator [SEL_23] (rows=41 width=223)
           Output:["_col0","_col1","_col2"]
           Filter Operator [FIL_22] (rows=41 width=229)
-            predicate:((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null))
+            predicate:((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null))
             Merge Join Operator [MERGEJOIN_45] (rows=41 width=229)
-              Conds:RS_19._col0, _col1=RS_20._col0, _col1(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5","_col8"]
+              Conds:RS_19._col0, _col1=RS_20._col0, _col2(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5","_col7"]
             <-Reducer 2 [SIMPLE_EDGE] llap
               SHUFFLE [RS_19]
                 PartitionCols:_col0, _col1
@@ -2739,7 +2739,7 @@ Stage-0
                                Please refer to the previous TableScan [TS_0]
             <-Reducer 5 [ONE_TO_ONE_EDGE] llap
               FORWARD [RS_20]
-                PartitionCols:_col0, _col1
+                PartitionCols:_col0, _col2
                 Select Operator [SEL_15] (rows=4 width=223)
                   Output:["_col0","_col1","_col2"]
                   Group By Operator [GBY_14] (rows=4 width=219)
@@ -2885,9 +2885,9 @@ Stage-0
             Select Operator [SEL_33] (rows=7 width=106)
               Output:["_col0","_col1"]
               Filter Operator [FIL_32] (rows=7 width=114)
-                predicate:((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null))
+                predicate:((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null))
                 Merge Join Operator [MERGEJOIN_48] (rows=7 width=114)
-                  Conds:RS_29._col0, _col1=RS_30._col0, _col1(Left Outer),Output:["_col0","_col1","_col3","_col4","_col7"]
+                  Conds:RS_29._col0, _col1=RS_30._col0, _col2(Left Outer),Output:["_col0","_col1","_col3","_col4","_col6"]
                 <-Reducer 3 [SIMPLE_EDGE] llap
                   SHUFFLE [RS_29]
                     PartitionCols:_col0, _col1
@@ -2931,7 +2931,7 @@ Stage-0
                                          Please refer to the previous Select Operator [SEL_1]
                 <-Reducer 8 [SIMPLE_EDGE] llap
                   SHUFFLE [RS_30]
-                    PartitionCols:_col0, _col1
+                    PartitionCols:_col0, _col2
                     Select Operator [SEL_25] (rows=1 width=110)
                       Output:["_col0","_col1","_col2"]
                       Filter Operator [FIL_40] (rows=1 width=114)
diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out b/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
index 8b52f38..4fb4324 100644
--- a/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
+++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
@@ -1802,7 +1802,7 @@ WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) A
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ws_bill_customer_sk" AS "ws_bill_customer_sk0", TRUE AS "$f1"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk" AS "ws_bill_customer_sk0"
 FROM (SELECT "ws_sold_date_sk", "ws_sold_time_sk", "ws_ship_date_sk", "ws_item_sk", "ws_bill_customer_sk", "ws_bill_cdemo_sk", "ws_bill_hdemo_sk", "ws_bill_addr_sk", "ws_ship_customer_sk", "ws_ship_cdemo_sk", "ws_ship_hdemo_sk", "ws_ship_addr_sk", "ws_web_page_sk", "ws_web_site_sk", "ws_ship_mode_sk", "ws_warehouse_sk", "ws_promo_sk", "ws_order_number", "ws_quantity", "ws_wholesale_cost", "ws_list_price", "ws_sales_price", "ws_ext_discount_amt", "ws_ext_sales_price", "ws_ext_wholesale_co [...]
 FROM "WEB_SALES"
 WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
@@ -1810,20 +1810,20 @@ INNER JOIN (SELECT "d_date_sk"
 FROM "DATE_DIM"
 WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
 GROUP BY "t0"."ws_bill_customer_sk"
-                    hive.sql.query.fieldNames ws_bill_customer_sk0,$f1
-                    hive.sql.query.fieldTypes int,boolean
+                    hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk0
+                    hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: ws_bill_customer_sk0 (type: int), $f1 (type: boolean)
+                    expressions: literaltrue (type: boolean), ws_bill_customer_sk0 (type: int)
                     outputColumnNames: _col0, _col1
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col0 (type: int)
+                      key expressions: _col1 (type: int)
                       sort order: +
-                      Map-reduce partition columns: _col0 (type: int)
+                      Map-reduce partition columns: _col1 (type: int)
                       Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col1 (type: boolean)
+                      value expressions: _col0 (type: boolean)
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 9 
@@ -1831,7 +1831,7 @@ GROUP BY "t0"."ws_bill_customer_sk"
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT "t0"."cs_ship_customer_sk" AS "cs_ship_customer_sk0", TRUE AS "$f1"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk" AS "cs_ship_customer_sk0"
 FROM (SELECT "cs_sold_date_sk", "cs_sold_time_sk", "cs_ship_date_sk", "cs_bill_customer_sk", "cs_bill_cdemo_sk", "cs_bill_hdemo_sk", "cs_bill_addr_sk", "cs_ship_customer_sk", "cs_ship_cdemo_sk", "cs_ship_hdemo_sk", "cs_ship_addr_sk", "cs_call_center_sk", "cs_catalog_page_sk", "cs_ship_mode_sk", "cs_warehouse_sk", "cs_item_sk", "cs_promo_sk", "cs_order_number", "cs_quantity", "cs_wholesale_cost", "cs_list_price", "cs_sales_price", "cs_ext_discount_amt", "cs_ext_sales_price", "cs_ext_whole [...]
 FROM "CATALOG_SALES"
 WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
@@ -1839,20 +1839,20 @@ INNER JOIN (SELECT "d_date_sk"
 FROM "DATE_DIM"
 WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
 GROUP BY "t0"."cs_ship_customer_sk"
-                    hive.sql.query.fieldNames cs_ship_customer_sk0,$f1
-                    hive.sql.query.fieldTypes int,boolean
+                    hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk0
+                    hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: cs_ship_customer_sk0 (type: int), $f1 (type: boolean)
+                    expressions: literaltrue (type: boolean), cs_ship_customer_sk0 (type: int)
                     outputColumnNames: _col0, _col1
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col0 (type: int)
+                      key expressions: _col1 (type: int)
                       sort order: +
-                      Map-reduce partition columns: _col0 (type: int)
+                      Map-reduce partition columns: _col1 (type: int)
                       Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col1 (type: boolean)
+                      value expressions: _col0 (type: boolean)
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Reducer 2 
@@ -1880,11 +1880,11 @@ GROUP BY "t0"."cs_ship_customer_sk"
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col41
+                  1 _col1 (type: int)
+                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col41 is null (type: boolean)
+                  predicate: _col40 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
@@ -1904,11 +1904,11 @@ GROUP BY "t0"."cs_ship_customer_sk"
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col43
+                  1 _col1 (type: int)
+                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col42
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col43 is null (type: boolean)
+                  predicate: _col42 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
@@ -2283,7 +2283,7 @@ WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) A
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ws_bill_customer_sk" AS "ws_bill_customer_sk0", TRUE AS "$f1"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk" AS "ws_bill_customer_sk0"
 FROM (SELECT "ws_sold_date_sk", "ws_sold_time_sk", "ws_ship_date_sk", "ws_item_sk", "ws_bill_customer_sk", "ws_bill_cdemo_sk", "ws_bill_hdemo_sk", "ws_bill_addr_sk", "ws_ship_customer_sk", "ws_ship_cdemo_sk", "ws_ship_hdemo_sk", "ws_ship_addr_sk", "ws_web_page_sk", "ws_web_site_sk", "ws_ship_mode_sk", "ws_warehouse_sk", "ws_promo_sk", "ws_order_number", "ws_quantity", "ws_wholesale_cost", "ws_list_price", "ws_sales_price", "ws_ext_discount_amt", "ws_ext_sales_price", "ws_ext_wholesale_co [...]
 FROM "WEB_SALES"
 WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
@@ -2291,20 +2291,20 @@ INNER JOIN (SELECT "d_date_sk"
 FROM "DATE_DIM"
 WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
 GROUP BY "t0"."ws_bill_customer_sk"
-                    hive.sql.query.fieldNames ws_bill_customer_sk0,$f1
-                    hive.sql.query.fieldTypes int,boolean
+                    hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk0
+                    hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: ws_bill_customer_sk0 (type: int), $f1 (type: boolean)
+                    expressions: literaltrue (type: boolean), ws_bill_customer_sk0 (type: int)
                     outputColumnNames: _col0, _col1
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col0 (type: int)
+                      key expressions: _col1 (type: int)
                       sort order: +
-                      Map-reduce partition columns: _col0 (type: int)
+                      Map-reduce partition columns: _col1 (type: int)
                       Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col1 (type: boolean)
+                      value expressions: _col0 (type: boolean)
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 9 
@@ -2312,7 +2312,7 @@ GROUP BY "t0"."ws_bill_customer_sk"
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT "t0"."cs_ship_customer_sk" AS "cs_ship_customer_sk0", TRUE AS "$f1"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk" AS "cs_ship_customer_sk0"
 FROM (SELECT "cs_sold_date_sk", "cs_sold_time_sk", "cs_ship_date_sk", "cs_bill_customer_sk", "cs_bill_cdemo_sk", "cs_bill_hdemo_sk", "cs_bill_addr_sk", "cs_ship_customer_sk", "cs_ship_cdemo_sk", "cs_ship_hdemo_sk", "cs_ship_addr_sk", "cs_call_center_sk", "cs_catalog_page_sk", "cs_ship_mode_sk", "cs_warehouse_sk", "cs_item_sk", "cs_promo_sk", "cs_order_number", "cs_quantity", "cs_wholesale_cost", "cs_list_price", "cs_sales_price", "cs_ext_discount_amt", "cs_ext_sales_price", "cs_ext_whole [...]
 FROM "CATALOG_SALES"
 WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
@@ -2320,20 +2320,20 @@ INNER JOIN (SELECT "d_date_sk"
 FROM "DATE_DIM"
 WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
 GROUP BY "t0"."cs_ship_customer_sk"
-                    hive.sql.query.fieldNames cs_ship_customer_sk0,$f1
-                    hive.sql.query.fieldTypes int,boolean
+                    hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk0
+                    hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: cs_ship_customer_sk0 (type: int), $f1 (type: boolean)
+                    expressions: literaltrue (type: boolean), cs_ship_customer_sk0 (type: int)
                     outputColumnNames: _col0, _col1
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col0 (type: int)
+                      key expressions: _col1 (type: int)
                       sort order: +
-                      Map-reduce partition columns: _col0 (type: int)
+                      Map-reduce partition columns: _col1 (type: int)
                       Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col1 (type: boolean)
+                      value expressions: _col0 (type: boolean)
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Reducer 2 
@@ -2361,11 +2361,11 @@ GROUP BY "t0"."cs_ship_customer_sk"
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col41
+                  1 _col1 (type: int)
+                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col41 is null (type: boolean)
+                  predicate: _col40 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
@@ -2385,11 +2385,11 @@ GROUP BY "t0"."cs_ship_customer_sk"
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col43
+                  1 _col1 (type: int)
+                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col42
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col43 is null (type: boolean)
+                  predicate: _col42 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
diff --git a/ql/src/test/results/clientpositive/llap/subquery_in.q.out b/ql/src/test/results/clientpositive/llap/subquery_in.q.out
index c888a87..4885dba 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_in.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_in.q.out
@@ -5019,11 +5019,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string), UDFToLong(_col5) (type: bigint)
-                  1 _col1 (type: string), _col0 (type: bigint)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: string), _col0 (type: bigint)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 13 Data size: 8307 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 1 Data size: 639 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -5090,15 +5090,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col1 (type: bigint), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: bigint), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1508 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: bigint)
+                      key expressions: _col2 (type: string), _col0 (type: bigint)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: bigint)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: bigint)
                       Statistics: Num rows: 13 Data size: 1508 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -5273,11 +5273,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), UDFToDouble(_col5) (type: double)
-                  1 _col1 (type: int), _col0 (type: double)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: int), _col0 (type: double)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 13 Data size: 8307 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 1 Data size: 639 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -5339,15 +5339,15 @@ STAGE PLANS:
                   predicate: (_col2 is not null and UDFToDouble(_col1) is not null) (type: boolean)
                   Statistics: Num rows: 13 Data size: 260 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: (UDFToDouble(_col1) / _col2) (type: double), _col0 (type: int), true (type: boolean)
+                    expressions: (UDFToDouble(_col1) / _col2) (type: double), true (type: boolean), _col0 (type: int)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 208 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col1 (type: int), _col0 (type: double)
+                      key expressions: _col2 (type: int), _col0 (type: double)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: int), _col0 (type: double)
+                      Map-reduce partition columns: _col2 (type: int), _col0 (type: double)
                       Statistics: Num rows: 13 Data size: 208 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/llap/subquery_in_having.q.out b/ql/src/test/results/clientpositive/llap/subquery_in_having.q.out
index 3d96385..934d963 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_in_having.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_in_having.q.out
@@ -1696,10 +1696,10 @@ STAGE PLANS:
                       outputColumnNames: _col0, _col1, _col2, _col3
                       input vertices:
                         1 Reducer 4
-                      residual filter predicates: {(_col2 <> _col1)}
+                      residual filter predicates: {(_col3 <> _col1)}
                       Statistics: Num rows: 1 Data size: 553 Basic stats: COMPLETE Column stats: NONE
                       Filter Operator
-                        predicate: _col3 is null (type: boolean)
+                        predicate: _col2 is null (type: boolean)
                         Statistics: Num rows: 1 Data size: 553 Basic stats: COMPLETE Column stats: NONE
                         Select Operator
                           expressions: _col0 (type: string), _col1 (type: string)
@@ -1775,10 +1775,10 @@ STAGE PLANS:
                         outputColumnNames: _col0, _col1, _col2, _col3
                         input vertices:
                           1 Reducer 4
-                        residual filter predicates: {(_col2 <> _col1)}
+                        residual filter predicates: {(_col3 <> _col1)}
                         Statistics: Num rows: 1 Data size: 553 Basic stats: COMPLETE Column stats: NONE
                         Filter Operator
-                          predicate: _col3 is null (type: boolean)
+                          predicate: _col2 is null (type: boolean)
                           Statistics: Num rows: 1 Data size: 553 Basic stats: COMPLETE Column stats: NONE
                           Select Operator
                             expressions: _col0 (type: string), _col1 (type: string)
@@ -1825,13 +1825,13 @@ STAGE PLANS:
                            Left Outer Join 0 to 1
                       keys:
                         0 _col1 (type: string), _col2 (type: bigint)
-                        1 _col1 (type: string), _col0 (type: bigint)
-                      outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+                        1 _col2 (type: string), _col0 (type: bigint)
+                      outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
                       input vertices:
                         1 Reducer 9
                       Statistics: Num rows: 1 Data size: 668 Basic stats: COMPLETE Column stats: NONE
                       Filter Operator
-                        predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col2 is null)) (type: boolean)
+                        predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col2 is null)) (type: boolean)
                         Statistics: Num rows: 1 Data size: 668 Basic stats: COMPLETE Column stats: NONE
                         Select Operator
                           expressions: _col0 (type: string), _col1 (type: string), _col2 (type: bigint)
@@ -1853,17 +1853,17 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
                     sort order: 
                     Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col0 (type: string), _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean), _col1 (type: string)
                   Reduce Output Operator
                     sort order: 
                     Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col0 (type: string), _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean), _col1 (type: string)
         Reducer 6 
             Execution mode: llap
             Reduce Operator Tree:
@@ -1980,15 +1980,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 922 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: bigint), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: bigint), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 922 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col1 (type: string), _col0 (type: bigint)
+                    key expressions: _col2 (type: string), _col0 (type: bigint)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: string), _col0 (type: bigint)
+                    Map-reduce partition columns: _col2 (type: string), _col0 (type: bigint)
                     Statistics: Num rows: 1 Data size: 922 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/llap/subquery_multi.q.out b/ql/src/test/results/clientpositive/llap/subquery_multi.q.out
index 190c79e..6b54673 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_multi.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_multi.q.out
@@ -1770,8 +1770,8 @@ POSTHOOK: Input: default@part_null
 #### A masked pattern was here ####
 CBO PLAN:
 HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4], p_size=[$5], p_container=[$6], p_retailprice=[$7], p_comment=[$8])
-  HiveFilter(condition=[AND(OR(IS NULL($14), =($10, 0), IS NULL($10)), OR(IS NOT NULL($3), =($10, 0), IS NULL($10), IS NOT NULL($14)), OR(IS NOT TRUE(<($11, $10)), =($10, 0), IS NULL($10), IS NOT NULL($14), IS NULL($3)))])
-    HiveJoin(condition=[AND(=($3, $12), =($13, $4))], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[AND(OR(IS NULL($13), =($10, 0), IS NULL($10)), OR(IS NOT NULL($3), =($10, 0), IS NULL($10), IS NOT NULL($13)), OR(IS NOT TRUE(<($11, $10)), =($10, 0), IS NULL($10), IS NOT NULL($13), IS NULL($3)))])
+    HiveJoin(condition=[AND(=($3, $12), =($14, $4))], joinType=[left], algorithm=[none], cost=[not available])
       HiveJoin(condition=[=($9, $4)], joinType=[left], algorithm=[none], cost=[not available])
         HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4], p_size=[$5], p_container=[$6], p_retailprice=[$7], p_comment=[$8])
           HiveTableScan(table=[[default, part_null]], table:alias=[part_null])
@@ -1784,7 +1784,7 @@ HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4],
               HiveProject(p_brand=[$3], p_type=[$4])
                 HiveFilter(condition=[AND(IS NOT NULL($4), IS NOT NULL($3))])
                   HiveTableScan(table=[[default, part]], table:alias=[pp])
-      HiveProject(p_container=[$1], p_type=[$0], $f2=[true])
+      HiveProject(p_container=[$1], literalTrue=[true], p_type=[$0])
         HiveAggregate(group=[{1, 2}])
           HiveSemiJoin(condition=[AND(=($1, $4), =($0, $3))], joinType=[inner])
             HiveProject(p_brand=[$3], p_type=[$4], p_container=[$6])
@@ -1947,15 +1947,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 7 Data size: 1372 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 7 Data size: 1400 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 7 Data size: 1400 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 2 
             Execution mode: llap
             Reduce Operator Tree:
@@ -1998,11 +1998,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col4 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 16 Data size: 3891 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 16 Data size: 3891 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2456,15 +2456,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 7 Data size: 1372 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 7 Data size: 1400 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 7 Data size: 1400 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 2 
             Execution mode: llap
             Reduce Operator Tree:
@@ -2507,11 +2507,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col4 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 16 Data size: 5484 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 16 Data size: 5484 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2781,11 +2781,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col5 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 16 Data size: 3891 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 16 Data size: 3891 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2822,15 +2822,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -4611,11 +4611,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10
+                  1 _col1 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                 Statistics: Num rows: 15 Data size: 9532 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col10 is null (type: boolean)
+                  predicate: _col9 is null (type: boolean)
                   Statistics: Num rows: 7 Data size: 4448 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -4637,15 +4637,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/llap/subquery_notin.q.out b/ql/src/test/results/clientpositive/llap/subquery_notin.q.out
index 1a7e598..7f87ef4 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_notin.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_notin.q.out
@@ -402,11 +402,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
                 Statistics: Num rows: 38 Data size: 8914 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 38 Data size: 8914 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col1 (type: string), _col0 (type: string), _col2 (type: int)
@@ -537,15 +537,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 4 Data size: 876 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 4 Data size: 892 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 4 Data size: 892 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -1004,11 +1004,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
                 Statistics: Num rows: 15 Data size: 3605 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col2 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col2 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 15 Data size: 3605 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col1 (type: string), _col0 (type: string), _col2 (type: int)
@@ -1203,15 +1203,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 4 Data size: 408 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 4 Data size: 424 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 4 Data size: 424 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -1752,11 +1752,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string), _col5 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 64 Data size: 40340 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 64 Data size: 40340 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -1793,15 +1793,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col1 (type: string), _col0 (type: int)
+                    key expressions: _col2 (type: string), _col0 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                    Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                     Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -2422,11 +2422,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col3 (type: int)
-                outputColumnNames: _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col3 (type: int)
+                outputColumnNames: _col1, _col3, _col4, _col6
                 Statistics: Num rows: 48 Data size: 660 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 48 Data size: 660 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     Statistics: Num rows: 48 Data size: 660 Basic stats: COMPLETE Column stats: COMPLETE
@@ -2479,7 +2479,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1625 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
@@ -2487,7 +2487,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: int)
                     Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 8 
             Execution mode: llap
             Reduce Operator Tree:
@@ -2500,11 +2500,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
-                  key expressions: _col1 (type: string), _col3 (type: int)
+                  key expressions: _col2 (type: string), _col3 (type: int)
                   sort order: ++
-                  Map-reduce partition columns: _col1 (type: string), _col3 (type: int)
+                  Map-reduce partition columns: _col2 (type: string), _col3 (type: int)
                   Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -2834,11 +2834,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col5 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 40 Data size: 25032 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col1 is null) and (_col1 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col1 is null) and (_col1 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 40 Data size: 25032 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2875,15 +2875,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 6 Data size: 750 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 6 Data size: 774 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 6 Data size: 774 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -2989,15 +2989,15 @@ STAGE PLANS:
                     predicate: (p_size is not null and p_partkey is not null and p_name is not null) (type: boolean)
                     Statistics: Num rows: 26 Data size: 3354 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
-                      keys: p_partkey (type: int), p_name (type: string), p_size (type: int)
+                      keys: p_partkey (type: int), p_size (type: int), p_name (type: string)
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
                       Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
                       Reduce Output Operator
-                        key expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int)
+                        key expressions: _col0 (type: int), _col1 (type: int), _col2 (type: string)
                         sort order: +++
-                        Map-reduce partition columns: _col0 (type: int), _col1 (type: string), _col2 (type: int)
+                        Map-reduce partition columns: _col0 (type: int), _col1 (type: int), _col2 (type: string)
                         Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
             Execution mode: vectorized, llap
             LLAP IO: no inputs
@@ -3013,9 +3013,9 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12
                 Statistics: Num rows: 39 Data size: 24365 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
-                  key expressions: _col0 (type: int), _col1 (type: string), _col5 (type: int)
+                  key expressions: _col0 (type: int), _col5 (type: int), _col1 (type: string)
                   sort order: +++
-                  Map-reduce partition columns: _col0 (type: int), _col1 (type: string), _col5 (type: int)
+                  Map-reduce partition columns: _col0 (type: int), _col5 (type: int), _col1 (type: string)
                   Statistics: Num rows: 39 Data size: 24365 Basic stats: COMPLETE Column stats: COMPLETE
                   value expressions: _col2 (type: string), _col3 (type: string), _col4 (type: string), _col6 (type: string), _col7 (type: double), _col8 (type: string), _col11 (type: bigint), _col12 (type: bigint)
         Reducer 3 
@@ -3025,12 +3025,12 @@ STAGE PLANS:
                 condition map:
                      Left Outer Join 0 to 1
                 keys:
-                  0 _col0 (type: int), _col1 (type: string), _col5 (type: int)
-                  1 _col1 (type: int), _col0 (type: string), _col2 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12, _col16
+                  0 _col0 (type: int), _col5 (type: int), _col1 (type: string)
+                  1 _col2 (type: int), _col3 (type: int), _col0 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12, _col14
                 Statistics: Num rows: 59 Data size: 37149 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col16 is null or (_col11 = 0L) or _col11 is null) and ((_col12 < _col11) is not true or (_col11 = 0L) or _col11 is null or _col16 is not null or _col1 is null) and (_col1 is not null or (_col11 = 0L) or _col11 is null or _col16 is not null)) (type: boolean)
+                  predicate: ((_col14 is null or (_col11 = 0L) or _col11 is null) and ((_col12 < _col11) is not true or (_col11 = 0L) or _col11 is null or _col14 is not null or _col1 is null) and (_col1 is not null or (_col11 = 0L) or _col11 is null or _col14 is not null)) (type: boolean)
                   Statistics: Num rows: 59 Data size: 37149 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -3062,20 +3062,20 @@ STAGE PLANS:
             Execution mode: vectorized, llap
             Reduce Operator Tree:
               Group By Operator
-                keys: KEY._col0 (type: int), KEY._col1 (type: string), KEY._col2 (type: int)
+                keys: KEY._col0 (type: int), KEY._col1 (type: int), KEY._col2 (type: string)
                 mode: mergepartial
                 outputColumnNames: _col0, _col1, _col2
                 Statistics: Num rows: 13 Data size: 1677 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: int), _col2 (type: int), true (type: boolean)
+                  expressions: _col2 (type: string), true (type: boolean), _col0 (type: int), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2, _col3
                   Statistics: Num rows: 13 Data size: 1729 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col1 (type: int), _col0 (type: string), _col2 (type: int)
+                    key expressions: _col2 (type: int), _col3 (type: int), _col0 (type: string)
                     sort order: +++
-                    Map-reduce partition columns: _col1 (type: int), _col0 (type: string), _col2 (type: int)
+                    Map-reduce partition columns: _col2 (type: int), _col3 (type: int), _col0 (type: string)
                     Statistics: Num rows: 13 Data size: 1729 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col3 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3202,11 +3202,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 UDFToDouble(_col1) (type: double), _col2 (type: string)
-                  1 _col0 (type: double), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  1 _col0 (type: double), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 58 Data size: 13682 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 58 Data size: 13682 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -3243,15 +3243,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1300 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: double), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: double), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1352 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: double), _col1 (type: string)
+                    key expressions: _col0 (type: double), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: double), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: double), _col2 (type: string)
                     Statistics: Num rows: 13 Data size: 1352 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3440,11 +3440,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 46 Data size: 10734 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 46 Data size: 10734 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -3527,15 +3527,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 8 Data size: 864 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 8 Data size: 896 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 8 Data size: 896 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -4000,11 +4000,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col1 (type: string), _col0 (type: string)
-                outputColumnNames: _col0, _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col0 (type: string)
+                outputColumnNames: _col0, _col1, _col3, _col4, _col6
                 Statistics: Num rows: 1623 Data size: 309794 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 1401 Data size: 267414 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -4083,15 +4083,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 250 Data size: 67750 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: string), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 250 Data size: 68750 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col1 (type: string), _col0 (type: string)
+                    key expressions: _col2 (type: string), _col0 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: string), _col0 (type: string)
+                    Map-reduce partition columns: _col2 (type: string), _col0 (type: string)
                     Statistics: Num rows: 250 Data size: 68750 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 9 
             Execution mode: vectorized, llap
             Reduce Operator Tree:
@@ -5484,11 +5484,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col3 (type: int)
-                outputColumnNames: _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col3 (type: int)
+                outputColumnNames: _col1, _col3, _col4, _col6
                 Statistics: Num rows: 53 Data size: 780 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 53 Data size: 780 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     Statistics: Num rows: 53 Data size: 780 Basic stats: COMPLETE Column stats: COMPLETE
@@ -5541,7 +5541,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 2548 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: string), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 2600 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
@@ -5549,7 +5549,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: UDFToDouble(_col0) (type: double)
                     Statistics: Num rows: 13 Data size: 2600 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 8 
             Execution mode: llap
             Reduce Operator Tree:
@@ -5562,11 +5562,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 13 Data size: 1300 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
-                  key expressions: _col1 (type: string), _col3 (type: int)
+                  key expressions: _col2 (type: string), _col3 (type: int)
                   sort order: ++
-                  Map-reduce partition columns: _col1 (type: string), _col3 (type: int)
+                  Map-reduce partition columns: _col2 (type: string), _col3 (type: int)
                   Statistics: Num rows: 13 Data size: 1300 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -5913,11 +5913,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: char(100))
-                  1 _col0 (type: int), _col1 (type: char(100))
-                outputColumnNames: _col0, _col3, _col4, _col7
+                  1 _col0 (type: int), _col2 (type: char(100))
+                outputColumnNames: _col0, _col3, _col4, _col6
                 Statistics: Num rows: 6 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 6 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -6024,15 +6024,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 92 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: char(100)), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: char(100))
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 96 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int), _col1 (type: char(100))
+                    key expressions: _col0 (type: int), _col2 (type: char(100))
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: int), _col1 (type: char(100))
+                    Map-reduce partition columns: _col0 (type: int), _col2 (type: char(100))
                     Statistics: Num rows: 1 Data size: 96 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -6211,11 +6211,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: int)
-                  1 _col1 (type: int), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col3, _col4, _col7
+                  1 _col2 (type: int), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col3, _col4, _col6
                 Statistics: Num rows: 3 Data size: 84 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null)) (type: boolean)
                   Statistics: Num rows: 3 Data size: 84 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -6252,15 +6252,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), _col0 (type: int), true (type: boolean)
+                  expressions: _col1 (type: int), true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col1 (type: int), _col0 (type: int)
+                    key expressions: _col2 (type: int), _col0 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: int), _col0 (type: int)
+                    Map-reduce partition columns: _col2 (type: int), _col0 (type: int)
                     Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -6903,11 +6903,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: int)
-                  1 _col0 (type: int), _col1 (type: int)
-                outputColumnNames: _col0, _col3, _col4, _col7
+                  1 _col0 (type: int), _col2 (type: int)
+                outputColumnNames: _col0, _col3, _col4, _col6
                 Statistics: Num rows: 4 Data size: 88 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 4 Data size: 88 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -6944,15 +6944,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int), _col1 (type: int)
+                    key expressions: _col0 (type: int), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: int), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: int), _col2 (type: int)
                     Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -7428,10 +7428,10 @@ STAGE PLANS:
                   0 _col0 (type: string)
                   1 _col0 (type: string)
                 outputColumnNames: _col0, _col1, _col3, _col4, _col6, _col7
-                residual filter predicates: {(_col1 > _col6)}
+                residual filter predicates: {(_col1 > _col7)}
                 Statistics: Num rows: 1145 Data size: 236851 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 1145 Data size: 236851 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string), _col1 (type: string)
@@ -7497,7 +7497,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 83 Data size: 14774 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
@@ -7505,7 +7505,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: string)
                     Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 8 
             Execution mode: vectorized, llap
             Reduce Operator Tree:
diff --git a/ql/src/test/results/clientpositive/llap/subquery_scalar.q.out b/ql/src/test/results/clientpositive/llap/subquery_scalar.q.out
index f9cb495..b49bd46 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_scalar.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_scalar.q.out
@@ -5103,15 +5103,15 @@ STAGE PLANS:
                   predicate: CASE WHEN (_col11 is null) THEN ((UDFToLong(_col2) <> 0L)) ELSE ((UDFToLong(_col2) <> _col10)) END (type: boolean)
                   Statistics: Num rows: 3 Data size: 1065 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
-                    outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
+                    expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date), _col11 (type: boolean)
+                    outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col11
                     Statistics: Num rows: 3 Data size: 1065 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
                       key expressions: _col2 (type: int)
                       sort order: +
                       Map-reduce partition columns: _col2 (type: int)
                       Statistics: Num rows: 3 Data size: 1065 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col0 (type: int), _col1 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
+                      value expressions: _col0 (type: int), _col1 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date), _col11 (type: boolean)
         Reducer 3 
             Execution mode: llap
             Reduce Operator Tree:
@@ -5120,11 +5120,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col2 (type: int)
-                  1 _col2 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col13, _col14
+                  1 _col1 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col11, _col13
                 Statistics: Num rows: 4 Data size: 1428 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: CASE WHEN (_col14 is null) THEN ((UDFToLong(_col0) > 0L)) ELSE ((UDFToLong(_col0) > _col13)) END (type: boolean)
+                  predicate: CASE WHEN (_col11 is null) THEN ((UDFToLong(_col0) > 0L)) ELSE ((UDFToLong(_col0) > _col13)) END (type: boolean)
                   Statistics: Num rows: 2 Data size: 714 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
@@ -5166,15 +5166,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: bigint), true (type: boolean), _col0 (type: int)
-                  outputColumnNames: _col0, _col1, _col2
-                  Statistics: Num rows: 1 Data size: 16 Basic stats: COMPLETE Column stats: COMPLETE
+                  expressions: _col1 (type: bigint), _col0 (type: int)
+                  outputColumnNames: _col0, _col1
+                  Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col2 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col2 (type: int)
-                    Statistics: Num rows: 1 Data size: 16 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col0 (type: bigint), _col1 (type: boolean)
+                    Map-reduce partition columns: _col1 (type: int)
+                    Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
+                    value expressions: _col0 (type: bigint)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/llap/subquery_select.q.out b/ql/src/test/results/clientpositive/llap/subquery_select.q.out
index 1f451b1..f005762 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_select.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_select.q.out
@@ -297,11 +297,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col9
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col8
                 Statistics: Num rows: 48 Data size: 852 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), ((_col9 is not null and (_col5 or _col4 is null) is not true) or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col9 is null)) (type: boolean)
+                  expressions: _col1 (type: int), ((_col8 is not null and (_col5 or _col4 is null) is not true) or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col8 is null)) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 48 Data size: 384 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -349,15 +349,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -770,11 +770,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: int), _col0 (type: string)
-                  1 _col0 (type: int), _col1 (type: string)
-                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col9
+                  1 _col0 (type: int), _col2 (type: string)
+                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col8
                 Statistics: Num rows: 13 Data size: 364 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), ((_col5 or _col4 is null) is true or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col9 is null) or ((_col5 or _col4 is null) is not true and _col9 is null and (_col2 or _col6) is not true)) (type: boolean)
+                  expressions: _col1 (type: int), ((_col5 or _col4 is null) is true or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col8 is null) or ((_col5 or _col4 is null) is not true and _col8 is null and (_col2 or _col6) is not true)) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 104 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -797,15 +797,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col0 (type: int), _col1 (type: string)
+                      key expressions: _col0 (type: int), _col2 (type: string)
                       sort order: ++
-                      Map-reduce partition columns: _col0 (type: int), _col1 (type: string)
+                      Map-reduce partition columns: _col0 (type: int), _col2 (type: string)
                       Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 8 
             Execution mode: vectorized, llap
             Reduce Operator Tree:
@@ -1087,11 +1087,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 36 Data size: 204 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is not null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is not null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 36 Data size: 288 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -1110,15 +1110,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1352 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -1373,11 +1373,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 36 Data size: 204 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 36 Data size: 288 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -1396,15 +1396,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1352 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3258,15 +3258,15 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col2, _col3, _col4, _col6, _col7, _col8, _col11
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col2, _col3, _col4, _col6, _col7, _col8, _col10
                 Statistics: Num rows: 48 Data size: 6852 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
                   key expressions: _col0 (type: string)
                   sort order: +
                   Map-reduce partition columns: _col0 (type: string)
                   Statistics: Num rows: 48 Data size: 6852 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col11 (type: boolean)
+                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col10 (type: boolean)
         Reducer 4 
             Execution mode: llap
             Reduce Operator Tree:
@@ -3276,12 +3276,12 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: string)
                   1 _col0 (type: string)
-                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col11, _col13
+                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col10, _col13
                 Statistics: Num rows: 49 Data size: 1084 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
                   sort order: 
                   Statistics: Num rows: 49 Data size: 1084 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col11 (type: boolean), _col13 (type: boolean)
+                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col10 (type: boolean), _col13 (type: boolean)
         Reducer 5 
             Execution mode: llap
             Reduce Operator Tree:
@@ -3291,10 +3291,10 @@ STAGE PLANS:
                 keys:
                   0 
                   1 
-                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col11, _col13, _col14, _col15
+                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col10, _col13, _col14, _col15
                 Statistics: Num rows: 49 Data size: 1476 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col2 (type: int), (((_col11 is not null and (_col7 or _col6 is null) is not true) or ((_col3 or _col8) is true and null and (_col7 or _col6 is null) is not true and _col11 is null)) and ((_col13 is not null and _col14) or ((_col4 or _col15) and null and _col14 and _col13 is null))) (type: boolean)
+                  expressions: _col2 (type: int), (((_col10 is not null and (_col7 or _col6 is null) is not true) or ((_col3 or _col8) is true and null and (_col7 or _col6 is null) is not true and _col10 is null)) and ((_col13 is not null and _col14) or ((_col4 or _col15) and null and _col14 and _col13 is null))) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 49 Data size: 392 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -3333,15 +3333,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 13 Data size: 1456 Basic stats: COMPLETE Column stats: COMPLETE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 9 
             Execution mode: vectorized, llap
             Reduce Operator Tree:
@@ -3494,11 +3494,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 36 Data size: 204 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 36 Data size: 288 Basic stats: COMPLETE Column stats: COMPLETE
                   File Output Operator
@@ -3517,15 +3517,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1352 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1404 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/llap/subquery_views.q.out b/ql/src/test/results/clientpositive/llap/subquery_views.q.out
index ccc913a..1ac405b 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_views.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_views.q.out
@@ -277,11 +277,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col3 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  1 _col3 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 386 Data size: 73020 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 373 Data size: 70566 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string), _col1 (type: string)
@@ -335,7 +335,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 27 Data size: 4806 Basic stats: COMPLETE Column stats: COMPLETE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 27 Data size: 4914 Basic stats: COMPLETE Column stats: COMPLETE
                   Reduce Output Operator
@@ -343,7 +343,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: string)
                     Statistics: Num rows: 27 Data size: 4914 Basic stats: COMPLETE Column stats: COMPLETE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 7 
             Execution mode: llap
             Reduce Operator Tree:
@@ -356,17 +356,17 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 27 Data size: 4914 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
-                  key expressions: _col3 (type: string), _col1 (type: string)
+                  key expressions: _col3 (type: string), _col2 (type: string)
                   sort order: ++
-                  Map-reduce partition columns: _col3 (type: string), _col1 (type: string)
+                  Map-reduce partition columns: _col3 (type: string), _col2 (type: string)
                   Statistics: Num rows: 27 Data size: 4914 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
                 Reduce Output Operator
-                  key expressions: _col3 (type: string), _col1 (type: string)
+                  key expressions: _col3 (type: string), _col2 (type: string)
                   sort order: ++
-                  Map-reduce partition columns: _col3 (type: string), _col1 (type: string)
+                  Map-reduce partition columns: _col3 (type: string), _col2 (type: string)
                   Statistics: Num rows: 27 Data size: 4914 Basic stats: COMPLETE Column stats: COMPLETE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
         Reducer 8 
             Execution mode: llap
             Reduce Operator Tree:
@@ -375,11 +375,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col3 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col4, _col5, _col8
+                  1 _col3 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col4, _col5, _col7
                 Statistics: Num rows: 319 Data size: 30993 Basic stats: COMPLETE Column stats: COMPLETE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 304 Data size: 29540 Basic stats: COMPLETE Column stats: COMPLETE
                   Select Operator
                     expressions: _col0 (type: string)
diff --git a/ql/src/test/results/clientpositive/perf/spark/query10.q.out b/ql/src/test/results/clientpositive/perf/spark/query10.q.out
index 85bdad0..f201461 100644
--- a/ql/src/test/results/clientpositive/perf/spark/query10.q.out
+++ b/ql/src/test/results/clientpositive/perf/spark/query10.q.out
@@ -381,15 +381,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 17 
             Reduce Operator Tree:
               Join Operator
@@ -420,15 +420,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -471,12 +471,12 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                  2 _col0 (type: int)
-                  3 _col0 (type: int)
-                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13, _col15, _col17
+                  2 _col1 (type: int)
+                  3 _col1 (type: int)
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13, _col14, _col16
                 Statistics: Num rows: 2090864244 Data size: 184456650574 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: (_col15 is not null or _col17 is not null) (type: boolean)
+                  predicate: (_col14 is not null or _col16 is not null) (type: boolean)
                   Statistics: Num rows: 2090864244 Data size: 184456650574 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col6 (type: string), _col7 (type: string), _col8 (type: string), _col9 (type: int), _col10 (type: string), _col11 (type: int), _col12 (type: int), _col13 (type: int)
diff --git a/ql/src/test/results/clientpositive/perf/spark/query16.q.out b/ql/src/test/results/clientpositive/perf/spark/query16.q.out
index a9247dd..c5882a9 100644
--- a/ql/src/test/results/clientpositive/perf/spark/query16.q.out
+++ b/ql/src/test/results/clientpositive/perf/spark/query16.q.out
@@ -227,15 +227,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 14399440 Data size: 1528617286 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 14399440 Data size: 1528617286 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 14399440 Data size: 1528617286 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 2 
             Local Work:
               Map Reduce Local Work
@@ -302,11 +302,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col4, _col5, _col6, _col14
+                  1 _col1 (type: int)
+                outputColumnNames: _col4, _col5, _col6, _col13
                 Statistics: Num rows: 463810558 Data size: 62809267017 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col14 is null (type: boolean)
+                  predicate: _col13 is null (type: boolean)
                   Statistics: Num rows: 231905279 Data size: 31404633508 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col4 (type: int), _col5 (type: decimal(7,2)), _col6 (type: decimal(7,2))
diff --git a/ql/src/test/results/clientpositive/perf/spark/query35.q.out b/ql/src/test/results/clientpositive/perf/spark/query35.q.out
index 0959b85..2ff720b 100644
--- a/ql/src/test/results/clientpositive/perf/spark/query35.q.out
+++ b/ql/src/test/results/clientpositive/perf/spark/query35.q.out
@@ -378,15 +378,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 17 
             Reduce Operator Tree:
               Join Operator
@@ -417,15 +417,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -472,12 +472,12 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                  2 _col0 (type: int)
-                  3 _col0 (type: int)
-                outputColumnNames: _col4, _col6, _col7, _col8, _col9, _col10, _col12, _col14
+                  2 _col1 (type: int)
+                  3 _col1 (type: int)
+                outputColumnNames: _col4, _col6, _col7, _col8, _col9, _col10, _col11, _col13
                 Statistics: Num rows: 2090864244 Data size: 184456650574 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: (_col12 is not null or _col14 is not null) (type: boolean)
+                  predicate: (_col11 is not null or _col13 is not null) (type: boolean)
                   Statistics: Num rows: 2090864244 Data size: 184456650574 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col4 (type: string), _col6 (type: string), _col7 (type: string), _col8 (type: int), _col9 (type: int), _col10 (type: int)
diff --git a/ql/src/test/results/clientpositive/perf/spark/query69.q.out b/ql/src/test/results/clientpositive/perf/spark/query69.q.out
index bd0ff6b..80b0dc4 100644
--- a/ql/src/test/results/clientpositive/perf/spark/query69.q.out
+++ b/ql/src/test/results/clientpositive/perf/spark/query69.q.out
@@ -358,15 +358,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 79201469 Data size: 10769109250 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 18 
             Reduce Operator Tree:
               Join Operator
@@ -397,15 +397,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 158394413 Data size: 21449785388 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -447,11 +447,11 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                  2 _col0 (type: int)
-                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col12
+                  2 _col1 (type: int)
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col11
                 Statistics: Num rows: 1393909496 Data size: 122971100382 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col12 is null (type: boolean)
+                  predicate: _col11 is null (type: boolean)
                   Statistics: Num rows: 696954748 Data size: 61485550191 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col6 (type: string), _col7 (type: string), _col8 (type: string), _col9 (type: int), _col10 (type: string)
@@ -470,11 +470,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col14
+                  1 _col1 (type: int)
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col13
                 Statistics: Num rows: 766650239 Data size: 67634106676 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col14 is null (type: boolean)
+                  predicate: _col13 is null (type: boolean)
                   Statistics: Num rows: 383325119 Data size: 33817053293 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col6 (type: string), _col7 (type: string), _col8 (type: string), _col9 (type: int), _col10 (type: string)
diff --git a/ql/src/test/results/clientpositive/perf/spark/query94.q.out b/ql/src/test/results/clientpositive/perf/spark/query94.q.out
index f282d51..53c9d55 100644
--- a/ql/src/test/results/clientpositive/perf/spark/query94.q.out
+++ b/ql/src/test/results/clientpositive/perf/spark/query94.q.out
@@ -223,15 +223,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 7199233 Data size: 662597045 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 7199233 Data size: 662597045 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 7199233 Data size: 662597045 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
         Reducer 2 
             Local Work:
               Map Reduce Local Work
@@ -298,11 +298,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: int)
-                  1 _col0 (type: int)
-                outputColumnNames: _col4, _col5, _col6, _col14
+                  1 _col1 (type: int)
+                outputColumnNames: _col4, _col5, _col6, _col13
                 Statistics: Num rows: 231917759 Data size: 31534108438 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col14 is null (type: boolean)
+                  predicate: _col13 is null (type: boolean)
                   Statistics: Num rows: 115958879 Data size: 15767054151 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col4 (type: int), _col5 (type: decimal(7,2)), _col6 (type: decimal(7,2))
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query10.q.out b/ql/src/test/results/clientpositive/perf/tez/cbo_query10.q.out
index 9dc22a3..9df533b 100644
--- a/ql/src/test/results/clientpositive/perf/tez/cbo_query10.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query10.q.out
@@ -134,9 +134,9 @@ CBO PLAN:
 HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=[$8], sort6=[$10], sort7=[$12], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], dir5=[ASC], dir6=[ASC], dir7=[ASC], fetch=[100])
   HiveProject(cd_gender=[$0], cd_marital_status=[$1], cd_education_status=[$2], cnt1=[$8], cd_purchase_estimate=[$3], cnt2=[$8], cd_credit_rating=[$4], cnt3=[$8], cd_dep_count=[$5], cnt4=[$8], cd_dep_employed_count=[$6], cnt5=[$8], cd_dep_college_count=[$7], cnt6=[$8])
     HiveAggregate(group=[{6, 7, 8, 9, 10, 11, 12, 13}], agg#0=[count()])
-      HiveFilter(condition=[OR(IS NOT NULL($15), IS NOT NULL($17))])
-        HiveJoin(condition=[=($0, $16)], joinType=[left], algorithm=[none], cost=[not available])
-          HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+      HiveFilter(condition=[OR(IS NOT NULL($14), IS NOT NULL($16))])
+        HiveJoin(condition=[=($0, $17)], joinType=[left], algorithm=[none], cost=[not available])
+          HiveJoin(condition=[=($0, $15)], joinType=[left], algorithm=[none], cost=[not available])
             HiveSemiJoin(condition=[=($0, $14)], joinType=[inner])
               HiveJoin(condition=[=($5, $1)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveJoin(condition=[=($2, $3)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -157,7 +157,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=
                   HiveProject(d_date_sk=[$0])
                     HiveFilter(condition=[AND(=($6, 2002), BETWEEN(false, $8, 4, 7), IS NOT NULL($0))])
                       HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-            HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+            HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
               HiveAggregate(group=[{1}])
                 HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                   HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -166,7 +166,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=
                   HiveProject(d_date_sk=[$0])
                     HiveFilter(condition=[AND(=($6, 2002), BETWEEN(false, $8, 4, 7), IS NOT NULL($0))])
                       HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-          HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+          HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
             HiveAggregate(group=[{1}])
               HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query16.q.out b/ql/src/test/results/clientpositive/perf/tez/cbo_query16.q.out
index 7f39e2e..8126e43 100644
--- a/ql/src/test/results/clientpositive/perf/tez/cbo_query16.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query16.q.out
@@ -72,8 +72,8 @@ POSTHOOK: Input: default@date_dim
 POSTHOOK: Output: hdfs://### HDFS PATH ###
 CBO PLAN:
 HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[sum($6)])
-  HiveFilter(condition=[IS NULL($14)])
-    HiveJoin(condition=[=($4, $13)], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[IS NULL($13)])
+    HiveJoin(condition=[=($4, $14)], joinType=[left], algorithm=[none], cost=[not available])
       HiveSemiJoin(condition=[AND(<>($3, $13), =($4, $14))], joinType=[inner])
         HiveProject(cs_ship_date_sk=[$2], cs_ship_addr_sk=[$3], cs_call_center_sk=[$4], cs_warehouse_sk=[$5], cs_order_number=[$6], cs_ext_ship_cost=[$7], cs_net_profit=[$8], d_date_sk=[$9], d_date=[$10], ca_address_sk=[$0], ca_state=[$1], cc_call_center_sk=[$11], cc_county=[$12])
           HiveJoin(condition=[=($4, $11)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -94,7 +94,7 @@ HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[su
         HiveProject(cs_warehouse_sk=[$14], cs_order_number=[$17])
           HiveFilter(condition=[AND(IS NOT NULL($14), IS NOT NULL($17))])
             HiveTableScan(table=[[default, catalog_sales]], table:alias=[cs2])
-      HiveProject(cr_order_number0=[$0], $f1=[true])
+      HiveProject(literalTrue=[true], cr_order_number0=[$0])
         HiveAggregate(group=[{16}])
           HiveFilter(condition=[IS NOT NULL($16)])
             HiveTableScan(table=[[default, catalog_returns]], table:alias=[cr1])
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query35.q.out b/ql/src/test/results/clientpositive/perf/tez/cbo_query35.q.out
index 7c7bce9..dcfc53b 100644
--- a/ql/src/test/results/clientpositive/perf/tez/cbo_query35.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query35.q.out
@@ -131,9 +131,9 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
   HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$17], sort4=[$7], sort5=[$12], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], dir5=[ASC], fetch=[100])
     HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$6], _o__c4=[/(CAST($7):DOUBLE, $8)], _o__c5=[$9], _o__c6=[$7], cd_dep_employed_count=[$4], cnt2=[$6], _o__c9=[/(CAST($10):DOUBLE, $11)], _o__c10=[$12], _o__c11=[$10], cd_dep_college_count=[$5], cnt3=[$6], _o__c14=[/(CAST($13):DOUBLE, $14)], _o__c15=[$15], _o__c16=[$13], (tok_table_or_col cd_dep_count)=[$3])
       HiveAggregate(group=[{4, 6, 7, 8, 9, 10}], agg#0=[count()], agg#1=[sum($8)], agg#2=[count($8)], agg#3=[max($8)], agg#4=[sum($9)], agg#5=[count($9)], agg#6=[max($9)], agg#7=[sum($10)], agg#8=[count($10)], agg#9=[max($10)])
-        HiveFilter(condition=[OR(IS NOT NULL($12), IS NOT NULL($14))])
-          HiveJoin(condition=[=($0, $13)], joinType=[left], algorithm=[none], cost=[not available])
-            HiveJoin(condition=[=($0, $11)], joinType=[left], algorithm=[none], cost=[not available])
+        HiveFilter(condition=[OR(IS NOT NULL($11), IS NOT NULL($13))])
+          HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+            HiveJoin(condition=[=($0, $12)], joinType=[left], algorithm=[none], cost=[not available])
               HiveSemiJoin(condition=[=($0, $11)], joinType=[inner])
                 HiveJoin(condition=[=($5, $1)], joinType=[inner], algorithm=[none], cost=[not available])
                   HiveJoin(condition=[=($2, $3)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -154,7 +154,7 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
                     HiveProject(d_date_sk=[$0])
                       HiveFilter(condition=[AND(=($6, 1999), <($10, 4), IS NOT NULL($0))])
                         HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-              HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+              HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
                 HiveAggregate(group=[{1}])
                   HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                     HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -163,7 +163,7 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
                     HiveProject(d_date_sk=[$0])
                       HiveFilter(condition=[AND(=($6, 1999), <($10, 4), IS NOT NULL($0))])
                         HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-            HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+            HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
               HiveAggregate(group=[{1}])
                 HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                   HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out b/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
index de7353d..f0cca27 100644
--- a/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
@@ -110,11 +110,11 @@ CBO PLAN:
 HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], fetch=[100])
   HiveProject(cd_gender=[$0], cd_marital_status=[$1], cd_education_status=[$2], cnt1=[$5], cd_purchase_estimate=[$3], cnt2=[$5], cd_credit_rating=[$4], cnt3=[$5])
     HiveAggregate(group=[{6, 7, 8, 9, 10}], agg#0=[count()])
-      HiveFilter(condition=[IS NULL($14)])
-        HiveJoin(condition=[=($0, $13)], joinType=[left], algorithm=[none], cost=[not available])
-          HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], c_current_addr_sk=[$2], ca_address_sk=[$3], ca_state=[$4], cd_demo_sk=[$5], cd_gender=[$6], cd_marital_status=[$7], cd_education_status=[$8], cd_purchase_estimate=[$9], cd_credit_rating=[$10], ws_bill_customer_sk0=[$11], $f1=[$12])
-            HiveFilter(condition=[IS NULL($12)])
-              HiveJoin(condition=[=($0, $11)], joinType=[left], algorithm=[none], cost=[not available])
+      HiveFilter(condition=[IS NULL($13)])
+        HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+          HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], c_current_addr_sk=[$2], ca_address_sk=[$3], ca_state=[$4], cd_demo_sk=[$5], cd_gender=[$6], cd_marital_status=[$7], cd_education_status=[$8], cd_purchase_estimate=[$9], cd_credit_rating=[$10], literalTrue=[$11], ws_bill_customer_sk0=[$12])
+            HiveFilter(condition=[IS NULL($11)])
+              HiveJoin(condition=[=($0, $12)], joinType=[left], algorithm=[none], cost=[not available])
                 HiveSemiJoin(condition=[=($0, $11)], joinType=[inner])
                   HiveJoin(condition=[=($5, $1)], joinType=[inner], algorithm=[none], cost=[not available])
                     HiveJoin(condition=[=($2, $3)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -135,7 +135,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[
                       HiveProject(d_date_sk=[$0])
                         HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, $8, 1, 3), IS NOT NULL($0))])
                           HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-                HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+                HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
                   HiveAggregate(group=[{1}])
                     HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                       HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -144,7 +144,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[
                       HiveProject(d_date_sk=[$0])
                         HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, $8, 1, 3), IS NOT NULL($0))])
                           HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-          HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+          HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
             HiveAggregate(group=[{1}])
               HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query94.q.out b/ql/src/test/results/clientpositive/perf/tez/cbo_query94.q.out
index 5649216..5cf486f 100644
--- a/ql/src/test/results/clientpositive/perf/tez/cbo_query94.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query94.q.out
@@ -68,8 +68,8 @@ POSTHOOK: Input: default@web_site
 POSTHOOK: Output: hdfs://### HDFS PATH ###
 CBO PLAN:
 HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[sum($6)])
-  HiveFilter(condition=[IS NULL($14)])
-    HiveJoin(condition=[=($4, $13)], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[IS NULL($13)])
+    HiveJoin(condition=[=($4, $14)], joinType=[left], algorithm=[none], cost=[not available])
       HiveSemiJoin(condition=[AND(<>($3, $13), =($4, $14))], joinType=[inner])
         HiveProject(ws_ship_date_sk=[$2], ws_ship_addr_sk=[$3], ws_web_site_sk=[$4], ws_warehouse_sk=[$5], ws_order_number=[$6], ws_ext_ship_cost=[$7], ws_net_profit=[$8], d_date_sk=[$9], d_date=[$10], ca_address_sk=[$0], ca_state=[$1], web_site_sk=[$11], web_company_name=[$12])
           HiveJoin(condition=[=($4, $11)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -90,7 +90,7 @@ HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[su
         HiveProject(ws_warehouse_sk=[$15], ws_order_number=[$17])
           HiveFilter(condition=[AND(IS NOT NULL($15), IS NOT NULL($17))])
             HiveTableScan(table=[[default, web_sales]], table:alias=[ws2])
-      HiveProject(wr_order_number0=[$0], $f1=[true])
+      HiveProject(literalTrue=[true], wr_order_number0=[$0])
         HiveAggregate(group=[{13}])
           HiveFilter(condition=[IS NOT NULL($13)])
             HiveTableScan(table=[[default, web_returns]], table:alias=[wr1])
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query10.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query10.q.out
index fe33192..2427cbd 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query10.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query10.q.out
@@ -134,9 +134,9 @@ CBO PLAN:
 HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=[$8], sort6=[$10], sort7=[$12], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], dir5=[ASC], dir6=[ASC], dir7=[ASC], fetch=[100])
   HiveProject(cd_gender=[$0], cd_marital_status=[$1], cd_education_status=[$2], cnt1=[$8], cd_purchase_estimate=[$3], cnt2=[$8], cd_credit_rating=[$4], cnt3=[$8], cd_dep_count=[$5], cnt4=[$8], cd_dep_employed_count=[$6], cnt5=[$8], cd_dep_college_count=[$7], cnt6=[$8])
     HiveAggregate(group=[{6, 7, 8, 9, 10, 11, 12, 13}], agg#0=[count()])
-      HiveFilter(condition=[OR(IS NOT NULL($15), IS NOT NULL($17))])
-        HiveJoin(condition=[=($0, $16)], joinType=[left], algorithm=[none], cost=[not available])
-          HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+      HiveFilter(condition=[OR(IS NOT NULL($14), IS NOT NULL($16))])
+        HiveJoin(condition=[=($0, $17)], joinType=[left], algorithm=[none], cost=[not available])
+          HiveJoin(condition=[=($0, $15)], joinType=[left], algorithm=[none], cost=[not available])
             HiveSemiJoin(condition=[=($0, $14)], joinType=[inner])
               HiveJoin(condition=[=($5, $1)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveJoin(condition=[=($2, $3)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -156,7 +156,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=
                   HiveProject(d_date_sk=[$0])
                     HiveFilter(condition=[AND(=($6, 2002), BETWEEN(false, $8, 4, 7))])
                       HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-            HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+            HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
               HiveAggregate(group=[{1}])
                 HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                   HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -165,7 +165,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], sort5=
                   HiveProject(d_date_sk=[$0])
                     HiveFilter(condition=[AND(=($6, 2002), BETWEEN(false, $8, 4, 7))])
                       HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-          HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+          HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
             HiveAggregate(group=[{1}])
               HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query16.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query16.q.out
index 01373c7..13c6477 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query16.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query16.q.out
@@ -72,8 +72,8 @@ POSTHOOK: Input: default@date_dim
 POSTHOOK: Output: hdfs://### HDFS PATH ###
 CBO PLAN:
 HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[sum($6)])
-  HiveFilter(condition=[IS NULL($14)])
-    HiveJoin(condition=[=($4, $13)], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[IS NULL($13)])
+    HiveJoin(condition=[=($4, $14)], joinType=[left], algorithm=[none], cost=[not available])
       HiveSemiJoin(condition=[AND(<>($3, $13), =($4, $14))], joinType=[inner])
         HiveProject(cs_ship_date_sk=[$2], cs_ship_addr_sk=[$3], cs_call_center_sk=[$4], cs_warehouse_sk=[$5], cs_order_number=[$6], cs_ext_ship_cost=[$7], cs_net_profit=[$8], d_date_sk=[$9], d_date=[$10], ca_address_sk=[$0], ca_state=[$1], cc_call_center_sk=[$11], cc_county=[$12])
           HiveJoin(condition=[=($4, $11)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -94,7 +94,7 @@ HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[su
         HiveProject(cs_warehouse_sk=[$14], cs_order_number=[$17])
           HiveFilter(condition=[IS NOT NULL($14)])
             HiveTableScan(table=[[default, catalog_sales]], table:alias=[cs2])
-      HiveProject(cr_order_number0=[$0], $f1=[true])
+      HiveProject(literalTrue=[true], cr_order_number0=[$0])
         HiveAggregate(group=[{16}])
           HiveTableScan(table=[[default, catalog_returns]], table:alias=[cr1])
 
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query35.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query35.q.out
index 174d640..d3d6658 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query35.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query35.q.out
@@ -131,9 +131,9 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
   HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$17], sort4=[$7], sort5=[$12], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], dir5=[ASC], fetch=[100])
     HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$6], _o__c4=[/(CAST($7):DOUBLE, $8)], _o__c5=[$9], _o__c6=[$7], cd_dep_employed_count=[$4], cnt2=[$6], _o__c9=[/(CAST($10):DOUBLE, $11)], _o__c10=[$12], _o__c11=[$10], cd_dep_college_count=[$5], cnt3=[$6], _o__c14=[/(CAST($13):DOUBLE, $14)], _o__c15=[$15], _o__c16=[$13], (tok_table_or_col cd_dep_count)=[$3])
       HiveAggregate(group=[{4, 6, 7, 8, 9, 10}], agg#0=[count()], agg#1=[sum($8)], agg#2=[count($8)], agg#3=[max($8)], agg#4=[sum($9)], agg#5=[count($9)], agg#6=[max($9)], agg#7=[sum($10)], agg#8=[count($10)], agg#9=[max($10)])
-        HiveFilter(condition=[OR(IS NOT NULL($12), IS NOT NULL($14))])
-          HiveJoin(condition=[=($0, $13)], joinType=[left], algorithm=[none], cost=[not available])
-            HiveJoin(condition=[=($0, $11)], joinType=[left], algorithm=[none], cost=[not available])
+        HiveFilter(condition=[OR(IS NOT NULL($11), IS NOT NULL($13))])
+          HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+            HiveJoin(condition=[=($0, $12)], joinType=[left], algorithm=[none], cost=[not available])
               HiveSemiJoin(condition=[=($0, $11)], joinType=[inner])
                 HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], c_current_addr_sk=[$2], ca_address_sk=[$9], ca_state=[$10], cd_demo_sk=[$3], cd_gender=[$4], cd_marital_status=[$5], cd_dep_count=[$6], cd_dep_employed_count=[$7], cd_dep_college_count=[$8])
                   HiveJoin(condition=[=($2, $9)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -153,7 +153,7 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
                     HiveProject(d_date_sk=[$0])
                       HiveFilter(condition=[AND(=($6, 1999), <($10, 4))])
                         HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-              HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+              HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
                 HiveAggregate(group=[{1}])
                   HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                     HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -162,7 +162,7 @@ HiveProject(ca_state=[$0], cd_gender=[$1], cd_marital_status=[$2], cnt1=[$3], _o
                     HiveProject(d_date_sk=[$0])
                       HiveFilter(condition=[AND(=($6, 1999), <($10, 4))])
                         HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-            HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+            HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
               HiveAggregate(group=[{1}])
                 HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                   HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query69.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query69.q.out
index 933967e..5b739ce 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query69.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query69.q.out
@@ -110,11 +110,11 @@ CBO PLAN:
 HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], fetch=[100])
   HiveProject(cd_gender=[$0], cd_marital_status=[$1], cd_education_status=[$2], cnt1=[$5], cd_purchase_estimate=[$3], cnt2=[$5], cd_credit_rating=[$4], cnt3=[$5])
     HiveAggregate(group=[{6, 7, 8, 9, 10}], agg#0=[count()])
-      HiveFilter(condition=[IS NULL($14)])
-        HiveJoin(condition=[=($0, $13)], joinType=[left], algorithm=[none], cost=[not available])
-          HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], c_current_addr_sk=[$2], ca_address_sk=[$3], ca_state=[$4], cd_demo_sk=[$5], cd_gender=[$6], cd_marital_status=[$7], cd_education_status=[$8], cd_purchase_estimate=[$9], cd_credit_rating=[$10], ws_bill_customer_sk0=[$11], $f1=[$12])
-            HiveFilter(condition=[IS NULL($12)])
-              HiveJoin(condition=[=($0, $11)], joinType=[left], algorithm=[none], cost=[not available])
+      HiveFilter(condition=[IS NULL($13)])
+        HiveJoin(condition=[=($0, $14)], joinType=[left], algorithm=[none], cost=[not available])
+          HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], c_current_addr_sk=[$2], ca_address_sk=[$3], ca_state=[$4], cd_demo_sk=[$5], cd_gender=[$6], cd_marital_status=[$7], cd_education_status=[$8], cd_purchase_estimate=[$9], cd_credit_rating=[$10], literalTrue=[$11], ws_bill_customer_sk0=[$12])
+            HiveFilter(condition=[IS NULL($11)])
+              HiveJoin(condition=[=($0, $12)], joinType=[left], algorithm=[none], cost=[not available])
                 HiveSemiJoin(condition=[=($0, $11)], joinType=[inner])
                   HiveJoin(condition=[=($5, $1)], joinType=[inner], algorithm=[none], cost=[not available])
                     HiveJoin(condition=[=($2, $3)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -134,7 +134,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[
                       HiveProject(d_date_sk=[$0])
                         HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, $8, 1, 3))])
                           HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-                HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+                HiveProject(literalTrue=[true], ws_bill_customer_sk0=[$0])
                   HiveAggregate(group=[{1}])
                     HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                       HiveProject(ws_sold_date_sk=[$0], ws_bill_customer_sk=[$4])
@@ -143,7 +143,7 @@ HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], dir0=[
                       HiveProject(d_date_sk=[$0])
                         HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, $8, 1, 3))])
                           HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
-          HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+          HiveProject(literalTrue=[true], cs_ship_customer_sk0=[$0])
             HiveAggregate(group=[{1}])
               HiveJoin(condition=[=($0, $2)], joinType=[inner], algorithm=[none], cost=[not available])
                 HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query94.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query94.q.out
index 8cf1329..8efda1e 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query94.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query94.q.out
@@ -68,8 +68,8 @@ POSTHOOK: Input: default@web_site
 POSTHOOK: Output: hdfs://### HDFS PATH ###
 CBO PLAN:
 HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[sum($6)])
-  HiveFilter(condition=[IS NULL($14)])
-    HiveJoin(condition=[=($4, $13)], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[IS NULL($13)])
+    HiveJoin(condition=[=($4, $14)], joinType=[left], algorithm=[none], cost=[not available])
       HiveSemiJoin(condition=[AND(<>($3, $13), =($4, $14))], joinType=[inner])
         HiveProject(ws_ship_date_sk=[$2], ws_ship_addr_sk=[$3], ws_web_site_sk=[$4], ws_warehouse_sk=[$5], ws_order_number=[$6], ws_ext_ship_cost=[$7], ws_net_profit=[$8], d_date_sk=[$9], d_date=[$10], ca_address_sk=[$0], ca_state=[$1], web_site_sk=[$11], web_company_name=[$12])
           HiveJoin(condition=[=($4, $11)], joinType=[inner], algorithm=[none], cost=[not available])
@@ -90,7 +90,7 @@ HiveAggregate(group=[{}], agg#0=[count(DISTINCT $4)], agg#1=[sum($5)], agg#2=[su
         HiveProject(ws_warehouse_sk=[$15], ws_order_number=[$17])
           HiveFilter(condition=[IS NOT NULL($15)])
             HiveTableScan(table=[[default, web_sales]], table:alias=[ws2])
-      HiveProject(wr_order_number0=[$0], $f1=[true])
+      HiveProject(literalTrue=[true], wr_order_number0=[$0])
         HiveAggregate(group=[{13}])
           HiveTableScan(table=[[default, web_returns]], table:alias=[wr1])
 
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/query10.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/query10.q.out
index 4602033..4173308 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/query10.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/query10.q.out
@@ -178,14 +178,14 @@ Stage-0
                         Select Operator [SEL_64] (rows=52 width=379)
                           Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13"]
                           Filter Operator [FIL_63] (rows=52 width=379)
-                            predicate:(_col15 is not null or _col17 is not null)
+                            predicate:(_col14 is not null or _col16 is not null)
                             Merge Join Operator [MERGEJOIN_180] (rows=52 width=379)
-                              Conds:RS_60._col0=RS_217._col0(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col15","_col17"]
+                              Conds:RS_60._col0=RS_217._col1(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col14","_col16"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_60]
                                 PartitionCols:_col0
                                 Merge Join Operator [MERGEJOIN_179] (rows=53 width=379)
-                                  Conds:RS_57._col0=RS_209._col0(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col15"]
+                                  Conds:RS_57._col0=RS_209._col1(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col14"]
                                 <-Reducer 4 [ONE_TO_ONE_EDGE]
                                   FORWARD [RS_57]
                                     PartitionCols:_col0
@@ -266,7 +266,7 @@ Stage-0
                                                       default@customer_address,ca,Tbl:COMPLETE,Col:COMPLETE,Output:["ca_address_sk","ca_county"]
                                 <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                   FORWARD [RS_209]
-                                    PartitionCols:_col0
+                                    PartitionCols:_col1
                                     Select Operator [SEL_208] (rows=155749 width=7)
                                       Output:["_col0","_col1"]
                                       Group By Operator [GBY_207] (rows=155749 width=3)
@@ -304,7 +304,7 @@ Stage-0
                                                                  Please refer to the previous Merge Join Operator [MERGEJOIN_178]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_217]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_216] (rows=153181 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_215] (rows=153181 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/query16.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/query16.q.out
index 2465e51..2289382 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/query16.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/query16.q.out
@@ -108,12 +108,12 @@ Stage-0
                     Select Operator [SEL_41] (rows=5150256 width=214)
                       Output:["_col4","_col5","_col6"]
                       Filter Operator [FIL_40] (rows=5150256 width=214)
-                        predicate:_col14 is null
+                        predicate:_col13 is null
                         Merge Join Operator [MERGEJOIN_125] (rows=10300512 width=214)
-                          Conds:RS_37._col4=RS_153._col0(Left Outer),Output:["_col4","_col5","_col6","_col14"]
+                          Conds:RS_37._col4=RS_153._col1(Left Outer),Output:["_col4","_col5","_col6","_col13"]
                         <-Reducer 16 [ONE_TO_ONE_EDGE] vectorized
                           FORWARD [RS_153]
-                            PartitionCols:_col0
+                            PartitionCols:_col1
                             Select Operator [SEL_152] (rows=18238808 width=8)
                               Output:["_col0","_col1"]
                               Group By Operator [GBY_151] (rows=18238808 width=4)
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/query35.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/query35.q.out
index 85fdceb..81d42d9 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/query35.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/query35.q.out
@@ -174,14 +174,14 @@ Stage-0
                         Select Operator [SEL_64] (rows=61 width=276)
                           Output:["_col4","_col6","_col7","_col8","_col9","_col10"]
                           Filter Operator [FIL_63] (rows=61 width=276)
-                            predicate:(_col12 is not null or _col14 is not null)
+                            predicate:(_col11 is not null or _col13 is not null)
                             Merge Join Operator [MERGEJOIN_181] (rows=61 width=276)
-                              Conds:RS_60._col0=RS_217._col0(Left Outer),Output:["_col4","_col6","_col7","_col8","_col9","_col10","_col12","_col14"]
+                              Conds:RS_60._col0=RS_217._col1(Left Outer),Output:["_col4","_col6","_col7","_col8","_col9","_col10","_col11","_col13"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_60]
                                 PartitionCols:_col0
                                 Merge Join Operator [MERGEJOIN_180] (rows=62 width=276)
-                                  Conds:RS_57._col0=RS_209._col0(Left Outer),Output:["_col0","_col4","_col6","_col7","_col8","_col9","_col10","_col12"]
+                                  Conds:RS_57._col0=RS_209._col1(Left Outer),Output:["_col0","_col4","_col6","_col7","_col8","_col9","_col10","_col11"]
                                 <-Reducer 4 [ONE_TO_ONE_EDGE]
                                   FORWARD [RS_57]
                                     PartitionCols:_col0
@@ -262,7 +262,7 @@ Stage-0
                                                       default@customer_demographics,customer_demographics,Tbl:COMPLETE,Col:COMPLETE,Output:["cd_demo_sk","cd_gender","cd_marital_status","cd_dep_count","cd_dep_employed_count","cd_dep_college_count"]
                                 <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                   FORWARD [RS_209]
-                                    PartitionCols:_col0
+                                    PartitionCols:_col1
                                     Select Operator [SEL_208] (rows=168147 width=7)
                                       Output:["_col0","_col1"]
                                       Group By Operator [GBY_207] (rows=168147 width=3)
@@ -300,7 +300,7 @@ Stage-0
                                                                  Please refer to the previous Merge Join Operator [MERGEJOIN_179]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_217]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_216] (rows=165374 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_215] (rows=165374 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/query69.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/query69.q.out
index b7cbd87..6cff1c3 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/query69.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/query69.q.out
@@ -154,18 +154,18 @@ Stage-0
                         Select Operator [SEL_66] (rows=1 width=363)
                           Output:["_col6","_col7","_col8","_col9","_col10"]
                           Filter Operator [FIL_65] (rows=1 width=363)
-                            predicate:_col14 is null
+                            predicate:_col13 is null
                             Merge Join Operator [MERGEJOIN_183] (rows=1 width=363)
-                              Conds:RS_62._col0=RS_220._col0(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col14"]
+                              Conds:RS_62._col0=RS_220._col1(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col13"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_62]
                                 PartitionCols:_col0
                                 Select Operator [SEL_47] (rows=1 width=367)
                                   Output:["_col0","_col6","_col7","_col8","_col9","_col10"]
                                   Filter Operator [FIL_46] (rows=1 width=367)
-                                    predicate:_col12 is null
+                                    predicate:_col11 is null
                                     Merge Join Operator [MERGEJOIN_182] (rows=30 width=367)
-                                      Conds:RS_43._col0=RS_212._col0(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col12"]
+                                      Conds:RS_43._col0=RS_212._col1(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11"]
                                     <-Reducer 4 [ONE_TO_ONE_EDGE]
                                       FORWARD [RS_43]
                                         PartitionCols:_col0
@@ -246,7 +246,7 @@ Stage-0
                                                           default@customer_address,ca,Tbl:COMPLETE,Col:COMPLETE,Output:["ca_address_sk","ca_state"]
                                     <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                       FORWARD [RS_212]
-                                        PartitionCols:_col0
+                                        PartitionCols:_col1
                                         Select Operator [SEL_211] (rows=116231 width=7)
                                           Output:["_col0","_col1"]
                                           Group By Operator [GBY_210] (rows=116231 width=3)
@@ -284,7 +284,7 @@ Stage-0
                                                                      Please refer to the previous Merge Join Operator [MERGEJOIN_181]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_220]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_219] (rows=114314 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_218] (rows=114314 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/query94.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/query94.q.out
index d67f208..a384d34 100644
--- a/ql/src/test/results/clientpositive/perf/tez/constraints/query94.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/query94.q.out
@@ -104,12 +104,12 @@ Stage-0
                     Select Operator [SEL_41] (rows=5022875 width=229)
                       Output:["_col4","_col5","_col6"]
                       Filter Operator [FIL_40] (rows=5022875 width=229)
-                        predicate:_col14 is null
+                        predicate:_col13 is null
                         Merge Join Operator [MERGEJOIN_125] (rows=10045750 width=229)
-                          Conds:RS_37._col4=RS_153._col0(Left Outer),Output:["_col4","_col5","_col6","_col14"]
+                          Conds:RS_37._col4=RS_153._col1(Left Outer),Output:["_col4","_col5","_col6","_col13"]
                         <-Reducer 16 [ONE_TO_ONE_EDGE] vectorized
                           FORWARD [RS_153]
-                            PartitionCols:_col0
+                            PartitionCols:_col1
                             Select Operator [SEL_152] (rows=8007986 width=8)
                               Output:["_col0","_col1"]
                               Group By Operator [GBY_151] (rows=8007986 width=4)
diff --git a/ql/src/test/results/clientpositive/perf/tez/query10.q.out b/ql/src/test/results/clientpositive/perf/tez/query10.q.out
index 7c5e00e..5bfaf06 100644
--- a/ql/src/test/results/clientpositive/perf/tez/query10.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/query10.q.out
@@ -178,14 +178,14 @@ Stage-0
                         Select Operator [SEL_65] (rows=52 width=379)
                           Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13"]
                           Filter Operator [FIL_64] (rows=52 width=379)
-                            predicate:(_col15 is not null or _col17 is not null)
+                            predicate:(_col14 is not null or _col16 is not null)
                             Merge Join Operator [MERGEJOIN_181] (rows=52 width=379)
-                              Conds:RS_61._col0=RS_219._col0(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col15","_col17"]
+                              Conds:RS_61._col0=RS_219._col1(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col14","_col16"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_61]
                                 PartitionCols:_col0
                                 Merge Join Operator [MERGEJOIN_180] (rows=53 width=379)
-                                  Conds:RS_58._col0=RS_211._col0(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col15"]
+                                  Conds:RS_58._col0=RS_211._col1(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11","_col12","_col13","_col14"]
                                 <-Reducer 4 [ONE_TO_ONE_EDGE]
                                   FORWARD [RS_58]
                                     PartitionCols:_col0
@@ -268,7 +268,7 @@ Stage-0
                                                       default@customer_address,ca,Tbl:COMPLETE,Col:COMPLETE,Output:["ca_address_sk","ca_county"]
                                 <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                   FORWARD [RS_211]
-                                    PartitionCols:_col0
+                                    PartitionCols:_col1
                                     Select Operator [SEL_210] (rows=155749 width=7)
                                       Output:["_col0","_col1"]
                                       Group By Operator [GBY_209] (rows=155749 width=3)
@@ -306,7 +306,7 @@ Stage-0
                                                                  Please refer to the previous Merge Join Operator [MERGEJOIN_179]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_219]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_218] (rows=153181 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_217] (rows=153181 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/query16.q.out b/ql/src/test/results/clientpositive/perf/tez/query16.q.out
index 3be01b4..8c5fa39 100644
--- a/ql/src/test/results/clientpositive/perf/tez/query16.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/query16.q.out
@@ -108,12 +108,12 @@ Stage-0
                     Select Operator [SEL_42] (rows=5150256 width=214)
                       Output:["_col4","_col5","_col6"]
                       Filter Operator [FIL_41] (rows=5150256 width=214)
-                        predicate:_col14 is null
+                        predicate:_col13 is null
                         Merge Join Operator [MERGEJOIN_126] (rows=10300512 width=214)
-                          Conds:RS_38._col4=RS_155._col0(Left Outer),Output:["_col4","_col5","_col6","_col14"]
+                          Conds:RS_38._col4=RS_155._col1(Left Outer),Output:["_col4","_col5","_col6","_col13"]
                         <-Reducer 16 [ONE_TO_ONE_EDGE] vectorized
                           FORWARD [RS_155]
-                            PartitionCols:_col0
+                            PartitionCols:_col1
                             Select Operator [SEL_154] (rows=18238808 width=8)
                               Output:["_col0","_col1"]
                               Group By Operator [GBY_153] (rows=18238808 width=4)
diff --git a/ql/src/test/results/clientpositive/perf/tez/query35.q.out b/ql/src/test/results/clientpositive/perf/tez/query35.q.out
index ad92953..9c90dd8 100644
--- a/ql/src/test/results/clientpositive/perf/tez/query35.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/query35.q.out
@@ -174,14 +174,14 @@ Stage-0
                         Select Operator [SEL_65] (rows=61 width=276)
                           Output:["_col4","_col6","_col7","_col8","_col9","_col10"]
                           Filter Operator [FIL_64] (rows=61 width=276)
-                            predicate:(_col12 is not null or _col14 is not null)
+                            predicate:(_col11 is not null or _col13 is not null)
                             Merge Join Operator [MERGEJOIN_182] (rows=61 width=276)
-                              Conds:RS_61._col0=RS_220._col0(Left Outer),Output:["_col4","_col6","_col7","_col8","_col9","_col10","_col12","_col14"]
+                              Conds:RS_61._col0=RS_220._col1(Left Outer),Output:["_col4","_col6","_col7","_col8","_col9","_col10","_col11","_col13"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_61]
                                 PartitionCols:_col0
                                 Merge Join Operator [MERGEJOIN_181] (rows=62 width=276)
-                                  Conds:RS_58._col0=RS_212._col0(Left Outer),Output:["_col0","_col4","_col6","_col7","_col8","_col9","_col10","_col12"]
+                                  Conds:RS_58._col0=RS_212._col1(Left Outer),Output:["_col0","_col4","_col6","_col7","_col8","_col9","_col10","_col11"]
                                 <-Reducer 4 [ONE_TO_ONE_EDGE]
                                   FORWARD [RS_58]
                                     PartitionCols:_col0
@@ -264,7 +264,7 @@ Stage-0
                                                       default@customer_address,ca,Tbl:COMPLETE,Col:COMPLETE,Output:["ca_address_sk","ca_state"]
                                 <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                   FORWARD [RS_212]
-                                    PartitionCols:_col0
+                                    PartitionCols:_col1
                                     Select Operator [SEL_211] (rows=168147 width=7)
                                       Output:["_col0","_col1"]
                                       Group By Operator [GBY_210] (rows=168147 width=3)
@@ -302,7 +302,7 @@ Stage-0
                                                                  Please refer to the previous Merge Join Operator [MERGEJOIN_180]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_220]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_219] (rows=165374 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_218] (rows=165374 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/query69.q.out b/ql/src/test/results/clientpositive/perf/tez/query69.q.out
index abe5e61..c9e4a03 100644
--- a/ql/src/test/results/clientpositive/perf/tez/query69.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/query69.q.out
@@ -154,18 +154,18 @@ Stage-0
                         Select Operator [SEL_67] (rows=1 width=363)
                           Output:["_col6","_col7","_col8","_col9","_col10"]
                           Filter Operator [FIL_66] (rows=1 width=363)
-                            predicate:_col14 is null
+                            predicate:_col13 is null
                             Merge Join Operator [MERGEJOIN_184] (rows=1 width=363)
-                              Conds:RS_63._col0=RS_222._col0(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col14"]
+                              Conds:RS_63._col0=RS_222._col1(Left Outer),Output:["_col6","_col7","_col8","_col9","_col10","_col13"]
                             <-Reducer 5 [ONE_TO_ONE_EDGE]
                               PARTITION_ONLY_SHUFFLE [RS_63]
                                 PartitionCols:_col0
                                 Select Operator [SEL_48] (rows=1 width=367)
                                   Output:["_col0","_col6","_col7","_col8","_col9","_col10"]
                                   Filter Operator [FIL_47] (rows=1 width=367)
-                                    predicate:_col12 is null
+                                    predicate:_col11 is null
                                     Merge Join Operator [MERGEJOIN_183] (rows=30 width=367)
-                                      Conds:RS_44._col0=RS_214._col0(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col12"]
+                                      Conds:RS_44._col0=RS_214._col1(Left Outer),Output:["_col0","_col6","_col7","_col8","_col9","_col10","_col11"]
                                     <-Reducer 4 [ONE_TO_ONE_EDGE]
                                       FORWARD [RS_44]
                                         PartitionCols:_col0
@@ -248,7 +248,7 @@ Stage-0
                                                           default@customer_address,ca,Tbl:COMPLETE,Col:COMPLETE,Output:["ca_address_sk","ca_state"]
                                     <-Reducer 18 [ONE_TO_ONE_EDGE] vectorized
                                       FORWARD [RS_214]
-                                        PartitionCols:_col0
+                                        PartitionCols:_col1
                                         Select Operator [SEL_213] (rows=116231 width=7)
                                           Output:["_col0","_col1"]
                                           Group By Operator [GBY_212] (rows=116231 width=3)
@@ -286,7 +286,7 @@ Stage-0
                                                                      Please refer to the previous Merge Join Operator [MERGEJOIN_182]
                             <-Reducer 20 [ONE_TO_ONE_EDGE] vectorized
                               FORWARD [RS_222]
-                                PartitionCols:_col0
+                                PartitionCols:_col1
                                 Select Operator [SEL_221] (rows=114314 width=7)
                                   Output:["_col0","_col1"]
                                   Group By Operator [GBY_220] (rows=114314 width=3)
diff --git a/ql/src/test/results/clientpositive/perf/tez/query94.q.out b/ql/src/test/results/clientpositive/perf/tez/query94.q.out
index f7739da..a69beb2 100644
--- a/ql/src/test/results/clientpositive/perf/tez/query94.q.out
+++ b/ql/src/test/results/clientpositive/perf/tez/query94.q.out
@@ -104,12 +104,12 @@ Stage-0
                     Select Operator [SEL_42] (rows=5022875 width=229)
                       Output:["_col4","_col5","_col6"]
                       Filter Operator [FIL_41] (rows=5022875 width=229)
-                        predicate:_col14 is null
+                        predicate:_col13 is null
                         Merge Join Operator [MERGEJOIN_126] (rows=10045750 width=229)
-                          Conds:RS_38._col4=RS_155._col0(Left Outer),Output:["_col4","_col5","_col6","_col14"]
+                          Conds:RS_38._col4=RS_155._col1(Left Outer),Output:["_col4","_col5","_col6","_col13"]
                         <-Reducer 16 [ONE_TO_ONE_EDGE] vectorized
                           FORWARD [RS_155]
-                            PartitionCols:_col0
+                            PartitionCols:_col1
                             Select Operator [SEL_154] (rows=8007986 width=8)
                               Output:["_col0","_col1"]
                               Group By Operator [GBY_153] (rows=8007986 width=4)
diff --git a/ql/src/test/results/clientpositive/spark/spark_explainuser_1.q.out b/ql/src/test/results/clientpositive/spark/spark_explainuser_1.q.out
index 24640b5..e3bf702 100644
--- a/ql/src/test/results/clientpositive/spark/spark_explainuser_1.q.out
+++ b/ql/src/test/results/clientpositive/spark/spark_explainuser_1.q.out
@@ -1971,9 +1971,9 @@ Stage-0
         Select Operator [SEL_18] (rows=500 width=178)
           Output:["_col0","_col1"]
           Filter Operator [FIL_17] (rows=500 width=178)
-            predicate:_col3 is null
+            predicate:_col2 is null
             Join Operator [JOIN_16] (rows=635 width=178)
-              Output:["_col0","_col1","_col3"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col1","1":"_col0"}
+              Output:["_col0","_col1","_col2"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col1","1":"_col1"}
             <-Map 1 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_14]
                 PartitionCols:_col1
@@ -1983,7 +1983,7 @@ Stage-0
                     default@src_cbo,b,Tbl:COMPLETE,Col:COMPLETE,Output:["key","value"]
             <-Reducer 4 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_15]
-                PartitionCols:_col0
+                PartitionCols:_col1
                 Select Operator [SEL_13] (rows=83 width=95)
                   Output:["_col0","_col1"]
                   Group By Operator [GBY_12] (rows=83 width=91)
@@ -2040,9 +2040,9 @@ Stage-0
         Select Operator [SEL_17] (rows=250 width=178)
           Output:["_col0","_col1"]
           Filter Operator [FIL_16] (rows=250 width=179)
-            predicate:_col4 is null
+            predicate:_col2 is null
             Join Operator [JOIN_15] (rows=333 width=179)
-              Output:["_col0","_col1","_col4"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col0, _col1"}
+              Output:["_col0","_col1","_col2"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col1, _col2"}
             <-Reducer 2 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_13]
                 PartitionCols:_col0, _col1
@@ -2059,7 +2059,7 @@ Stage-0
                           default@src_cbo,b,Tbl:COMPLETE,Col:COMPLETE,Output:["key","value"]
             <-Reducer 5 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_14]
-                PartitionCols:_col0, _col1
+                PartitionCols:_col1, _col2
                 Select Operator [SEL_12] (rows=83 width=182)
                   Output:["_col0","_col1","_col2"]
                   Group By Operator [GBY_11] (rows=83 width=178)
@@ -2594,9 +2594,9 @@ Stage-0
         Select Operator [SEL_23] (rows=41 width=223)
           Output:["_col0","_col1","_col2"]
           Filter Operator [FIL_22] (rows=41 width=229)
-            predicate:((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null))
+            predicate:((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null))
             Join Operator [JOIN_21] (rows=41 width=229)
-              Output:["_col0","_col1","_col2","_col4","_col5","_col8"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col0, _col1"}
+              Output:["_col0","_col1","_col2","_col4","_col5","_col7"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col0, _col2"}
             <-Reducer 2 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_19]
                 PartitionCols:_col0, _col1
@@ -2627,7 +2627,7 @@ Stage-0
                                 default@part,part,Tbl:COMPLETE,Col:COMPLETE,Output:["p_name","p_mfgr","p_size"]
             <-Reducer 7 [PARTITION-LEVEL SORT]
               PARTITION-LEVEL SORT [RS_20]
-                PartitionCols:_col0, _col1
+                PartitionCols:_col0, _col2
                 Select Operator [SEL_15] (rows=4 width=223)
                   Output:["_col0","_col1","_col2"]
                   Group By Operator [GBY_14] (rows=4 width=219)
@@ -2777,12 +2777,12 @@ Stage-0
             Select Operator [SEL_33] (rows=7 width=106)
               Output:["_col0","_col1"]
               Filter Operator [FIL_32] (rows=7 width=114)
-                predicate:((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null))
+                predicate:((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null))
                 Join Operator [JOIN_31] (rows=7 width=114)
-                  Output:["_col0","_col1","_col3","_col4","_col7"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col0, _col1"}
+                  Output:["_col0","_col1","_col3","_col4","_col6"],condition map:[{"":"{\"type\":\"Left Outer\",\"left\":0,\"right\":1}"}],keys:{"0":"_col0, _col1","1":"_col0, _col2"}
                 <-Reducer 10 [PARTITION-LEVEL SORT]
                   PARTITION-LEVEL SORT [RS_30]
-                    PartitionCols:_col0, _col1
+                    PartitionCols:_col0, _col2
                     Select Operator [SEL_25] (rows=1 width=110)
                       Output:["_col0","_col1","_col2"]
                       Filter Operator [FIL_24] (rows=1 width=114)
diff --git a/ql/src/test/results/clientpositive/spark/subquery_in.q.out b/ql/src/test/results/clientpositive/spark/subquery_in.q.out
index 7f72e9c..016e97f 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_in.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_in.q.out
@@ -4850,15 +4850,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col1 (type: bigint), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: bigint), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: bigint)
+                      key expressions: _col2 (type: string), _col0 (type: bigint)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: bigint)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: bigint)
                       Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -4905,11 +4905,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string), UDFToLong(_col5) (type: bigint)
-                  1 _col1 (type: string), _col0 (type: bigint)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: string), _col0 (type: bigint)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -5098,15 +5098,15 @@ STAGE PLANS:
                   predicate: (_col2 is not null and UDFToDouble(_col1) is not null) (type: boolean)
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: (UDFToDouble(_col1) / _col2) (type: double), _col0 (type: int), true (type: boolean)
+                    expressions: (UDFToDouble(_col1) / _col2) (type: double), true (type: boolean), _col0 (type: int)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: int), _col0 (type: double)
+                      key expressions: _col2 (type: int), _col0 (type: double)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: int), _col0 (type: double)
+                      Map-reduce partition columns: _col2 (type: int), _col0 (type: double)
                       Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -5153,11 +5153,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), UDFToDouble(_col5) (type: double)
-                  1 _col1 (type: int), _col0 (type: double)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: int), _col0 (type: double)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
diff --git a/ql/src/test/results/clientpositive/spark/subquery_multi.q.out b/ql/src/test/results/clientpositive/spark/subquery_multi.q.out
index fa606ce..ad95d2f 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_multi.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_multi.q.out
@@ -1718,8 +1718,8 @@ POSTHOOK: Input: default@part_null
 #### A masked pattern was here ####
 CBO PLAN:
 HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4], p_size=[$5], p_container=[$6], p_retailprice=[$7], p_comment=[$8])
-  HiveFilter(condition=[AND(OR(IS NULL($14), =($10, 0), IS NULL($10)), OR(IS NOT NULL($3), =($10, 0), IS NULL($10), IS NOT NULL($14)), OR(IS NOT TRUE(<($11, $10)), =($10, 0), IS NULL($10), IS NOT NULL($14), IS NULL($3)))])
-    HiveJoin(condition=[AND(=($3, $12), =($13, $4))], joinType=[left], algorithm=[none], cost=[not available])
+  HiveFilter(condition=[AND(OR(IS NULL($13), =($10, 0), IS NULL($10)), OR(IS NOT NULL($3), =($10, 0), IS NULL($10), IS NOT NULL($13)), OR(IS NOT TRUE(<($11, $10)), =($10, 0), IS NULL($10), IS NOT NULL($13), IS NULL($3)))])
+    HiveJoin(condition=[AND(=($3, $12), =($14, $4))], joinType=[left], algorithm=[none], cost=[not available])
       HiveJoin(condition=[=($9, $4)], joinType=[left], algorithm=[none], cost=[not available])
         HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4], p_size=[$5], p_container=[$6], p_retailprice=[$7], p_comment=[$8])
           HiveTableScan(table=[[default, part_null]], table:alias=[part_null])
@@ -1732,7 +1732,7 @@ HiveProject(p_partkey=[$0], p_name=[$1], p_mfgr=[$2], p_brand=[$3], p_type=[$4],
               HiveProject(p_brand=[$3], p_type=[$4])
                 HiveFilter(condition=[AND(IS NOT NULL($4), IS NOT NULL($3))])
                   HiveTableScan(table=[[default, part]], table:alias=[pp])
-      HiveProject(p_container=[$1], p_type=[$0], $f2=[true])
+      HiveProject(p_container=[$1], literalTrue=[true], p_type=[$0])
         HiveAggregate(group=[{1, 2}])
           HiveSemiJoin(condition=[AND(=($1, $4), =($0, $3))], joinType=[inner])
             HiveProject(p_brand=[$3], p_type=[$4], p_container=[$6])
@@ -1938,15 +1938,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -1986,11 +1986,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col4 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2458,15 +2458,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -2506,11 +2506,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col4 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2757,11 +2757,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col3 (type: string), _col5 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col3 is null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and (_col3 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col3 is null)) (type: boolean)
                   Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2798,15 +2798,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -4571,11 +4571,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10
+                  1 _col1 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col10 is null (type: boolean)
+                  predicate: _col9 is null (type: boolean)
                   Statistics: Num rows: 15 Data size: 1903 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -4597,15 +4597,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 1 Data size: 32560 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 1 Data size: 32560 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 1 Data size: 32560 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/spark/subquery_notin.q.out b/ql/src/test/results/clientpositive/spark/subquery_notin.q.out
index e60a396..3828448 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_notin.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_notin.q.out
@@ -397,11 +397,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col0 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+                  1 _col0 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col1 (type: string), _col0 (type: string), _col2 (type: int)
@@ -532,15 +532,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: string)
+                    key expressions: _col0 (type: string), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
                     Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -1034,15 +1034,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 4 Data size: 484 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -1089,11 +1089,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
                 Statistics: Num rows: 9 Data size: 1345 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col2 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col2 is null) and (_col2 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 9 Data size: 1345 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col1 (type: string), _col0 (type: string), _col2 (type: int)
@@ -1776,11 +1776,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col4 (type: string), _col5 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col5 is null) and (_col5 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -1817,15 +1817,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col1 (type: string), _col0 (type: int)
+                    key expressions: _col2 (type: string), _col0 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                    Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -2465,11 +2465,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col3 (type: int)
-                outputColumnNames: _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col3 (type: int)
+                outputColumnNames: _col1, _col3, _col4, _col6
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
@@ -2522,7 +2522,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
@@ -2530,7 +2530,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: int)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 9 
             Reduce Operator Tree:
               Join Operator
@@ -2542,11 +2542,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
-                  key expressions: _col1 (type: string), _col3 (type: int)
+                  key expressions: _col2 (type: string), _col3 (type: int)
                   sort order: ++
-                  Map-reduce partition columns: _col1 (type: string), _col3 (type: int)
+                  Map-reduce partition columns: _col2 (type: string), _col3 (type: int)
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -2883,11 +2883,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col5 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col14
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col10, _col11, _col13
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col14 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col14 is not null or _col1 is null) and (_col1 is not null or (_col10 = 0L) or _col10 is null or _col14 is not null)) (type: boolean)
+                  predicate: ((_col13 is null or (_col10 = 0L) or _col10 is null) and ((_col11 < _col10) is not true or (_col10 = 0L) or _col10 is null or _col13 is not null or _col1 is null) and (_col1 is not null or (_col10 = 0L) or _col10 is null or _col13 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -2924,15 +2924,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 6 Data size: 726 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 6 Data size: 726 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 6 Data size: 726 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3043,15 +3043,15 @@ STAGE PLANS:
                     predicate: (p_size is not null and p_partkey is not null and p_name is not null) (type: boolean)
                     Statistics: Num rows: 26 Data size: 3147 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
-                      keys: p_partkey (type: int), p_name (type: string), p_size (type: int)
+                      keys: p_partkey (type: int), p_size (type: int), p_name (type: string)
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
                       Statistics: Num rows: 26 Data size: 3147 Basic stats: COMPLETE Column stats: NONE
                       Reduce Output Operator
-                        key expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int)
+                        key expressions: _col0 (type: int), _col1 (type: int), _col2 (type: string)
                         sort order: +++
-                        Map-reduce partition columns: _col0 (type: int), _col1 (type: string), _col2 (type: int)
+                        Map-reduce partition columns: _col0 (type: int), _col1 (type: int), _col2 (type: string)
                         Statistics: Num rows: 26 Data size: 3147 Basic stats: COMPLETE Column stats: NONE
             Execution mode: vectorized
         Reducer 2 
@@ -3065,9 +3065,9 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12
                 Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
-                  key expressions: _col0 (type: int), _col1 (type: string), _col5 (type: int)
+                  key expressions: _col0 (type: int), _col5 (type: int), _col1 (type: string)
                   sort order: +++
-                  Map-reduce partition columns: _col0 (type: int), _col1 (type: string), _col5 (type: int)
+                  Map-reduce partition columns: _col0 (type: int), _col5 (type: int), _col1 (type: string)
                   Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                   value expressions: _col2 (type: string), _col3 (type: string), _col4 (type: string), _col6 (type: string), _col7 (type: double), _col8 (type: string), _col11 (type: bigint), _col12 (type: bigint)
         Reducer 3 
@@ -3076,12 +3076,12 @@ STAGE PLANS:
                 condition map:
                      Left Outer Join 0 to 1
                 keys:
-                  0 _col0 (type: int), _col1 (type: string), _col5 (type: int)
-                  1 _col1 (type: int), _col0 (type: string), _col2 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12, _col16
+                  0 _col0 (type: int), _col5 (type: int), _col1 (type: string)
+                  1 _col2 (type: int), _col3 (type: int), _col0 (type: string)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col11, _col12, _col14
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col16 is null or (_col11 = 0L) or _col11 is null) and ((_col12 < _col11) is not true or (_col11 = 0L) or _col11 is null or _col16 is not null or _col1 is null) and (_col1 is not null or (_col11 = 0L) or _col11 is null or _col16 is not null)) (type: boolean)
+                  predicate: ((_col14 is null or (_col11 = 0L) or _col11 is null) and ((_col12 < _col11) is not true or (_col11 = 0L) or _col11 is null or _col14 is not null or _col1 is null) and (_col1 is not null or (_col11 = 0L) or _col11 is null or _col14 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: string), _col7 (type: double), _col8 (type: string)
@@ -3113,20 +3113,20 @@ STAGE PLANS:
             Execution mode: vectorized
             Reduce Operator Tree:
               Group By Operator
-                keys: KEY._col0 (type: int), KEY._col1 (type: string), KEY._col2 (type: int)
+                keys: KEY._col0 (type: int), KEY._col1 (type: int), KEY._col2 (type: string)
                 mode: mergepartial
                 outputColumnNames: _col0, _col1, _col2
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: int), _col2 (type: int), true (type: boolean)
+                  expressions: _col2 (type: string), true (type: boolean), _col0 (type: int), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2, _col3
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col1 (type: int), _col0 (type: string), _col2 (type: int)
+                    key expressions: _col2 (type: int), _col3 (type: int), _col0 (type: string)
                     sort order: +++
-                    Map-reduce partition columns: _col1 (type: int), _col0 (type: string), _col2 (type: int)
+                    Map-reduce partition columns: _col2 (type: int), _col3 (type: int), _col0 (type: string)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col3 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3255,11 +3255,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 UDFToDouble(_col1) (type: double), _col2 (type: string)
-                  1 _col0 (type: double), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  1 _col0 (type: double), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -3296,15 +3296,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: double), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: double), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: double), _col1 (type: string)
+                    key expressions: _col0 (type: double), _col2 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: double), _col1 (type: string)
+                    Map-reduce partition columns: _col0 (type: double), _col2 (type: string)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3457,15 +3457,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string), _col1 (type: int)
+                    key expressions: _col0 (type: string), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: string), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: string), _col2 (type: int)
                     Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 13 
             Execution mode: vectorized
             Reduce Operator Tree:
@@ -3502,11 +3502,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col0 (type: string), _col1 (type: int)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  1 _col0 (type: string), _col2 (type: int)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -4082,11 +4082,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
-                  1 _col1 (type: string), _col0 (type: string)
-                outputColumnNames: _col0, _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col0 (type: string)
+                outputColumnNames: _col0, _col1, _col3, _col4, _col6
                 Statistics: Num rows: 605 Data size: 6427 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 605 Data size: 6427 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -4164,15 +4164,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: string), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col1 (type: string), _col0 (type: string)
+                    key expressions: _col2 (type: string), _col0 (type: string)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: string), _col0 (type: string)
+                    Map-reduce partition columns: _col2 (type: string), _col0 (type: string)
                     Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -5537,11 +5537,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col3 (type: int)
-                outputColumnNames: _col1, _col3, _col4, _col7
+                  1 _col2 (type: string), _col3 (type: int)
+                outputColumnNames: _col1, _col3, _col4, _col6
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
@@ -5594,7 +5594,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: string), _col0 (type: string), true (type: boolean)
+                  expressions: _col1 (type: string), true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
@@ -5602,7 +5602,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: UDFToDouble(_col0) (type: double)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 9 
             Reduce Operator Tree:
               Join Operator
@@ -5614,11 +5614,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
-                  key expressions: _col1 (type: string), _col3 (type: int)
+                  key expressions: _col2 (type: string), _col3 (type: int)
                   sort order: ++
-                  Map-reduce partition columns: _col1 (type: string), _col3 (type: int)
+                  Map-reduce partition columns: _col2 (type: string), _col3 (type: int)
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -5976,15 +5976,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 2 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: char(100)), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: char(100))
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 2 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int), _col1 (type: char(100))
+                    key expressions: _col0 (type: int), _col2 (type: char(100))
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: int), _col1 (type: char(100))
+                    Map-reduce partition columns: _col0 (type: int), _col2 (type: char(100))
                     Statistics: Num rows: 1 Data size: 2 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
         Reducer 13 
             Execution mode: vectorized
             Reduce Operator Tree:
@@ -6026,11 +6026,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: char(100))
-                  1 _col0 (type: int), _col1 (type: char(100))
-                outputColumnNames: _col0, _col3, _col4, _col7
+                  1 _col0 (type: int), _col2 (type: char(100))
+                outputColumnNames: _col0, _col3, _col4, _col6
                 Statistics: Num rows: 4 Data size: 378 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 4 Data size: 378 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -6279,11 +6279,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: int)
-                  1 _col1 (type: int), _col0 (type: int)
-                outputColumnNames: _col0, _col1, _col3, _col4, _col7
+                  1 _col2 (type: int), _col0 (type: int)
+                outputColumnNames: _col0, _col1, _col3, _col4, _col6
                 Statistics: Num rows: 3 Data size: 9 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col1 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col1 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col1 is null)) (type: boolean)
                   Statistics: Num rows: 3 Data size: 9 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -6320,15 +6320,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), _col0 (type: int), true (type: boolean)
+                  expressions: _col1 (type: int), true (type: boolean), _col0 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col1 (type: int), _col0 (type: int)
+                    key expressions: _col2 (type: int), _col0 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col1 (type: int), _col0 (type: int)
+                    Map-reduce partition columns: _col2 (type: int), _col0 (type: int)
                     Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -6959,11 +6959,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: int), _col1 (type: int)
-                  1 _col0 (type: int), _col1 (type: int)
-                outputColumnNames: _col0, _col3, _col4, _col7
+                  1 _col0 (type: int), _col2 (type: int)
+                outputColumnNames: _col0, _col3, _col4, _col6
                 Statistics: Num rows: 3 Data size: 12 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 3 Data size: 12 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int)
@@ -7000,15 +7000,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: int), _col1 (type: int), true (type: boolean)
+                  expressions: _col0 (type: int), true (type: boolean), _col1 (type: int)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: int), _col1 (type: int)
+                    key expressions: _col0 (type: int), _col2 (type: int)
                     sort order: ++
-                    Map-reduce partition columns: _col0 (type: int), _col1 (type: int)
+                    Map-reduce partition columns: _col0 (type: int), _col2 (type: int)
                     Statistics: Num rows: 1 Data size: 3 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -7488,7 +7488,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 83 Data size: 881 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 83 Data size: 881 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
@@ -7496,7 +7496,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: string)
                     Statistics: Num rows: 83 Data size: 881 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -7522,10 +7522,10 @@ STAGE PLANS:
                   0 _col0 (type: string)
                   1 _col0 (type: string)
                 outputColumnNames: _col0, _col1, _col3, _col4, _col6, _col7
-                residual filter predicates: {(_col1 > _col6)}
+                residual filter predicates: {(_col1 > _col7)}
                 Statistics: Num rows: 8367 Data size: 186148 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+                  predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
                   Statistics: Num rows: 8367 Data size: 186148 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string), _col1 (type: string)
diff --git a/ql/src/test/results/clientpositive/spark/subquery_scalar.q.out b/ql/src/test/results/clientpositive/spark/subquery_scalar.q.out
index 9b62717..ff801a2 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_scalar.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_scalar.q.out
@@ -4985,15 +4985,15 @@ STAGE PLANS:
                   predicate: CASE WHEN (_col11 is null) THEN ((UDFToLong(_col2) <> 0L)) ELSE ((UDFToLong(_col2) <> _col10)) END (type: boolean)
                   Statistics: Num rows: 2 Data size: 104 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
-                    outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
+                    expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date), _col11 (type: boolean)
+                    outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col11
                     Statistics: Num rows: 2 Data size: 104 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col2 (type: int)
                       sort order: +
                       Map-reduce partition columns: _col2 (type: int)
                       Statistics: Num rows: 2 Data size: 104 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col0 (type: int), _col1 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
+                      value expressions: _col0 (type: int), _col1 (type: string), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date), _col11 (type: boolean)
         Reducer 3 
             Reduce Operator Tree:
               Join Operator
@@ -5001,11 +5001,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col2 (type: int)
-                  1 _col2 (type: int)
-                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col13, _col14
+                  1 _col1 (type: int)
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col11, _col13
                 Statistics: Num rows: 2 Data size: 114 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: CASE WHEN (_col14 is null) THEN ((UDFToLong(_col0) > 0L)) ELSE ((UDFToLong(_col0) > _col13)) END (type: boolean)
+                  predicate: CASE WHEN (_col11 is null) THEN ((UDFToLong(_col0) > 0L)) ELSE ((UDFToLong(_col0) > _col13)) END (type: boolean)
                   Statistics: Num rows: 1 Data size: 57 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: int), _col1 (type: string), _col2 (type: int), _col3 (type: string), _col4 (type: string), _col5 (type: int), _col6 (type: int), _col7 (type: boolean), _col8 (type: boolean), _col9 (type: date)
@@ -5047,15 +5047,15 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: bigint), true (type: boolean), _col0 (type: int)
-                  outputColumnNames: _col0, _col1, _col2
+                  expressions: _col1 (type: bigint), _col0 (type: int)
+                  outputColumnNames: _col0, _col1
                   Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col2 (type: int)
+                    key expressions: _col1 (type: int)
                     sort order: +
-                    Map-reduce partition columns: _col2 (type: int)
+                    Map-reduce partition columns: _col1 (type: int)
                     Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col0 (type: bigint), _col1 (type: boolean)
+                    value expressions: _col0 (type: bigint)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/spark/subquery_select.q.out b/ql/src/test/results/clientpositive/spark/subquery_select.q.out
index 38e1edc..f11819e 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_select.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_select.q.out
@@ -272,11 +272,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col9
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col8
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), ((_col9 is not null and (_col5 or _col4 is null) is not true) or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col9 is null)) (type: boolean)
+                  expressions: _col1 (type: int), ((_col8 is not null and (_col5 or _col4 is null) is not true) or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col8 is null)) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -324,15 +324,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -665,15 +665,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
         Reducer 2 
             Reduce Operator Tree:
               Join Operator
@@ -720,11 +720,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string), _col1 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col9
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col1, _col2, _col4, _col5, _col6, _col8
                 Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), ((_col5 or _col4 is null) is true or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col9 is null) or ((_col5 or _col4 is null) is not true and _col9 is null and (_col2 or _col6) is not true)) (type: boolean)
+                  expressions: _col1 (type: int), ((_col5 or _col4 is null) is true or ((_col2 or _col6) is true and null and (_col5 or _col4 is null) is not true and _col8 is null) or ((_col5 or _col4 is null) is not true and _col8 is null and (_col2 or _col6) is not true)) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 14 Data size: 1730 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -1027,11 +1027,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is not null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is not null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -1050,15 +1050,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -1305,11 +1305,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -1328,15 +1328,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3233,15 +3233,15 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col1 (type: string), _col2 (type: int)
-                  1 _col1 (type: string), _col0 (type: int)
-                outputColumnNames: _col0, _col2, _col3, _col4, _col6, _col7, _col8, _col11
+                  1 _col2 (type: string), _col0 (type: int)
+                outputColumnNames: _col0, _col2, _col3, _col4, _col6, _col7, _col8, _col10
                 Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: string)
                   sort order: +
                   Map-reduce partition columns: _col0 (type: string)
                   Statistics: Num rows: 30 Data size: 3807 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col11 (type: boolean)
+                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col10 (type: boolean)
         Reducer 4 
             Reduce Operator Tree:
               Join Operator
@@ -3250,12 +3250,12 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: string)
                   1 _col0 (type: string)
-                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col11, _col13
+                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col10, _col13
                 Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   sort order: 
                   Statistics: Num rows: 33 Data size: 4187 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col11 (type: boolean), _col13 (type: boolean)
+                  value expressions: _col2 (type: int), _col3 (type: boolean), _col4 (type: boolean), _col6 (type: bigint), _col7 (type: boolean), _col8 (type: boolean), _col10 (type: boolean), _col13 (type: boolean)
         Reducer 5 
             Reduce Operator Tree:
               Join Operator
@@ -3264,10 +3264,10 @@ STAGE PLANS:
                 keys:
                   0 
                   1 
-                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col11, _col13, _col14, _col15
+                outputColumnNames: _col2, _col3, _col4, _col6, _col7, _col8, _col10, _col13, _col14, _col15
                 Statistics: Num rows: 33 Data size: 10556 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col2 (type: int), (((_col11 is not null and (_col7 or _col6 is null) is not true) or ((_col3 or _col8) is true and null and (_col7 or _col6 is null) is not true and _col11 is null)) and ((_col13 is not null and _col14) or ((_col4 or _col15) and null and _col14 and _col13 is null))) (type: boolean)
+                  expressions: _col2 (type: int), (((_col10 is not null and (_col7 or _col6 is null) is not true) or ((_col3 or _col8) is true and null and (_col7 or _col6 is null) is not true and _col10 is null)) and ((_col13 is not null and _col14) or ((_col4 or _col15) and null and _col14 and _col13 is null))) (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 33 Data size: 10556 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -3315,15 +3315,15 @@ STAGE PLANS:
                   predicate: _col1 is not null (type: boolean)
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col1 (type: int), _col0 (type: string), true (type: boolean)
+                    expressions: _col1 (type: int), true (type: boolean), _col0 (type: string)
                     outputColumnNames: _col0, _col1, _col2
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col1 (type: string), _col0 (type: int)
+                      key expressions: _col2 (type: string), _col0 (type: int)
                       sort order: ++
-                      Map-reduce partition columns: _col1 (type: string), _col0 (type: int)
+                      Map-reduce partition columns: _col2 (type: string), _col0 (type: int)
                       Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: boolean)
+                      value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
@@ -3438,11 +3438,11 @@ STAGE PLANS:
                      Left Outer Join 0 to 1
                 keys:
                   0 _col0 (type: string)
-                  1 _col0 (type: string)
-                outputColumnNames: _col1, _col3
+                  1 _col1 (type: string)
+                outputColumnNames: _col1, _col2
                 Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col1 (type: int), _col3 is null (type: boolean)
+                  expressions: _col1 (type: int), _col2 is null (type: boolean)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 28 Data size: 3461 Basic stats: COMPLETE Column stats: NONE
                   File Output Operator
@@ -3461,15 +3461,15 @@ STAGE PLANS:
                 outputColumnNames: _col0
                 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), true (type: boolean)
+                  expressions: true (type: boolean), _col0 (type: string)
                   outputColumnNames: _col0, _col1
                   Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
-                    key expressions: _col0 (type: string)
+                    key expressions: _col1 (type: string)
                     sort order: +
-                    Map-reduce partition columns: _col0 (type: string)
+                    Map-reduce partition columns: _col1 (type: string)
                     Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: boolean)
+                    value expressions: _col0 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/spark/subquery_views.q.out b/ql/src/test/results/clientpositive/spark/subquery_views.q.out
index 5d6aceb..106def7 100644
--- a/ql/src/test/results/clientpositive/spark/subquery_views.q.out
+++ b/ql/src/test/results/clientpositive/spark/subquery_views.q.out
@@ -255,11 +255,11 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
                   1 _col0 (type: string), _col1 (type: string)
-                  2 _col3 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col4, _col5, _col8
+                  2 _col3 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col4, _col5, _col7
                 Statistics: Num rows: 365 Data size: 3878 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
                   Statistics: Num rows: 365 Data size: 3878 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string)
@@ -300,7 +300,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
@@ -308,7 +308,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: string)
                     Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 17 
             Reduce Operator Tree:
               Join Operator
@@ -320,11 +320,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 91 Data size: 969 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
-                  key expressions: _col3 (type: string), _col1 (type: string)
+                  key expressions: _col3 (type: string), _col2 (type: string)
                   sort order: ++
-                  Map-reduce partition columns: _col3 (type: string), _col1 (type: string)
+                  Map-reduce partition columns: _col3 (type: string), _col2 (type: string)
                   Statistics: Num rows: 91 Data size: 969 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
         Reducer 19 
             Execution mode: vectorized
             Reduce Operator Tree:
@@ -347,11 +347,11 @@ STAGE PLANS:
                 keys:
                   0 _col0 (type: string), _col1 (type: string)
                   1 _col0 (type: string), _col1 (type: string)
-                  2 _col3 (type: string), _col1 (type: string)
-                outputColumnNames: _col0, _col1, _col4, _col5, _col8
+                  2 _col3 (type: string), _col2 (type: string)
+                outputColumnNames: _col0, _col1, _col4, _col5, _col7
                 Statistics: Num rows: 365 Data size: 3878 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null)) (type: boolean)
+                  predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null)) (type: boolean)
                   Statistics: Num rows: 365 Data size: 3878 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: _col0 (type: string), _col1 (type: string)
@@ -404,7 +404,7 @@ STAGE PLANS:
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
                 Select Operator
-                  expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+                  expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
                   outputColumnNames: _col0, _col1, _col2
                   Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
                   Reduce Output Operator
@@ -412,7 +412,7 @@ STAGE PLANS:
                     sort order: +
                     Map-reduce partition columns: _col0 (type: string)
                     Statistics: Num rows: 27 Data size: 286 Basic stats: COMPLETE Column stats: NONE
-                    value expressions: _col1 (type: string), _col2 (type: boolean)
+                    value expressions: _col1 (type: boolean), _col2 (type: string)
         Reducer 8 
             Reduce Operator Tree:
               Join Operator
@@ -424,11 +424,11 @@ STAGE PLANS:
                 outputColumnNames: _col1, _col2, _col3
                 Statistics: Num rows: 91 Data size: 969 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
-                  key expressions: _col3 (type: string), _col1 (type: string)
+                  key expressions: _col3 (type: string), _col2 (type: string)
                   sort order: ++
-                  Map-reduce partition columns: _col3 (type: string), _col1 (type: string)
+                  Map-reduce partition columns: _col3 (type: string), _col2 (type: string)
                   Statistics: Num rows: 91 Data size: 969 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col2 (type: boolean)
+                  value expressions: _col1 (type: boolean)
 
   Stage: Stage-0
     Fetch Operator
diff --git a/ql/src/test/results/clientpositive/subquery_notexists.q.out b/ql/src/test/results/clientpositive/subquery_notexists.q.out
index d8dc8b5..751a493 100644
--- a/ql/src/test/results/clientpositive/subquery_notexists.q.out
+++ b/ql/src/test/results/clientpositive/subquery_notexists.q.out
@@ -55,7 +55,7 @@ STAGE PLANS:
           outputColumnNames: _col0, _col1
           Statistics: Num rows: 83 Data size: 14774 Basic stats: COMPLETE Column stats: COMPLETE
           Select Operator
-            expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+            expressions: true (type: boolean), _col0 (type: string), _col1 (type: string)
             outputColumnNames: _col0, _col1, _col2
             Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
             File Output Operator
@@ -82,22 +82,22 @@ STAGE PLANS:
                 Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string), _col1 (type: string)
+              key expressions: _col1 (type: string), _col2 (type: string)
               sort order: ++
-              Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+              Map-reduce partition columns: _col1 (type: string), _col2 (type: string)
               Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col2 (type: boolean)
+              value expressions: _col0 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col0 (type: string), _col1 (type: string)
-            1 _col0 (type: string), _col1 (type: string)
-          outputColumnNames: _col0, _col1, _col4
+            1 _col1 (type: string), _col2 (type: string)
+          outputColumnNames: _col0, _col1, _col2
           Statistics: Num rows: 631 Data size: 112846 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col4 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 500 Data size: 89420 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: string)
@@ -322,7 +322,7 @@ STAGE PLANS:
               outputColumnNames: _col0
               Statistics: Num rows: 83 Data size: 7553 Basic stats: COMPLETE Column stats: COMPLETE
               Select Operator
-                expressions: _col0 (type: string), true (type: boolean)
+                expressions: true (type: boolean), _col0 (type: string)
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 83 Data size: 7885 Basic stats: COMPLETE Column stats: COMPLETE
                 File Output Operator
@@ -350,22 +350,22 @@ STAGE PLANS:
                 value expressions: _col0 (type: string)
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string)
+              key expressions: _col1 (type: string)
               sort order: +
-              Map-reduce partition columns: _col0 (type: string)
+              Map-reduce partition columns: _col1 (type: string)
               Statistics: Num rows: 83 Data size: 7885 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col1 (type: boolean)
+              value expressions: _col0 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col1 (type: string)
-            1 _col0 (type: string)
-          outputColumnNames: _col0, _col1, _col3
+            1 _col1 (type: string)
+          outputColumnNames: _col0, _col1, _col2
           Statistics: Num rows: 635 Data size: 113574 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col3 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 500 Data size: 89428 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: string)
@@ -582,7 +582,7 @@ STAGE PLANS:
           outputColumnNames: _col0, _col1
           Statistics: Num rows: 83 Data size: 14774 Basic stats: COMPLETE Column stats: COMPLETE
           Select Operator
-            expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+            expressions: true (type: boolean), _col0 (type: string), _col1 (type: string)
             outputColumnNames: _col0, _col1, _col2
             Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
             File Output Operator
@@ -610,7 +610,7 @@ STAGE PLANS:
             Reduce Output Operator
               sort order: 
               Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col0 (type: string), _col1 (type: string), _col2 (type: boolean)
+              value expressions: _col0 (type: boolean), _col1 (type: string), _col2 (type: string)
       Reduce Operator Tree:
         Join Operator
           condition map:
@@ -619,10 +619,10 @@ STAGE PLANS:
             0 
             1 
           outputColumnNames: _col0, _col1, _col2, _col3, _col4
-          residual filter predicates: {(_col2 > _col0)} {(_col1 <> _col3)}
+          residual filter predicates: {(_col3 > _col0)} {(_col1 <> _col4)}
           Statistics: Num rows: 41500 Data size: 14940000 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col4 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 1 Data size: 360 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: string)
@@ -740,22 +740,22 @@ STAGE PLANS:
               value expressions: _col0 (type: string)
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string)
+              key expressions: _col1 (type: string)
               sort order: +
-              Map-reduce partition columns: _col0 (type: string)
+              Map-reduce partition columns: _col1 (type: string)
               Statistics: Num rows: 12 Data size: 1296 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col1 (type: boolean)
+              value expressions: _col0 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col1 (type: string)
-            1 _col0 (type: string)
-          outputColumnNames: _col0, _col3
+            1 _col1 (type: string)
+          outputColumnNames: _col0, _col2
           Statistics: Num rows: 1014 Data size: 124050 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col3 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 676 Data size: 82700 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string)
@@ -909,7 +909,7 @@ STAGE PLANS:
           outputColumnNames: _col0
           Statistics: Num rows: 12 Data size: 1248 Basic stats: COMPLETE Column stats: COMPLETE
           Select Operator
-            expressions: _col0 (type: string), true (type: boolean)
+            expressions: true (type: boolean), _col0 (type: string)
             outputColumnNames: _col0, _col1
             Statistics: Num rows: 12 Data size: 1296 Basic stats: COMPLETE Column stats: COMPLETE
             File Output Operator
@@ -1613,3 +1613,63 @@ almond antique burnished rose metallic
 almond aquamarine rose maroon antique
 almond aquamarine sandy cyan gainsboro
 almond antique salmon chartreuse burlywood
+PREHOOK: query: create table tschema(id int, name string,dept string)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@tschema
+POSTHOOK: query: create table tschema(id int, name string,dept string)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@tschema
+PREHOOK: query: insert into tschema values(1,'a','it'),(2,'b','eee'),(NULL, 'c', 'cse')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@tschema
+POSTHOOK: query: insert into tschema values(1,'a','it'),(2,'b','eee'),(NULL, 'c', 'cse')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@tschema
+POSTHOOK: Lineage: tschema.dept SCRIPT []
+POSTHOOK: Lineage: tschema.id SCRIPT []
+POSTHOOK: Lineage: tschema.name SCRIPT []
+PREHOOK: query: explain cbo select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tschema
+#### A masked pattern was here ####
+POSTHOOK: query: explain cbo select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tschema
+#### A masked pattern was here ####
+CBO PLAN:
+HiveProject(eid=[_UTF-16LE'empno'], id=[$0])
+  HiveAggregate(group=[{0}])
+    HiveFilter(condition=[IS NULL($1)])
+      HiveJoin(condition=[=($0, $2)], joinType=[left], algorithm=[none], cost=[not available])
+        HiveProject(id=[$0])
+          HiveTableScan(table=[[default, tschema]], table:alias=[a])
+        HiveProject(literalTrue=[true], id0=[$0])
+          HiveAggregate(group=[{0}])
+            HiveFilter(condition=[IS NOT NULL($0)])
+              HiveTableScan(table=[[default, tschema]], table:alias=[c])
+
+PREHOOK: query: select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tschema
+#### A masked pattern was here ####
+POSTHOOK: query: select distinct 'empno' as eid, a.id from tschema a
+    where NOT EXISTS (select c.id from tschema c where a.id=c.id)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tschema
+#### A masked pattern was here ####
+empno	NULL
+PREHOOK: query: drop table tschema
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@tschema
+PREHOOK: Output: default@tschema
+POSTHOOK: query: drop table tschema
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@tschema
+POSTHOOK: Output: default@tschema
diff --git a/ql/src/test/results/clientpositive/subquery_notexists_having.q.out b/ql/src/test/results/clientpositive/subquery_notexists_having.q.out
index fd6cfd7..b14102c 100644
--- a/ql/src/test/results/clientpositive/subquery_notexists_having.q.out
+++ b/ql/src/test/results/clientpositive/subquery_notexists_having.q.out
@@ -75,22 +75,22 @@ STAGE PLANS:
               Statistics: Num rows: 250 Data size: 44500 Basic stats: COMPLETE Column stats: COMPLETE
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string), _col1 (type: string)
+              key expressions: _col1 (type: string), _col2 (type: string)
               sort order: ++
-              Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+              Map-reduce partition columns: _col1 (type: string), _col2 (type: string)
               Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col2 (type: boolean)
+              value expressions: _col0 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col0 (type: string), _col1 (type: string)
-            1 _col0 (type: string), _col1 (type: string)
-          outputColumnNames: _col0, _col1, _col4
+            1 _col1 (type: string), _col2 (type: string)
+          outputColumnNames: _col0, _col1, _col2
           Statistics: Num rows: 333 Data size: 59610 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col4 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 250 Data size: 44752 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: string)
@@ -133,7 +133,7 @@ STAGE PLANS:
           outputColumnNames: _col0, _col1
           Statistics: Num rows: 83 Data size: 14774 Basic stats: COMPLETE Column stats: COMPLETE
           Select Operator
-            expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+            expressions: true (type: boolean), _col0 (type: string), _col1 (type: string)
             outputColumnNames: _col0, _col1, _col2
             Statistics: Num rows: 83 Data size: 15106 Basic stats: COMPLETE Column stats: COMPLETE
             File Output Operator
@@ -267,22 +267,22 @@ STAGE PLANS:
               value expressions: _col0 (type: string)
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string)
+              key expressions: _col1 (type: string)
               sort order: +
-              Map-reduce partition columns: _col0 (type: string)
+              Map-reduce partition columns: _col1 (type: string)
               Statistics: Num rows: 83 Data size: 7885 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col1 (type: boolean)
+              value expressions: _col0 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col1 (type: string)
-            1 _col0 (type: string)
-          outputColumnNames: _col0, _col1, _col3
+            1 _col1 (type: string)
+          outputColumnNames: _col0, _col1, _col2
           Statistics: Num rows: 333 Data size: 59610 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: _col3 is null (type: boolean)
+            predicate: _col2 is null (type: boolean)
             Statistics: Num rows: 250 Data size: 44752 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: string)
@@ -334,7 +334,7 @@ STAGE PLANS:
               outputColumnNames: _col0
               Statistics: Num rows: 83 Data size: 7553 Basic stats: COMPLETE Column stats: COMPLETE
               Select Operator
-                expressions: _col0 (type: string), true (type: boolean)
+                expressions: true (type: boolean), _col0 (type: string)
                 outputColumnNames: _col0, _col1
                 Statistics: Num rows: 83 Data size: 7885 Basic stats: COMPLETE Column stats: COMPLETE
                 File Output Operator
diff --git a/ql/src/test/results/clientpositive/subquery_notin_having.q.out b/ql/src/test/results/clientpositive/subquery_notin_having.q.out
index 727af06..52b1cf8 100644
--- a/ql/src/test/results/clientpositive/subquery_notin_having.q.out
+++ b/ql/src/test/results/clientpositive/subquery_notin_having.q.out
@@ -338,22 +338,22 @@ STAGE PLANS:
               value expressions: _col3 (type: bigint), _col4 (type: bigint)
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string), _col1 (type: double)
+              key expressions: _col0 (type: string), _col2 (type: double)
               sort order: ++
-              Map-reduce partition columns: _col0 (type: string), _col1 (type: double)
+              Map-reduce partition columns: _col0 (type: string), _col2 (type: double)
               Statistics: Num rows: 1 Data size: 110 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col2 (type: boolean)
+              value expressions: _col1 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col0 (type: string), _col1 (type: double)
-            1 _col0 (type: string), _col1 (type: double)
-          outputColumnNames: _col0, _col1, _col3, _col4, _col7
+            1 _col0 (type: string), _col2 (type: double)
+          outputColumnNames: _col0, _col1, _col3, _col4, _col6
           Statistics: Num rows: 7 Data size: 798 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: ((_col7 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col7 is not null)) (type: boolean)
+            predicate: ((_col6 is null or (_col3 = 0L) or _col3 is null) and ((_col4 < _col3) is not true or (_col3 = 0L) or _col3 is null or _col6 is not null or _col0 is null) and (_col0 is not null or (_col3 = 0L) or _col3 is null or _col6 is not null)) (type: boolean)
             Statistics: Num rows: 7 Data size: 798 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col0 (type: string), _col1 (type: double)
@@ -479,7 +479,7 @@ STAGE PLANS:
             predicate: (((_col2 - _col1) > 600.0D) and _col1 is not null) (type: boolean)
             Statistics: Num rows: 1 Data size: 114 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
-              expressions: _col0 (type: string), _col1 (type: double), true (type: boolean)
+              expressions: _col0 (type: string), true (type: boolean), _col1 (type: double)
               outputColumnNames: _col0, _col1, _col2
               Statistics: Num rows: 1 Data size: 110 Basic stats: COMPLETE Column stats: COMPLETE
               File Output Operator
diff --git a/ql/src/test/results/clientpositive/subquery_unqualcolumnrefs.q.out b/ql/src/test/results/clientpositive/subquery_unqualcolumnrefs.q.out
index d567dc1..fe0b79d 100644
--- a/ql/src/test/results/clientpositive/subquery_unqualcolumnrefs.q.out
+++ b/ql/src/test/results/clientpositive/subquery_unqualcolumnrefs.q.out
@@ -454,22 +454,22 @@ STAGE PLANS:
               value expressions: _col2 (type: int), _col4 (type: bigint), _col5 (type: bigint)
           TableScan
             Reduce Output Operator
-              key expressions: _col0 (type: string), _col1 (type: string)
+              key expressions: _col0 (type: string), _col2 (type: string)
               sort order: ++
-              Map-reduce partition columns: _col0 (type: string), _col1 (type: string)
+              Map-reduce partition columns: _col0 (type: string), _col2 (type: string)
               Statistics: Num rows: 4 Data size: 892 Basic stats: COMPLETE Column stats: COMPLETE
-              value expressions: _col2 (type: boolean)
+              value expressions: _col1 (type: boolean)
       Reduce Operator Tree:
         Join Operator
           condition map:
                Left Outer Join 0 to 1
           keys:
             0 _col0 (type: string), _col1 (type: string)
-            1 _col0 (type: string), _col1 (type: string)
-          outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col8
+            1 _col0 (type: string), _col2 (type: string)
+          outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col7
           Statistics: Num rows: 38 Data size: 8914 Basic stats: COMPLETE Column stats: COMPLETE
           Filter Operator
-            predicate: ((_col8 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col8 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col8 is not null)) (type: boolean)
+            predicate: ((_col7 is null or (_col4 = 0L) or _col4 is null) and ((_col5 < _col4) is not true or (_col4 = 0L) or _col4 is null or _col7 is not null or _col0 is null) and (_col0 is not null or (_col4 = 0L) or _col4 is null or _col7 is not null)) (type: boolean)
             Statistics: Num rows: 38 Data size: 8914 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
               expressions: _col1 (type: string), _col0 (type: string), _col2 (type: int)
@@ -564,7 +564,7 @@ STAGE PLANS:
           outputColumnNames: _col0, _col1
           Statistics: Num rows: 4 Data size: 876 Basic stats: COMPLETE Column stats: COMPLETE
           Select Operator
-            expressions: _col0 (type: string), _col1 (type: string), true (type: boolean)
+            expressions: _col0 (type: string), true (type: boolean), _col1 (type: string)
             outputColumnNames: _col0, _col1, _col2
             Statistics: Num rows: 4 Data size: 892 Basic stats: COMPLETE Column stats: COMPLETE
             File Output Operator