You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by kr...@apache.org on 2025/08/26 06:03:12 UTC

(hive) branch master updated: HIVE-29122: Vectorization - Support IGNORE NULLS for FIRST_VALUE and LAST_VALUE [ADDENDUM] (#6027)

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

krisztiankasa 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 a33b5576209 HIVE-29122: Vectorization - Support IGNORE NULLS for FIRST_VALUE and LAST_VALUE [ADDENDUM] (#6027)
a33b5576209 is described below

commit a33b557620907391dd896994fd4ec7ce5dd54496
Author: Soumyakanti Das <so...@gmail.com>
AuthorDate: Mon Aug 25 23:03:06 2025 -0700

    HIVE-29122: Vectorization - Support IGNORE NULLS for FIRST_VALUE and LAST_VALUE [ADDENDUM] (#6027)
---
 .../ptf/VectorPTFEvaluatorDecimalLastValue.java    |   2 +-
 .../ptf/VectorPTFEvaluatorDoubleLastValue.java     |   2 +-
 .../ptf/VectorPTFEvaluatorLongLastValue.java       |   2 +-
 ...torized_first_last_value_ignore_nulls_decimal.q |  48 +--
 ...ctorized_first_last_value_ignore_nulls_double.q |  48 +--
 .../vectorized_first_last_value_ignore_nulls_int.q |  48 +--
 ...zed_first_last_value_ignore_nulls_decimal.q.out | 366 ++++++++++-----------
 ...ized_first_last_value_ignore_nulls_double.q.out | 366 ++++++++++-----------
 ...torized_first_last_value_ignore_nulls_int.q.out | 360 ++++++++++----------
 9 files changed, 621 insertions(+), 621 deletions(-)

diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDecimalLastValue.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDecimalLastValue.java
index 0a116c03bbd..0fb88d69c3d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDecimalLastValue.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDecimalLastValue.java
@@ -67,7 +67,7 @@ public void evaluateGroupBatch(VectorizedRowBatch batch)
         lastValue.set(decimalColVector.vector[0]);
         isGroupResultNull = false;
       } else {
-        isGroupResultNull = true;
+        isGroupResultNull = doesRespectNulls() || !lastValue.isSet();
       }
     } else if (decimalColVector.noNulls) {
       lastValue.set(decimalColVector.vector[size - 1]);
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDoubleLastValue.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDoubleLastValue.java
index 2615199e7ee..e7e4a0ce3a7 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDoubleLastValue.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDoubleLastValue.java
@@ -64,7 +64,7 @@ public void evaluateGroupBatch(VectorizedRowBatch batch)
         lastValue = doubleColVector.vector[0];
         isGroupResultNull = false;
       } else {
-        isGroupResultNull = true;
+        isGroupResultNull = doesRespectNulls() || lastValue == null;
       }
     } else if (doubleColVector.noNulls) {
       lastValue = doubleColVector.vector[size - 1];
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorLongLastValue.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorLongLastValue.java
index 5a83f68ca8a..bf0f27af832 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorLongLastValue.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorLongLastValue.java
@@ -65,7 +65,7 @@ public void evaluateGroupBatch(VectorizedRowBatch batch)
         lastValue = longColVector.vector[0];
         isGroupResultNull = false;
       } else {
-        isGroupResultNull = true;
+        isGroupResultNull = doesRespectNulls() || lastValue == null;
       }
     } else if (longColVector.noNulls) {
       lastValue = longColVector.vector[size - 1];
diff --git a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_decimal.q b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_decimal.q
index 924cc7a25f0..d7fdc40c55b 100644
--- a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_decimal.q
+++ b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_decimal.q
@@ -56,14 +56,14 @@ FROM window_decimal_test;
 -- Test FIRST_VALUE and LAST_VALUE for decimal column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for decimal column without IGNORE NULLS
@@ -82,14 +82,14 @@ FROM window_decimal_test;
 -- Test FIRST_VALUE and LAST_VALUE for decimal column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 
@@ -125,14 +125,14 @@ FROM window_decimal_test;
 -- Test FIRST_VALUE and LAST_VALUE for decimal column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for decimal column without IGNORE NULLS
@@ -151,14 +151,14 @@ FROM window_decimal_test;
 -- Test FIRST_VALUE and LAST_VALUE for decimal column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
 
 
@@ -189,13 +189,13 @@ SELECT id, decimal_col,
 FROM window_decimal_test;
 
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
 
 SELECT id, decimal_col,
@@ -209,11 +209,11 @@ SELECT id, decimal_col,
 FROM window_decimal_test;
 
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test;
 
 SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test;
diff --git a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_double.q b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_double.q
index 8c7d2edefe5..760db83d244 100644
--- a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_double.q
+++ b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_double.q
@@ -56,14 +56,14 @@ FROM window_double_test;
 -- Test FIRST_VALUE and LAST_VALUE for double column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for double column without IGNORE NULLS
@@ -82,14 +82,14 @@ FROM window_double_test;
 -- Test FIRST_VALUE and LAST_VALUE for double column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 
@@ -125,14 +125,14 @@ FROM window_double_test;
 -- Test FIRST_VALUE and LAST_VALUE for double column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for double column without IGNORE NULLS
@@ -151,14 +151,14 @@ FROM window_double_test;
 -- Test FIRST_VALUE and LAST_VALUE for double column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
 
 
@@ -189,13 +189,13 @@ SELECT id, double_col,
 FROM window_double_test;
 
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
 
 SELECT id, double_col,
@@ -209,11 +209,11 @@ SELECT id, double_col,
 FROM window_double_test;
 
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test;
 
 SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test;
diff --git a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_int.q b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_int.q
index 93b999b5930..b95924c5a9c 100644
--- a/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_int.q
+++ b/ql/src/test/queries/clientpositive/vectorized_first_last_value_ignore_nulls_int.q
@@ -56,14 +56,14 @@ FROM window_int_test;
 -- Test FIRST_VALUE and LAST_VALUE for int column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for int column without IGNORE NULLS
@@ -82,14 +82,14 @@ FROM window_int_test;
 -- Test FIRST_VALUE and LAST_VALUE for int column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 
@@ -125,14 +125,14 @@ FROM window_int_test;
 -- Test FIRST_VALUE and LAST_VALUE for int column with PARTITION BY clause
 set hive.vectorized.execution.enabled=false;
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
 
 -- Test FIRST_VALUE and LAST_VALUE for int column without IGNORE NULLS
@@ -151,14 +151,14 @@ FROM window_int_test;
 -- Test FIRST_VALUE and LAST_VALUE for int column with PARTITION BY clause and without IGNORE NULLS
 set hive.vectorized.execution.enabled=false;
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
 
 set hive.vectorized.execution.enabled=true;
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
 
 --========================================================================================
@@ -188,13 +188,13 @@ SELECT id, int_col,
 FROM window_int_test;
 
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
 
 SELECT id, int_col,
@@ -208,11 +208,11 @@ SELECT id, int_col,
 FROM window_int_test;
 
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test;
 
 SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test;
diff --git a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_decimal.q.out b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_decimal.q.out
index a6b7b0642a6..cf0944b7ed6 100644
--- a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_decimal.q.out
+++ b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_decimal.q.out
@@ -192,68 +192,68 @@ id	decimal_col	first_decimal	last_decimal
 NULL	NULL	200.00	800.00
 NULL	800.00	200.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
-5	500.20	500.20	500.20
-5	NULL	500.20	500.20
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	200.00	200.00
 2	200.00	200.00	200.00
 2	NULL	200.00	200.00
-4	NULL	400.00	400.00
+2	NULL	200.00	200.00
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	300.75
 4	400.00	400.00	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+4	NULL	400.00	400.00
+5	500.20	500.20	500.20
+5	NULL	500.20	500.20
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
 NULL	800.00	800.00	800.00
 NULL	NULL	800.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
-5	500.20	500.20	500.20
-5	NULL	500.20	500.20
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	200.00	200.00
 2	200.00	200.00	200.00
 2	NULL	200.00	200.00
-4	NULL	400.00	400.00
+2	NULL	200.00	200.00
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	300.75
 4	400.00	400.00	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+4	NULL	400.00	400.00
+5	500.20	500.20	500.20
+5	NULL	500.20	500.20
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
 NULL	800.00	800.00	800.00
 NULL	NULL	800.00	800.00
@@ -324,70 +324,70 @@ id	decimal_col	first_decimal	last_decimal
 NULL	NULL	NULL	800.00
 NULL	800.00	NULL	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
-3	300.50	NULL	300.50
-5	500.20	500.20	NULL
-5	NULL	500.20	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	200.00	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	400.00
-4	400.00	NULL	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+2	200.00	200.00	200.00
+2	NULL	200.00	NULL
+2	NULL	200.00	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	NULL
+4	400.00	400.00	400.00
+4	NULL	400.00	NULL
+5	500.20	500.20	500.20
+5	NULL	500.20	NULL
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
-NULL	800.00	800.00	NULL
+NULL	800.00	800.00	800.00
 NULL	NULL	800.00	NULL
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
-3	300.50	NULL	300.50
-5	500.20	500.20	NULL
-5	NULL	500.20	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	200.00	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	400.00
-4	400.00	NULL	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+2	200.00	200.00	200.00
+2	NULL	200.00	NULL
+2	NULL	200.00	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	NULL
+4	400.00	400.00	400.00
+4	NULL	400.00	NULL
+5	500.20	500.20	500.20
+5	NULL	500.20	NULL
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
-NULL	800.00	800.00	NULL
+NULL	800.00	800.00	800.00
 NULL	NULL	800.00	NULL
 PREHOOK: query: SELECT id, decimal_col,
   FIRST_VALUE(decimal_col) IGNORE NULLS OVER(ORDER BY id ASC NULLS FIRST) AS first_decimal,
@@ -522,15 +522,15 @@ NULL	800.00	800.00	800.00
 6	610.00	800.00	610.00
 7	NULL	800.00	610.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -539,31 +539,31 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	800.00	800.00
-NULL	800.00	800.00	800.00
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	200.00	200.00	200.00
-2	NULL	200.00	200.00
-2	NULL	200.00	200.00
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
+3	NULL	NULL	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+4	NULL	NULL	NULL
 4	400.00	400.00	400.00
-4	NULL	400.00	400.00
-5	NULL	500.20	500.20
+5	NULL	NULL	NULL
 5	500.20	500.20	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	800.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -572,21 +572,21 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	800.00	800.00
-NULL	800.00	800.00	800.00
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	200.00	200.00	200.00
-2	NULL	200.00	200.00
-2	NULL	200.00	200.00
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
+3	NULL	NULL	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+4	NULL	NULL	NULL
 4	400.00	400.00	400.00
-4	NULL	400.00	400.00
-5	NULL	500.20	500.20
+5	NULL	NULL	NULL
 5	500.20	500.20	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	800.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
   FIRST_VALUE(decimal_col) OVER(ORDER BY id ASC NULLS FIRST) AS first_decimal,
   LAST_VALUE(decimal_col) OVER(ORDER BY id ASC NULLS FIRST) AS last_decimal
@@ -654,15 +654,15 @@ NULL	800.00	NULL	800.00
 6	610.00	NULL	610.00
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -671,31 +671,31 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	800.00
-NULL	800.00	NULL	800.00
-2	200.00	200.00	NULL
-2	NULL	200.00	NULL
-2	NULL	200.00	NULL
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	200.00	NULL	200.00
+3	NULL	NULL	NULL
 3	300.50	NULL	300.50
-4	400.00	400.00	NULL
-4	NULL	400.00	NULL
-5	NULL	NULL	500.20
+3	300.75	NULL	300.75
+4	NULL	NULL	NULL
+4	400.00	NULL	400.00
+5	NULL	NULL	NULL
 5	500.20	NULL	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	NULL	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -704,21 +704,21 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	800.00
-NULL	800.00	NULL	800.00
-2	200.00	200.00	NULL
-2	NULL	200.00	NULL
-2	NULL	200.00	NULL
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	200.00	NULL	200.00
+3	NULL	NULL	NULL
 3	300.50	NULL	300.50
-4	400.00	400.00	NULL
-4	NULL	400.00	NULL
-5	NULL	NULL	500.20
+3	300.75	NULL	300.75
+4	NULL	NULL	NULL
+4	400.00	NULL	400.00
+5	NULL	NULL	NULL
 5	500.20	NULL	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	NULL	800.00
 PREHOOK: query: SELECT id, decimal_col,
   FIRST_VALUE(decimal_col) IGNORE NULLS OVER(ORDER BY id) AS first_decimal,
   LAST_VALUE(decimal_col) IGNORE NULLS OVER(ORDER BY id) AS last_decimal
@@ -852,48 +852,48 @@ NULL	800.00	800.00	800.00
 6	610.00	800.00	610.00
 7	NULL	800.00	610.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
-5	500.20	500.20	500.20
-5	NULL	500.20	500.20
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	200.00	200.00
 2	200.00	200.00	200.00
 2	NULL	200.00	200.00
-4	NULL	400.00	400.00
+2	NULL	200.00	200.00
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	300.75
 4	400.00	400.00	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+4	NULL	400.00	400.00
+5	500.20	500.20	500.20
+5	NULL	500.20	500.20
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
 NULL	800.00	800.00	800.00
 NULL	NULL	800.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -902,21 +902,21 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	800.00	800.00
-NULL	800.00	800.00	800.00
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	200.00	200.00	200.00
-2	NULL	200.00	200.00
-2	NULL	200.00	200.00
-3	NULL	300.75	300.50
-3	300.75	300.75	300.50
-3	300.50	300.75	300.50
+3	NULL	NULL	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+4	NULL	NULL	NULL
 4	400.00	400.00	400.00
-4	NULL	400.00	400.00
-5	NULL	500.20	500.20
+5	NULL	NULL	NULL
 5	500.20	500.20	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	800.00	800.00
 PREHOOK: query: SELECT id, decimal_col,
   FIRST_VALUE(decimal_col) OVER(ORDER BY id) AS first_decimal,
   LAST_VALUE(decimal_col) OVER(ORDER BY id) AS last_decimal
@@ -984,48 +984,48 @@ NULL	800.00	NULL	800.00
 6	610.00	NULL	610.00
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id, decimal_col) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 id	decimal_col	first_decimal	last_decimal
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
-3	300.50	NULL	300.50
-5	500.20	500.20	NULL
-5	NULL	500.20	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	200.00	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	400.00
-4	400.00	NULL	400.00
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+2	200.00	200.00	200.00
+2	NULL	200.00	NULL
+2	NULL	200.00	NULL
+3	300.50	300.50	300.50
+3	300.75	300.50	300.75
+3	NULL	300.50	NULL
+4	400.00	400.00	400.00
+4	NULL	400.00	NULL
+5	500.20	500.20	500.20
+5	NULL	500.20	NULL
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
-NULL	800.00	800.00	NULL
+NULL	800.00	800.00	800.00
 NULL	NULL	800.00	NULL
 PREHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_decimal_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, decimal_col,
