You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jc...@apache.org on 2020/07/17 14:55:40 UTC

[hive] branch master updated: HIVE-23868: Windowing function spec: support 0 preceeding/following (Jason Dere via Jesus Camacho Rodriguez)

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

jcamacho 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 58d55e0  HIVE-23868: Windowing function spec: support 0 preceeding/following (Jason Dere via Jesus Camacho Rodriguez)
58d55e0 is described below

commit 58d55e027dc173b0bed41ac2d38faa1d2b1ac892
Author: jdere <jd...@hortonworks.com>
AuthorDate: Fri Jul 17 07:55:23 2020 -0700

    HIVE-23868: Windowing function spec: support 0 preceeding/following (Jason Dere via Jesus Camacho Rodriguez)
    
    Closes apache/hive#1269
---
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java     | 12 ++++--
 .../queries/clientpositive/windowing_windowspec4.q | 19 ++++++++
 .../llap/windowing_windowspec4.q.out               | 50 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index aeaf8ac..1d013ae 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -14357,11 +14357,17 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       else
       {
         int amt = Integer.parseInt(amtNode.getText());
-        if ( amt <= 0 ) {
+        if ( amt < 0 ) {
           throw new SemanticException(
-              "Window Frame Boundary Amount must be a positive integer, provided amount is: " + amt);
+              "Window Frame Boundary Amount must be a non-negative integer, provided amount is: " + amt);
+        } else if (amt == 0) {
+          // Convert 0 PRECEDING/FOLLOWING to CURRENT ROW
+          LOG.info("Converting 0 {} to CURRENT ROW", bs.getDirection());
+          bs.setDirection(Direction.CURRENT);
+          hasAmt = false;
+        } else {
+          bs.setAmt(amt);
         }
-        bs.setAmt(amt);
       }
     }
 
diff --git a/ql/src/test/queries/clientpositive/windowing_windowspec4.q b/ql/src/test/queries/clientpositive/windowing_windowspec4.q
index fcf0f25..ca2d9a8 100644
--- a/ql/src/test/queries/clientpositive/windowing_windowspec4.q
+++ b/ql/src/test/queries/clientpositive/windowing_windowspec4.q
@@ -17,3 +17,22 @@ sum(i) over (partition by type order by i rows between 1 preceding and 7 followi
 collect_set(i) over (partition by type order by i rows between 1 preceding and 7 following),
 count(i) over (partition by type order by i rows between 1 preceding and 7 following)
 from smalltable_windowing;
+
+-- 0 preceding/following should be the same as current row
+select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and 0 following),
+min(i) over (partition by type order by i rows between 1 preceding and 0 following),
+max(i) over (partition by type order by i rows between 0 preceding and 1 following),
+min(i) over (partition by type order by i rows between 0 preceding and 1 following),
+max(i) over (partition by type order by i rows between 0 preceding and 0 following),
+min(i) over (partition by type order by i rows between 0 preceding and 0 following)
+from smalltable_windowing;
+
+select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and current row),
+min(i) over (partition by type order by i rows between 1 preceding and current row),
+max(i) over (partition by type order by i rows between current row and 1 following),
+min(i) over (partition by type order by i rows between current row and 1 following),
+max(i) over (partition by type order by i rows between current row and current row),
+min(i) over (partition by type order by i rows between current row and current row)
+from smalltable_windowing;
diff --git a/ql/src/test/results/clientpositive/llap/windowing_windowspec4.q.out b/ql/src/test/results/clientpositive/llap/windowing_windowspec4.q.out
index b668047..c8eca40 100644
--- a/ql/src/test/results/clientpositive/llap/windowing_windowspec4.q.out
+++ b/ql/src/test/results/clientpositive/llap/windowing_windowspec4.q.out
@@ -53,3 +53,53 @@ POSTHOOK: Input: default@smalltable_windowing
 a	1	3	1	1	3	2.0	6	[1,2,3]	3
 a	2	3	1	1	3	2.0	6	[1,2,3]	3
 a	3	3	2	2	3	2.5	5	[2,3]	2
+PREHOOK: query: select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and 0 following),
+min(i) over (partition by type order by i rows between 1 preceding and 0 following),
+max(i) over (partition by type order by i rows between 0 preceding and 1 following),
+min(i) over (partition by type order by i rows between 0 preceding and 1 following),
+max(i) over (partition by type order by i rows between 0 preceding and 0 following),
+min(i) over (partition by type order by i rows between 0 preceding and 0 following)
+from smalltable_windowing
+PREHOOK: type: QUERY
+PREHOOK: Input: default@smalltable_windowing
+#### A masked pattern was here ####
+POSTHOOK: query: select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and 0 following),
+min(i) over (partition by type order by i rows between 1 preceding and 0 following),
+max(i) over (partition by type order by i rows between 0 preceding and 1 following),
+min(i) over (partition by type order by i rows between 0 preceding and 1 following),
+max(i) over (partition by type order by i rows between 0 preceding and 0 following),
+min(i) over (partition by type order by i rows between 0 preceding and 0 following)
+from smalltable_windowing
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@smalltable_windowing
+#### A masked pattern was here ####
+a	1	1	1	2	1	1	1
+a	2	2	1	3	2	2	2
+a	3	3	2	3	3	3	3
+PREHOOK: query: select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and current row),
+min(i) over (partition by type order by i rows between 1 preceding and current row),
+max(i) over (partition by type order by i rows between current row and 1 following),
+min(i) over (partition by type order by i rows between current row and 1 following),
+max(i) over (partition by type order by i rows between current row and current row),
+min(i) over (partition by type order by i rows between current row and current row)
+from smalltable_windowing
+PREHOOK: type: QUERY
+PREHOOK: Input: default@smalltable_windowing
+#### A masked pattern was here ####
+POSTHOOK: query: select type, i,
+max(i) over (partition by type order by i rows between 1 preceding and current row),
+min(i) over (partition by type order by i rows between 1 preceding and current row),
+max(i) over (partition by type order by i rows between current row and 1 following),
+min(i) over (partition by type order by i rows between current row and 1 following),
+max(i) over (partition by type order by i rows between current row and current row),
+min(i) over (partition by type order by i rows between current row and current row)
+from smalltable_windowing
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@smalltable_windowing
+#### A masked pattern was here ####
+a	1	1	1	2	1	1	1
+a	2	2	1	3	2	2	2
+a	3	3	2	3	3	3	3