diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java index 50f86df..953f3ae 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java @@ -145,7 +145,7 @@ public void validateAndMakeEffective() throws SemanticException { } // 2. A Window Spec with no Parition Spec, is Partitioned on a Constant(number 0) - applyContantPartition(wdwSpec); + applyConstantPartition(wdwSpec); // 3. For missing Wdw Frames or for Frames with only a Start Boundary, completely // specify them by the rules in {@link effectiveWindowFrame} @@ -154,8 +154,8 @@ public void validateAndMakeEffective() throws SemanticException { // 4. Validate the effective Window Frames with the rules in {@link validateWindowFrame} validateWindowFrame(wdwSpec); - // 5. If there is no Order, then add the Partition expressions as the Order. - wdwSpec.ensureOrderSpec(); + // 5. Add the Partition expressions as the Order if there is no Order and validate Order spec. + setAndValidateOrderSpec(wdwSpec); } } @@ -196,7 +196,7 @@ private void fillInWindowSpec(String sourceId, WindowSpec dest, ArrayList 1 ) { throw new SemanticException("Range based Window Frame can have only 1 Sort Key"); } + + if (start instanceof ValueBoundarySpec) { + ((ValueBoundarySpec)start).setExpression(order.getExpressions().get(0).getExpression()); + } + if (end instanceof ValueBoundarySpec) { + ((ValueBoundarySpec)end).setExpression(order.getExpressions().get(0).getExpression()); + } } - vbs.setExpression(order.getExpressions().get(0).getExpression()); } } diff --git a/ql/src/test/queries/clientpositive/windowing_windowspec3.q b/ql/src/test/queries/clientpositive/windowing_windowspec3.q index d00e939..c87aaff 100644 --- a/ql/src/test/queries/clientpositive/windowing_windowspec3.q +++ b/ql/src/test/queries/clientpositive/windowing_windowspec3.q @@ -16,6 +16,10 @@ create table emp(empno smallint, load data local inpath '../../data/files/emp2.txt' into table emp; +-- No order by +select hirets, salary, sum(salary) over (partition by hirets range between current row and unbounded following) from emp; + + -- Support date datatype select deptno, empno, hiredate, salary, sum(salary) over (partition by deptno order by hiredate range 90 preceding), @@ -25,5 +29,3 @@ select deptno, empno, hiredate, salary, sum(salary) over (partition by deptno order by hiredate range between 10 following and unbounded following), sum(salary) over (partition by deptno order by hiredate range between unbounded preceding and 10 following) from emp; - - diff --git a/ql/src/test/results/clientpositive/windowing_windowspec3.q.out b/ql/src/test/results/clientpositive/windowing_windowspec3.q.out index a5eae5b..bf7797a 100644 --- a/ql/src/test/results/clientpositive/windowing_windowspec3.q.out +++ b/ql/src/test/results/clientpositive/windowing_windowspec3.q.out @@ -42,6 +42,32 @@ POSTHOOK: query: load data local inpath '../../data/files/emp2.txt' into table e POSTHOOK: type: LOAD #### A masked pattern was here #### POSTHOOK: Output: default@emp +PREHOOK: query: -- No order by +select hirets, salary, sum(salary) over (partition by hirets range between current row and unbounded following) from emp +PREHOOK: type: QUERY +PREHOOK: Input: default@emp +#### A masked pattern was here #### +POSTHOOK: query: -- No order by +select hirets, salary, sum(salary) over (partition by hirets range between current row and unbounded following) from emp +POSTHOOK: type: QUERY +POSTHOOK: Input: default@emp +#### A masked pattern was here #### +NULL 1500.0 3000.0 +NULL 1500.0 3000.0 +1980-12-17 00:00:00 800.0 800.0 +1981-02-20 00:00:00 1600.0 1600.0 +1981-02-22 00:00:00 1250.0 1250.0 +1981-04-02 00:00:00 2975.0 2975.0 +1981-05-01 00:00:00 2850.0 2850.0 +1981-06-09 00:00:00 2450.0 2450.0 +1981-09-08 00:00:00 1500.0 1500.0 +1981-09-28 00:00:00 1250.0 1250.0 +1981-11-17 00:00:00 5000.0 5000.0 +1981-12-03 00:00:00 3000.0 3950.0 +1981-12-03 00:00:00 950.0 3950.0 +1982-01-23 00:00:00 1300.0 1300.0 +1982-12-09 00:00:00 3000.0 3000.0 +1983-01-12 00:00:00 1100.0 1100.0 PREHOOK: query: -- Support date datatype select deptno, empno, hiredate, salary, sum(salary) over (partition by deptno order by hiredate range 90 preceding),