-  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_decimal,
-  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_decimal
+  FIRST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS first_decimal,
+  LAST_VALUE(decimal_col) OVER(PARTITION BY id ORDER BY id ASC, decimal_col ASC NULLS FIRST) AS last_decimal
 FROM window_decimal_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_decimal_test
@@ -1034,18 +1034,18 @@ id	decimal_col	first_decimal	last_decimal
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	800.00
-NULL	800.00	NULL	800.00
-2	200.00	200.00	NULL
-2	NULL	200.00	NULL
-2	NULL	200.00	NULL
-3	NULL	NULL	300.50
-3	300.75	NULL	300.50
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	200.00	NULL	200.00
+3	NULL	NULL	NULL
 3	300.50	NULL	300.50
-4	400.00	400.00	NULL
-4	NULL	400.00	NULL
-5	NULL	NULL	500.20
+3	300.75	NULL	300.75
+4	NULL	NULL	NULL
+4	400.00	NULL	400.00
+5	NULL	NULL	NULL
 5	500.20	NULL	500.20
-6	610.00	610.00	600.00
-6	600.00	610.00	600.00
+6	600.00	600.00	600.00
+6	610.00	600.00	610.00
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	800.00	NULL	800.00
diff --git a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_double.q.out b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_double.q.out
index 1375327e848..118d6266ce2 100644
--- a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_double.q.out
+++ b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_double.q.out
@@ -192,68 +192,68 @@ id	double_col	first_double	last_double
 NULL	NULL	25.5	80.5
 NULL	80.5	25.5	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
-5	50.5	50.5	50.5
-5	NULL	50.5	50.5
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	25.5	25.5
 2	25.5	25.5	25.5
 2	NULL	25.5	25.5
-4	NULL	42.3	42.3
+2	NULL	25.5	25.5
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	32.5
 4	42.3	42.3	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+4	NULL	42.3	42.3
+5	50.5	50.5	50.5
+5	NULL	50.5	50.5
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
 NULL	80.5	80.5	80.5
 NULL	NULL	80.5	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
-5	50.5	50.5	50.5
-5	NULL	50.5	50.5
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	25.5	25.5
 2	25.5	25.5	25.5
 2	NULL	25.5	25.5
-4	NULL	42.3	42.3
+2	NULL	25.5	25.5
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	32.5
 4	42.3	42.3	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+4	NULL	42.3	42.3
+5	50.5	50.5	50.5
+5	NULL	50.5	50.5
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
 NULL	80.5	80.5	80.5
 NULL	NULL	80.5	80.5
@@ -324,70 +324,70 @@ id	double_col	first_double	last_double
 NULL	NULL	NULL	80.5
 NULL	80.5	NULL	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
-3	30.5	NULL	30.5
-5	50.5	50.5	NULL
-5	NULL	50.5	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	25.5	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	42.3
-4	42.3	NULL	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+2	25.5	25.5	25.5
+2	NULL	25.5	NULL
+2	NULL	25.5	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	NULL
+4	42.3	42.3	42.3
+4	NULL	42.3	NULL
+5	50.5	50.5	50.5
+5	NULL	50.5	NULL
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
-NULL	80.5	80.5	NULL
+NULL	80.5	80.5	80.5
 NULL	NULL	80.5	NULL
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
-3	30.5	NULL	30.5
-5	50.5	50.5	NULL
-5	NULL	50.5	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	25.5	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	42.3
-4	42.3	NULL	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+2	25.5	25.5	25.5
+2	NULL	25.5	NULL
+2	NULL	25.5	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	NULL
+4	42.3	42.3	42.3
+4	NULL	42.3	NULL
+5	50.5	50.5	50.5
+5	NULL	50.5	NULL
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
-NULL	80.5	80.5	NULL
+NULL	80.5	80.5	80.5
 NULL	NULL	80.5	NULL
 PREHOOK: query: SELECT id, double_col,
   FIRST_VALUE(double_col) IGNORE NULLS OVER(ORDER BY id ASC NULLS FIRST) AS first_double,
@@ -522,15 +522,15 @@ NULL	80.5	80.5	80.5
 6	65.5	80.5	65.5
 7	NULL	80.5	65.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -539,31 +539,31 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80.5	80.5
-NULL	80.5	80.5	80.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	25.5	25.5	25.5
-2	NULL	25.5	25.5
-2	NULL	25.5	25.5
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
+3	NULL	NULL	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+4	NULL	NULL	NULL
 4	42.3	42.3	42.3
-4	NULL	42.3	42.3
-5	NULL	50.5	50.5
+5	NULL	NULL	NULL
 5	50.5	50.5	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	80.5	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -572,21 +572,21 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80.5	80.5
-NULL	80.5	80.5	80.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	25.5	25.5	25.5
-2	NULL	25.5	25.5
-2	NULL	25.5	25.5
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
+3	NULL	NULL	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+4	NULL	NULL	NULL
 4	42.3	42.3	42.3
-4	NULL	42.3	42.3
-5	NULL	50.5	50.5
+5	NULL	NULL	NULL
 5	50.5	50.5	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	80.5	80.5
 PREHOOK: query: SELECT id, double_col,
   FIRST_VALUE(double_col) OVER(ORDER BY id ASC NULLS FIRST) AS first_double,
   LAST_VALUE(double_col) OVER(ORDER BY id ASC NULLS FIRST) AS last_double
@@ -654,15 +654,15 @@ NULL	80.5	NULL	80.5
 6	65.5	NULL	65.5
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -671,31 +671,31 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80.5
-NULL	80.5	NULL	80.5
-2	25.5	25.5	NULL
-2	NULL	25.5	NULL
-2	NULL	25.5	NULL
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	25.5	NULL	25.5
+3	NULL	NULL	NULL
 3	30.5	NULL	30.5
-4	42.3	42.3	NULL
-4	NULL	42.3	NULL
-5	NULL	NULL	50.5
+3	32.5	NULL	32.5
+4	NULL	NULL	NULL
+4	42.3	NULL	42.3
+5	NULL	NULL	NULL
 5	50.5	NULL	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	NULL	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -704,21 +704,21 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80.5
-NULL	80.5	NULL	80.5
-2	25.5	25.5	NULL
-2	NULL	25.5	NULL
-2	NULL	25.5	NULL
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	25.5	NULL	25.5
+3	NULL	NULL	NULL
 3	30.5	NULL	30.5
-4	42.3	42.3	NULL
-4	NULL	42.3	NULL
-5	NULL	NULL	50.5
+3	32.5	NULL	32.5
+4	NULL	NULL	NULL
+4	42.3	NULL	42.3
+5	NULL	NULL	NULL
 5	50.5	NULL	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	NULL	80.5
 PREHOOK: query: SELECT id, double_col,
   FIRST_VALUE(double_col) IGNORE NULLS OVER(ORDER BY id) AS first_double,
   LAST_VALUE(double_col) IGNORE NULLS OVER(ORDER BY id) AS last_double
@@ -852,48 +852,48 @@ NULL	80.5	80.5	80.5
 6	65.5	80.5	65.5
 7	NULL	80.5	65.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
-5	50.5	50.5	50.5
-5	NULL	50.5	50.5
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	25.5	25.5
 2	25.5	25.5	25.5
 2	NULL	25.5	25.5
-4	NULL	42.3	42.3
+2	NULL	25.5	25.5
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	32.5
 4	42.3	42.3	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+4	NULL	42.3	42.3
+5	50.5	50.5	50.5
+5	NULL	50.5	50.5
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
 NULL	80.5	80.5	80.5
 NULL	NULL	80.5	80.5
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -902,21 +902,21 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80.5	80.5
-NULL	80.5	80.5	80.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	25.5	25.5	25.5
-2	NULL	25.5	25.5
-2	NULL	25.5	25.5
-3	NULL	32.5	30.5
-3	32.5	32.5	30.5
-3	30.5	32.5	30.5
+3	NULL	NULL	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+4	NULL	NULL	NULL
 4	42.3	42.3	42.3
-4	NULL	42.3	42.3
-5	NULL	50.5	50.5
+5	NULL	NULL	NULL
 5	50.5	50.5	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	80.5	80.5
 PREHOOK: query: SELECT id, double_col,
   FIRST_VALUE(double_col) OVER(ORDER BY id) AS first_double,
   LAST_VALUE(double_col) OVER(ORDER BY id) AS last_double
@@ -984,48 +984,48 @@ NULL	80.5	NULL	80.5
 6	65.5	NULL	65.5
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id, double_col) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 id	double_col	first_double	last_double
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
-3	30.5	NULL	30.5
-5	50.5	50.5	NULL
-5	NULL	50.5	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	25.5	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	42.3
-4	42.3	NULL	42.3
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+2	25.5	25.5	25.5
+2	NULL	25.5	NULL
+2	NULL	25.5	NULL
+3	30.5	30.5	30.5
+3	32.5	30.5	32.5
+3	NULL	30.5	NULL
+4	42.3	42.3	42.3
+4	NULL	42.3	NULL
+5	50.5	50.5	50.5
+5	NULL	50.5	NULL
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
-NULL	80.5	80.5	NULL
+NULL	80.5	80.5	80.5
 NULL	NULL	80.5	NULL
 PREHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_double_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, double_col,
-  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_double,
-  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_double
+  FIRST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS first_double,
+  LAST_VALUE(double_col) OVER(PARTITION BY id ORDER BY id ASC, double_col ASC NULLS FIRST) AS last_double
 FROM window_double_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_double_test
@@ -1034,18 +1034,18 @@ id	double_col	first_double	last_double
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80.5
-NULL	80.5	NULL	80.5
-2	25.5	25.5	NULL
-2	NULL	25.5	NULL
-2	NULL	25.5	NULL
-3	NULL	NULL	30.5
-3	32.5	NULL	30.5
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	25.5	NULL	25.5
+3	NULL	NULL	NULL
 3	30.5	NULL	30.5
-4	42.3	42.3	NULL
-4	NULL	42.3	NULL
-5	NULL	NULL	50.5
+3	32.5	NULL	32.5
+4	NULL	NULL	NULL
+4	42.3	NULL	42.3
+5	NULL	NULL	NULL
 5	50.5	NULL	50.5
-6	65.5	65.5	65.2
-6	65.2	65.5	65.2
+6	65.2	65.2	65.2
+6	65.5	65.2	65.5
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80.5	NULL	80.5
diff --git a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_int.q.out b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_int.q.out
index a89884eaa61..b555951bb68 100644
--- a/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_int.q.out
+++ b/ql/src/test/results/clientpositive/llap/vectorized_first_last_value_ignore_nulls_int.q.out
@@ -192,68 +192,68 @@ id	int_col	first_int	last_int
 NULL	NULL	20	80
 NULL	80	20	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	30	32
-3	30	30	32
-3	32	30	32
-5	50	50	50
-5	NULL	50	50
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	20	20
 2	20	20	20
 2	NULL	20	20
-4	NULL	40	40
+2	NULL	20	20
+3	30	30	30
+3	32	30	32
+3	NULL	30	32
 4	40	40	40
-6	62	62	60
-6	60	62	60
+4	NULL	40	40
+5	50	50	50
+5	NULL	50	50
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
 NULL	80	80	80
 NULL	NULL	80	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	30	32
-3	30	30	32
-3	32	30	32
-5	50	50	50
-5	NULL	50	50
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	20	20
 2	20	20	20
 2	NULL	20	20
-4	NULL	40	40
+2	NULL	20	20
+3	30	30	30
+3	32	30	32
+3	NULL	30	32
 4	40	40	40
-6	62	62	60
-6	60	62	60
+4	NULL	40	40
+5	50	50	50
+5	NULL	50	50
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
 NULL	80	80	80
 NULL	NULL	80	80
@@ -324,70 +324,70 @@ id	int_col	first_int	last_int
 NULL	NULL	NULL	80
 NULL	80	NULL	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	NULL	32
-3	30	NULL	32
-3	32	NULL	32
-5	50	50	NULL
-5	NULL	50	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	20	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	40
-4	40	NULL	40
-6	62	62	60
-6	60	62	60
+2	20	20	20
+2	NULL	20	NULL
+2	NULL	20	NULL
+3	30	30	30
+3	32	30	32
+3	NULL	30	NULL
+4	40	40	40
+4	NULL	40	NULL
+5	50	50	50
+5	NULL	50	NULL
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
-NULL	80	80	NULL
+NULL	80	80	80
 NULL	NULL	80	NULL
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	NULL	32
-3	30	NULL	32
-3	32	NULL	32
-5	50	50	NULL
-5	NULL	50	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	20	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	40
-4	40	NULL	40
-6	62	62	60
-6	60	62	60
+2	20	20	20
+2	NULL	20	NULL
+2	NULL	20	NULL
+3	30	30	30
+3	32	30	32
+3	NULL	30	NULL
+4	40	40	40
+4	NULL	40	NULL
+5	50	50	50
+5	NULL	50	NULL
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
-NULL	80	80	NULL
+NULL	80	80	80
 NULL	NULL	80	NULL
 PREHOOK: query: SELECT id, int_col,
   FIRST_VALUE(int_col) IGNORE NULLS OVER(ORDER BY id ASC NULLS FIRST) AS first_int,
@@ -522,15 +522,15 @@ NULL	80	80	80
 6	62	80	62
 7	NULL	80	62
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -539,31 +539,31 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80	80
-NULL	80	80	80
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	20	20	20
-2	NULL	20	20
-2	NULL	20	20
-3	NULL	30	32
-3	30	30	32
+3	NULL	NULL	NULL
+3	30	30	30
 3	32	30	32
+4	NULL	NULL	NULL
 4	40	40	40
-4	NULL	40	40
-5	NULL	50	50
+5	NULL	NULL	NULL
 5	50	50	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	80	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -572,21 +572,21 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80	80
-NULL	80	80	80
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	20	20	20
-2	NULL	20	20
-2	NULL	20	20
-3	NULL	30	32
-3	30	30	32
+3	NULL	NULL	NULL
+3	30	30	30
 3	32	30	32
+4	NULL	NULL	NULL
 4	40	40	40
-4	NULL	40	40
-5	NULL	50	50
+5	NULL	NULL	NULL
 5	50	50	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	80	80
 PREHOOK: query: SELECT id, int_col,
   FIRST_VALUE(int_col) OVER(ORDER BY id ASC NULLS FIRST) AS first_int,
   LAST_VALUE(int_col) OVER(ORDER BY id ASC NULLS FIRST) AS last_int
@@ -654,15 +654,15 @@ NULL	80	NULL	80
 6	62	NULL	62
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -671,31 +671,31 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80
-NULL	80	NULL	80
-2	20	20	NULL
-2	NULL	20	NULL
-2	NULL	20	NULL
-3	NULL	NULL	32
-3	30	NULL	32
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	20	NULL	20
+3	NULL	NULL	NULL
+3	30	NULL	30
 3	32	NULL	32
-4	40	40	NULL
-4	NULL	40	NULL
-5	NULL	NULL	50
+4	NULL	NULL	NULL
+4	40	NULL	40
+5	NULL	NULL	NULL
 5	50	NULL	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	NULL	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -704,21 +704,21 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80
-NULL	80	NULL	80
-2	20	20	NULL
-2	NULL	20	NULL
-2	NULL	20	NULL
-3	NULL	NULL	32
-3	30	NULL	32
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	20	NULL	20
+3	NULL	NULL	NULL
+3	30	NULL	30
 3	32	NULL	32
-4	40	40	NULL
-4	NULL	40	NULL
-5	NULL	NULL	50
+4	NULL	NULL	NULL
+4	40	NULL	40
+5	NULL	NULL	NULL
 5	50	NULL	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	NULL	80
 PREHOOK: query: SELECT id, int_col,
   FIRST_VALUE(int_col) IGNORE NULLS OVER(ORDER BY id) AS first_int,
   LAST_VALUE(int_col) IGNORE NULLS OVER(ORDER BY id) AS last_int
@@ -852,48 +852,48 @@ NULL	80	80	80
 6	62	80	62
 7	NULL	80	62
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	30	32
-3	30	30	32
-3	32	30	32
-5	50	50	50
-5	NULL	50	50
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	20	20
 2	20	20	20
 2	NULL	20	20
-4	NULL	40	40
+2	NULL	20	20
+3	30	30	30
+3	32	30	32
+3	NULL	30	32
 4	40	40	40
-6	62	62	60
-6	60	62	60
+4	NULL	40	40
+5	50	50	50
+5	NULL	50	50
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
 NULL	80	80	80
 NULL	NULL	80	80
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col IGNORE NULLS) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -902,21 +902,21 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	80	80
-NULL	80	80	80
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
 2	20	20	20
-2	NULL	20	20
-2	NULL	20	20
-3	NULL	30	32
-3	30	30	32
+3	NULL	NULL	NULL
+3	30	30	30
 3	32	30	32
+4	NULL	NULL	NULL
 4	40	40	40
-4	NULL	40	40
-5	NULL	50	50
+5	NULL	NULL	NULL
 5	50	50	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	80	80
 PREHOOK: query: SELECT id, int_col,
   FIRST_VALUE(int_col) OVER(ORDER BY id) AS first_int,
   LAST_VALUE(int_col) OVER(ORDER BY id) AS last_int
@@ -984,48 +984,48 @@ NULL	80	NULL	80
 6	62	NULL	62
 7	NULL	NULL	NULL
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id, int_col) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 id	int_col	first_int	last_int
-3	NULL	NULL	32
-3	30	NULL	32
-3	32	NULL	32
-5	50	50	NULL
-5	NULL	50	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-2	NULL	NULL	NULL
-2	20	NULL	NULL
-2	NULL	NULL	NULL
-4	NULL	NULL	40
-4	40	NULL	40
-6	62	62	60
-6	60	62	60
+2	20	20	20
+2	NULL	20	NULL
+2	NULL	20	NULL
+3	30	30	30
+3	32	30	32
+3	NULL	30	NULL
+4	40	40	40
+4	NULL	40	NULL
+5	50	50	50
+5	NULL	50	NULL
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
-NULL	80	80	NULL
+NULL	80	80	80
 NULL	NULL	80	NULL
 PREHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 PREHOOK: type: QUERY
 PREHOOK: Input: default@window_int_test
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT id, int_col,
-  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS first_int,
-  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC NULLS FIRST) AS last_int
+  FIRST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS first_int,
+  LAST_VALUE(int_col) OVER(PARTITION BY id ORDER BY id ASC, int_col ASC NULLS FIRST) AS last_int
 FROM window_int_test
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@window_int_test
@@ -1034,18 +1034,18 @@ id	int_col	first_int	last_int
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
 1	NULL	NULL	NULL
-NULL	NULL	NULL	80
-NULL	80	NULL	80
-2	20	20	NULL
-2	NULL	20	NULL
-2	NULL	20	NULL
-3	NULL	NULL	32
-3	30	NULL	32
+2	NULL	NULL	NULL
+2	NULL	NULL	NULL
+2	20	NULL	20
+3	NULL	NULL	NULL
+3	30	NULL	30
 3	32	NULL	32
-4	40	40	NULL
-4	NULL	40	NULL
-5	NULL	NULL	50
+4	NULL	NULL	NULL
+4	40	NULL	40
+5	NULL	NULL	NULL
 5	50	NULL	50
-6	62	62	60
-6	60	62	60
+6	60	60	60
+6	62	60	62
 7	NULL	NULL	NULL
+NULL	NULL	NULL	NULL
+NULL	80	NULL	80